Class HttpFields

  • All Implemented Interfaces:
    java.lang.Iterable<HttpField>

    public class HttpFields
    extends java.lang.Object
    implements java.lang.Iterable<HttpField>
    HTTP Fields. A collection of HTTP header and or Trailer fields.

    This class is not synchronized as it is expected that modifications will only be performed by a single thread.

    The cookie handling provided by this class is guided by the Servlet specification and RFC6265.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String __separators
      Deprecated.
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpFields()
      Initialize an empty HttpFields.
      HttpFields​(int capacity)
      Initialize an empty HttpFields.
      HttpFields​(HttpFields fields)
      Initialize HttpFields from copy.
    • Field Detail

      • __separators

        @Deprecated
        public static final java.lang.String __separators
        Deprecated.
        See Also:
        Constant Field Values
    • Constructor Detail

      • HttpFields

        public HttpFields()
        Initialize an empty HttpFields.
      • HttpFields

        public HttpFields​(int capacity)
        Initialize an empty HttpFields.
        Parameters:
        capacity - the capacity of the http fields
      • HttpFields

        public HttpFields​(HttpFields fields)
        Initialize HttpFields from copy.
        Parameters:
        fields - the fields to copy data from
    • Method Detail

      • size

        public int size()
      • iterator

        public java.util.Iterator<HttpField> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<HttpField>
      • listIterator

        public java.util.ListIterator<HttpField> listIterator()
      • stream

        public java.util.stream.Stream<HttpField> stream()
      • getFieldNamesCollection

        public java.util.Set<java.lang.String> getFieldNamesCollection()
        Get Collection of header names.
        Returns:
        the unique set of field names.
      • getFieldNames

        public java.util.Enumeration<java.lang.String> getFieldNames()
        Get enumeration of header _names. Returns an enumeration of strings representing the header _names for this request.
        Returns:
        an enumeration of field names
      • getField

        public HttpField getField​(int index)
        Get a Field by index.
        Parameters:
        index - the field index
        Returns:
        A Field value or null if the Field value has not been set
      • getField

        public HttpField getField​(java.lang.String name)
      • contains

        public boolean contains​(HttpField field)
      • contains

        public boolean contains​(HttpHeader header,
                                java.lang.String value)
      • contains

        public boolean contains​(java.lang.String name,
                                java.lang.String value)
      • contains

        public boolean contains​(HttpHeader header)
      • containsKey

        public boolean containsKey​(java.lang.String name)
      • getStringField

        @Deprecated
        public java.lang.String getStringField​(HttpHeader header)
        Deprecated.
      • get

        public java.lang.String get​(HttpHeader header)
      • getStringField

        @Deprecated
        public java.lang.String getStringField​(java.lang.String name)
        Deprecated.
      • get

        public java.lang.String get​(java.lang.String header)
      • getValuesList

        public java.util.List<java.lang.String> getValuesList​(HttpHeader header)
        Get multiple header of the same name
        Parameters:
        header - the header
        Returns:
        List the values
      • getValuesList

        public java.util.List<java.lang.String> getValuesList​(java.lang.String name)
        Get multiple header of the same name
        Parameters:
        name - the case-insensitive field name
        Returns:
        List the header values
      • addCSV

        public boolean addCSV​(HttpHeader header,
                              java.lang.String... values)
        Add comma separated values, but only if not already present.
        Parameters:
        header - The header to add the value(s) to
        values - The value(s) to add
        Returns:
        True if headers were modified
      • addCSV

        public boolean addCSV​(java.lang.String name,
                              java.lang.String... values)
        Add comma separated values, but only if not already present.
        Parameters:
        name - The header to add the value(s) to
        values - The value(s) to add
        Returns:
        True if headers were modified
      • getCSV

        public java.util.List<java.lang.String> getCSV​(HttpHeader header,
                                                       boolean keepQuotes)
        Get multiple field values of the same name, split as a QuotedCSV
        Parameters:
        header - The header
        keepQuotes - True if the fields are kept quoted
        Returns:
        List the values with OWS stripped
      • getCSV

        public java.util.List<java.lang.String> getCSV​(java.lang.String name,
                                                       boolean keepQuotes)
        Get multiple field values of the same name as a QuotedCSV
        Parameters:
        name - the case-insensitive field name
        keepQuotes - True if the fields are kept quoted
        Returns:
        List the values with OWS stripped
      • getQualityCSV

        public java.util.List<java.lang.String> getQualityCSV​(HttpHeader header)
        Get multiple field values of the same name, split and sorted as a QuotedQualityCSV
        Parameters:
        header - The header
        Returns:
        List the values in quality order with the q param and OWS stripped
      • getQualityCSV

        public java.util.List<java.lang.String> getQualityCSV​(HttpHeader header,
                                                              java.util.function.ToIntFunction<java.lang.String> secondaryOrdering)
        Get multiple field values of the same name, split and sorted as a QuotedQualityCSV
        Parameters:
        header - The header
        secondaryOrdering - Function to apply an ordering other than specified by quality
        Returns:
        List the values in quality order with the q param and OWS stripped
      • getQualityCSV

        public java.util.List<java.lang.String> getQualityCSV​(java.lang.String name)
        Get multiple field values of the same name, split and sorted as a QuotedQualityCSV
        Parameters:
        name - the case-insensitive field name
        Returns:
        List the values in quality order with the q param and OWS stripped
      • getValues

        public java.util.Enumeration<java.lang.String> getValues​(java.lang.String name)
        Get multi headers
        Parameters:
        name - the case-insensitive field name
        Returns:
        Enumeration of the values
      • getValues

        @Deprecated
        public java.util.Enumeration<java.lang.String> getValues​(java.lang.String name,
                                                                 java.lang.String separators)
        Deprecated.
        Get multi field values with separator. The multiple values can be represented as separate headers of the same name, or by a single header using the separator(s), or a combination of both. Separators may be quoted.
        Parameters:
        name - the case-insensitive field name
        separators - String of separators.
        Returns:
        Enumeration of the values, or null if no such header.
      • put

        public void put​(java.lang.String name,
                        java.lang.String value)
        Set a field.
        Parameters:
        name - the name of the field
        value - the value of the field. If null the field is cleared.
      • put

        public void put​(HttpHeader header,
                        java.lang.String value)
        Set a field.
        Parameters:
        header - the header name of the field
        value - the value of the field. If null the field is cleared.
      • put

        public void put​(java.lang.String name,
                        java.util.List<java.lang.String> list)
        Set a field.
        Parameters:
        name - the name of the field
        list - the List value of the field. If null the field is cleared.
      • add

        public void add​(java.lang.String name,
                        java.lang.String value)
        Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.
        Parameters:
        name - the name of the field
        value - the value of the field.
      • add

        public void add​(HttpHeader header,
                        java.lang.String value)
        Add to or set a field. If the field is allowed to have multiple values, add will add multiple headers of the same name.
        Parameters:
        header - the header
        value - the value of the field.
      • remove

        public HttpField remove​(HttpHeader name)
        Remove a field.
        Parameters:
        name - the field to remove
        Returns:
        the header that was removed
      • remove

        public HttpField remove​(java.lang.String name)
        Remove a field.
        Parameters:
        name - the field to remove
        Returns:
        the header that was removed
      • getLongField

        public long getLongField​(java.lang.String name)
                          throws java.lang.NumberFormatException
        Get a header as an long value. Returns the value of an integer field or -1 if not found. The case of the field name is ignored.
        Parameters:
        name - the case-insensitive field name
        Returns:
        the value of the field as a long
        Throws:
        java.lang.NumberFormatException - If bad long found
      • getDateField

        public long getDateField​(java.lang.String name)
        Get a header as a date value. Returns the value of a date field, or -1 if not found. The case of the field name is ignored.
        Parameters:
        name - the case-insensitive field name
        Returns:
        the value of the field as a number of milliseconds since unix epoch
      • putLongField

        public void putLongField​(HttpHeader name,
                                 long value)
        Sets the value of an long field.
        Parameters:
        name - the field name
        value - the field long value
      • putLongField

        public void putLongField​(java.lang.String name,
                                 long value)
        Sets the value of an long field.
        Parameters:
        name - the field name
        value - the field long value
      • putDateField

        public void putDateField​(HttpHeader name,
                                 long date)
        Sets the value of a date field.
        Parameters:
        name - the field name
        date - the field date value
      • putDateField

        public void putDateField​(java.lang.String name,
                                 long date)
        Sets the value of a date field.
        Parameters:
        name - the field name
        date - the field date value
      • addDateField

        public void addDateField​(java.lang.String name,
                                 long date)
        Sets the value of a date field.
        Parameters:
        name - the field name
        date - the field date value
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • clear

        public void clear()
      • addAll

        public void addAll​(HttpFields fields)
      • add

        @Deprecated
        public void add​(HttpFields fields)
        Deprecated.
        Add fields from another HttpFields instance. Single valued fields are replaced, while all others are added.
        Parameters:
        fields - the fields to add
      • stripParameters

        public static java.lang.String stripParameters​(java.lang.String value)
        Get field value without parameters. Some field values can have parameters. This method separates the value from the parameters and optionally populates a map with the parameters. For example:
        
         FieldName : Value ; param1=val1 ; param2=val2
        
         
        Parameters:
        value - The Field value, possibly with parameters.
        Returns:
        The value.
      • valueParameters

        public static java.lang.String valueParameters​(java.lang.String value,
                                                       java.util.Map<java.lang.String,​java.lang.String> parameters)
        Get field value parameters. Some field values can have parameters. This method separates the value from the parameters and optionally populates a map with the parameters. For example:
        
         FieldName : Value ; param1=val1 ; param2=val2
        
         
        Parameters:
        value - The Field value, possibly with parameters.
        parameters - A map to populate with the parameters, or null
        Returns:
        The value.
      • getQuality

        @Deprecated
        public static java.lang.Float getQuality​(java.lang.String value)
        Deprecated.
      • qualityList

        @Deprecated
        public static java.util.List<java.lang.String> qualityList​(java.util.Enumeration<java.lang.String> e)
        Deprecated.
        List values in quality order.
        Parameters:
        e - Enumeration of values with quality parameters
        Returns:
        values in quality order.