Class HttpField

java.lang.Object
org.eclipse.jetty.http.HttpField
Direct Known Subclasses:
HostPortHttpField, HttpCookieUtils.SetCookieHttpField, HttpField.IntValueHttpField, HttpField.LongValueHttpField, PreEncodedHttpField, ResponseHttpFields.PersistentHttpField, StaticTableHttpField

public class HttpField extends Object

An immutable class representing an HTTP header or trailer.

HttpField has a case-insensitive name and case sensitive value, and may be multi-valued with each value separated by a comma.

See Also:
  • Field Details

  • Constructor Details

    • HttpField

      public HttpField(HttpHeader header, String name, String value)

      Creates a new HttpField with the given HttpHeader, name string and value string.

      A null field value may be passed as parameter, and will be converted to the empty string. This allows the direct constructions of fields that have no value, and/or HttpField subclasses that override getValue().

      Parameters:
      header - the HttpHeader referencing a well-known HTTP header name; may be null in case of an unknown or custom HTTP header name
      name - the field name; if null, then HttpHeader.asString() is used
      value - the field value; if null, the empty string will be used
    • HttpField

      public HttpField(HttpHeader header, String value)

      Creates a new HttpField with the given HttpHeader and value string.

      Parameters:
      header - the non-null HttpHeader referencing a well-known HTTP header name
      value - the field value; if null, the empty string will be used
    • HttpField

      public HttpField(HttpHeader header, HttpHeaderValue value)

      Creates a new HttpField with the given HttpHeader and value.

      Parameters:
      header - the non-null HttpHeader referencing a well-known HTTP header name
      value - the field value; if null, the empty string will be used
    • HttpField

      public HttpField(String name, String value)

      Creates a new HttpField with the given name string and value string.

      Parameters:
      name - the non-null field name
      value - the field value; if null, the empty string will be used
  • Method Details

    • getValueParameters

      public static String getValueParameters(String valueParams, Map<String,String> parameters)

      Returns the field value and its parameters.

      A field value may have parameters, typically separated by ;, for example

      
       Content-Type: text/plain; charset=UTF-8
       Accept: text/html, text/plain; q=0.5
       
      Parameters:
      valueParams - the field value, possibly with parameters
      parameters - An output map to populate with the parameters, or null to strip the parameters
      Returns:
      the field value without parameters
      See Also:
    • stripParameters

      public static String stripParameters(String value)

      Returns the field value, stripped of its parameters.

      Parameters:
      value - the field value, possibly with parameters
      Returns:
      the field value without parameters
      See Also:
    • valueParameters

      @Deprecated public static String valueParameters(String value, Map<String,String> parameters)
      Deprecated.
    • contains

      public boolean contains(String search)

      Returns whether this field value, possibly multi-valued, contains the specified search string, case-insensitively.

      Only values, and not parameters, are compared with the search string.

      Parameters:
      search - the string to search for
      Returns:
      whether this field value, possibly multi-valued, contains the specified search string
    • contains

      public static boolean contains(String value, String search)

      Returns whether the given value, possibly multi-valued, contains the specified search string, case-insensitively.

      Only values, and not parameters, are compared with the search string.

      Parameters:
      value - the value string to search into
      search - the string to search for
      Returns:
      whether the given value, possibly multi-valued, contains the specified search string
    • containsLast

      public boolean containsLast(String search)
      Look for a value as the last value in a possible multivalued field Parameters and specifically quality parameters are not considered.
      Parameters:
      search - Values to search for (case-insensitive)
      Returns:
      True iff the value is contained in the field value entirely or as the last element of a quoted comma separated list.
    • containsLast

      public static boolean containsLast(String value, String search)
      Look for the last value in a possible multivalued field Parameters and specifically quality parameters are not considered.
      Parameters:
      value - The field value to search in.
      search - Values to search for (case-insensitive)
      Returns:
      True iff the value is contained in the field value entirely or as the last element of a quoted comma separated list.
    • hashCode

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • getHeader

      public HttpHeader getHeader()
      Get the HttpHeader of this field, or null.
      Returns:
      the HttpHeader of this field, or null
    • getIntValue

      public int getIntValue()
      Returns:
      the value of this field as an int
      Throws:
      NumberFormatException - if the value cannot be parsed as an int
    • getLongValue

      public long getLongValue()
      Returns:
      the value of this field as an long
      Throws:
      NumberFormatException - if the value cannot be parsed as an long
    • getLowerCaseName

      public String getLowerCaseName()
      Get the field name in lower-case.
      Returns:
      the field name in lower-case
    • getName

      public String getName()
      Get the field name.
      Returns:
      the field name
    • getValue

      public String getValue()
      Get the field value.
      Returns:
      the field value
    • getValues

      public String[] getValues()
      Returns:
      the field values as a String[]
      See Also:
    • getValueList

      public List<String> getValueList()

      Returns a list of the field values.

      If the field value is multi-valued, the encoded field value is split into multiple values using QuotedCSV and the different values returned in a list.

      If the field value is single-valued, the value is wrapped into a list.

      Returns:
      a list of the field values
    • isSameName

      public boolean isSameName(HttpField field)

      Returns whether this field has the same name as the given field.

      The comparison of field name is case-insensitive via is(String).

      Parameters:
      field - the field to compare the name to
      Returns:
      whether this field has the same name as the given field
    • is

      public boolean is(String name)

      Returns whether this field name is the same as the given string.

      The comparison of field name is case-insensitive.

      Parameters:
      name - the field name to compare to
      Returns:
      whether this field name is the same as the given string
    • toString

      public String toString()
      Overrides:
      toString in class Object