Class DefaultHttpHeaders

java.lang.Object
io.netty.handler.codec.http.HttpHeaders
io.netty.handler.codec.http.DefaultHttpHeaders
All Implemented Interfaces:
java.lang.Iterable<java.util.Map.Entry<java.lang.String, java.lang.String>>
Direct Known Subclasses:
CombinedHttpHeaders

public class DefaultHttpHeaders extends HttpHeaders
Default implementation of HttpHeaders.
  • Field Details

    • CASE_INSENSITIVE_CONTAINS

      private static final java.util.function.BiPredicate<java.lang.CharSequence, java.lang.CharSequence> CASE_INSENSITIVE_CONTAINS
    • CASE_SENSITIVE_CONTAINS

      private static final java.util.function.BiPredicate<java.lang.CharSequence, java.lang.CharSequence> CASE_SENSITIVE_CONTAINS
    • headers

      private final DefaultHeaders<java.lang.CharSequence, java.lang.CharSequence, ?> headers
  • Constructor Details

  • Method Details

    • unwrap

      public Headers<java.lang.CharSequence, java.lang.CharSequence, ?> unwrap()
    • add

      public HttpHeaders add(HttpHeaders headers)
      Description copied from class: HttpHeaders
      Adds all header entries of the specified headers.
      Overrides:
      add in class HttpHeaders
      Returns:
      this
    • set

      public HttpHeaders set(HttpHeaders headers)
      Description copied from class: HttpHeaders
      Cleans the current header entries and copies all header entries of the specified headers.
      Overrides:
      set in class HttpHeaders
      Returns:
      this
    • add

      public HttpHeaders add(java.lang.String name, java.lang.Object value)
      Specified by:
      add in class HttpHeaders
      See Also:
    • add

      public HttpHeaders add(java.lang.CharSequence name, java.lang.Object value)
      Description copied from class: HttpHeaders
      Adds a new header with the specified name and value. If the specified value is not a String, it is converted into a String by Object.toString(), except in the cases of Date and Calendar, which are formatted to the date format defined in RFC2616.
      Overrides:
      add in class HttpHeaders
      Parameters:
      name - The name of the header being added
      value - The value of the header being added
      Returns:
      this
    • add

      public HttpHeaders add(java.lang.String name, java.lang.Iterable<?> values)
      Specified by:
      add in class HttpHeaders
      See Also:
    • add

      public HttpHeaders add(java.lang.CharSequence name, java.lang.Iterable<?> values)
      Description copied from class: HttpHeaders
      Adds a new header with the specified name and values. This getMethod can be represented approximately as the following code:
      for (Object v: values) {
          if (v == null) {
              break;
          }
          headers.add(name, v);
      }
      
      Overrides:
      add in class HttpHeaders
      Parameters:
      name - The name of the headers being set
      values - The values of the headers being set
      Returns:
      this
    • addInt

      public HttpHeaders addInt(java.lang.CharSequence name, int value)
      Description copied from class: HttpHeaders
      Add the name to value.
      Specified by:
      addInt in class HttpHeaders
      Parameters:
      name - The name to modify
      value - The value
      Returns:
      this
    • addShort

      public HttpHeaders addShort(java.lang.CharSequence name, short value)
      Description copied from class: HttpHeaders
      Add the name to value.
      Specified by:
      addShort in class HttpHeaders
      Parameters:
      name - The name to modify
      value - The value
      Returns:
      this
    • remove

      public HttpHeaders remove(java.lang.String name)
      Specified by:
      remove in class HttpHeaders
      See Also:
    • remove

      public HttpHeaders remove(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Removes the header with the specified name.
      Overrides:
      remove in class HttpHeaders
      Parameters:
      name - The name of the header to remove
      Returns:
      this
    • set

      public HttpHeaders set(java.lang.String name, java.lang.Object value)
      Specified by:
      set in class HttpHeaders
      See Also:
    • set

      public HttpHeaders set(java.lang.CharSequence name, java.lang.Object value)
      Description copied from class: HttpHeaders
      Sets a header with the specified name and value. If there is an existing header with the same name, it is removed. If the specified value is not a String, it is converted into a String by Object.toString(), except for Date and Calendar, which are formatted to the date format defined in RFC2616.
      Overrides:
      set in class HttpHeaders
      Parameters:
      name - The name of the header being set
      value - The value of the header being set
      Returns:
      this
    • set

      public HttpHeaders set(java.lang.String name, java.lang.Iterable<?> values)
      Specified by:
      set in class HttpHeaders
      See Also:
    • set

      public HttpHeaders set(java.lang.CharSequence name, java.lang.Iterable<?> values)
      Description copied from class: HttpHeaders
      Sets a header with the specified name and values. If there is an existing header with the same name, it is removed. This getMethod can be represented approximately as the following code:
      headers.remove(name);
      for (Object v: values) {
          if (v == null) {
              break;
          }
          headers.add(name, v);
      }
      
      Overrides:
      set in class HttpHeaders
      Parameters:
      name - The name of the headers being set
      values - The values of the headers being set
      Returns:
      this
    • setInt

      public HttpHeaders setInt(java.lang.CharSequence name, int value)
      Description copied from class: HttpHeaders
      Set the name to value. This will remove all previous values associated with name.
      Specified by:
      setInt in class HttpHeaders
      Parameters:
      name - The name to modify
      value - The value
      Returns:
      this
    • setShort

      public HttpHeaders setShort(java.lang.CharSequence name, short value)
      Description copied from class: HttpHeaders
      Set the name to value. This will remove all previous values associated with name.
      Specified by:
      setShort in class HttpHeaders
      Parameters:
      name - The name to modify
      value - The value
      Returns:
      this
    • clear

      public HttpHeaders clear()
      Description copied from class: HttpHeaders
      Removes all headers from this HttpMessage.
      Specified by:
      clear in class HttpHeaders
      Returns:
      this
    • get

      public java.lang.String get(java.lang.String name)
      Specified by:
      get in class HttpHeaders
      See Also:
    • get

      public java.lang.String get(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Returns the value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
      Overrides:
      get in class HttpHeaders
      Parameters:
      name - The name of the header to search
      Returns:
      The first header value or null if there is no such header
      See Also:
    • getInt

      public java.lang.Integer getInt(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Returns the integer value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
      Specified by:
      getInt in class HttpHeaders
      Parameters:
      name - the name of the header to search
      Returns:
      the first header value if the header is found and its value is an integer. null if there's no such header or its value is not an integer.
    • getInt

      public int getInt(java.lang.CharSequence name, int defaultValue)
      Description copied from class: HttpHeaders
      Returns the integer value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
      Specified by:
      getInt in class HttpHeaders
      Parameters:
      name - the name of the header to search
      defaultValue - the default value
      Returns:
      the first header value if the header is found and its value is an integer. defaultValue if there's no such header or its value is not an integer.
    • getShort

      public java.lang.Short getShort(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Returns the short value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
      Specified by:
      getShort in class HttpHeaders
      Parameters:
      name - the name of the header to search
      Returns:
      the first header value if the header is found and its value is a short. null if there's no such header or its value is not a short.
    • getShort

      public short getShort(java.lang.CharSequence name, short defaultValue)
      Description copied from class: HttpHeaders
      Returns the short value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
      Specified by:
      getShort in class HttpHeaders
      Parameters:
      name - the name of the header to search
      defaultValue - the default value
      Returns:
      the first header value if the header is found and its value is a short. defaultValue if there's no such header or its value is not a short.
    • getTimeMillis

      public java.lang.Long getTimeMillis(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Returns the date value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
      Specified by:
      getTimeMillis in class HttpHeaders
      Parameters:
      name - the name of the header to search
      Returns:
      the first header value if the header is found and its value is a date. null if there's no such header or its value is not a date.
    • getTimeMillis

      public long getTimeMillis(java.lang.CharSequence name, long defaultValue)
      Description copied from class: HttpHeaders
      Returns the date value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
      Specified by:
      getTimeMillis in class HttpHeaders
      Parameters:
      name - the name of the header to search
      defaultValue - the default value
      Returns:
      the first header value if the header is found and its value is a date. defaultValue if there's no such header or its value is not a date.
    • getAll

      public java.util.List<java.lang.String> getAll(java.lang.String name)
      Specified by:
      getAll in class HttpHeaders
      See Also:
    • getAll

      public java.util.List<java.lang.String> getAll(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Returns the values of headers with the specified name
      Overrides:
      getAll in class HttpHeaders
      Parameters:
      name - The name of the headers to search
      Returns:
      A List of header values which will be empty if no values are found
      See Also:
    • entries

      public java.util.List<java.util.Map.Entry<java.lang.String, java.lang.String>> entries()
      Description copied from class: HttpHeaders
      Returns a new List that contains all headers in this object. Note that modifying the returned List will not affect the state of this object. If you intend to enumerate over the header entries only, use HttpHeaders.iterator() instead, which has much less overhead.
      Specified by:
      entries in class HttpHeaders
      See Also:
    • iterator

      @Deprecated public java.util.Iterator<java.util.Map.Entry<java.lang.String, java.lang.String>> iterator()
      Deprecated.
      Specified by:
      iterator in interface java.lang.Iterable<java.util.Map.Entry<java.lang.String, java.lang.String>>
      Specified by:
      iterator in class HttpHeaders
    • iteratorCharSequence

      public java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence, java.lang.CharSequence>> iteratorCharSequence()
      Specified by:
      iteratorCharSequence in class HttpHeaders
      Returns:
      Iterator over the name/value header pairs.
    • valueStringIterator

      public java.util.Iterator<java.lang.String> valueStringIterator(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Equivalent to HttpHeaders.getAll(String) but it is possible that no intermediate list is generated.
      Overrides:
      valueStringIterator in class HttpHeaders
      Parameters:
      name - the name of the header to retrieve
      Returns:
      an Iterator of header values corresponding to name.
    • valueCharSequenceIterator

      public java.util.Iterator<java.lang.CharSequence> valueCharSequenceIterator(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Equivalent to HttpHeaders.getAll(String) but it is possible that no intermediate list is generated.
      Overrides:
      valueCharSequenceIterator in class HttpHeaders
      Parameters:
      name - the name of the header to retrieve
      Returns:
      an Iterator of header values corresponding to name.
    • containsValue

      public boolean containsValue(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase)
      Description copied from class: HttpHeaders
      Returns true if a header with the name and value exists, false otherwise. This also handles multiple values that are separated with a ,.

      If ignoreCase is true then a case insensitive compare is done on the value.

      Overrides:
      containsValue in class HttpHeaders
      Parameters:
      name - the name of the header to find
      value - the value of the header to find
      ignoreCase - true then a case insensitive compare is run to compare values. otherwise a case sensitive compare is run to compare values.
    • contains

      public boolean contains(java.lang.String name)
      Specified by:
      contains in class HttpHeaders
      See Also:
    • contains

      public boolean contains(java.lang.CharSequence name)
      Description copied from class: HttpHeaders
      Checks to see if there is a header with the specified name
      Overrides:
      contains in class HttpHeaders
      Parameters:
      name - The name of the header to search for
      Returns:
      True if at least one header is found
    • isEmpty

      public boolean isEmpty()
      Description copied from class: HttpHeaders
      Checks if no header exists.
      Specified by:
      isEmpty in class HttpHeaders
    • size

      public int size()
      Description copied from class: HttpHeaders
      Returns the number of headers in this object.
      Specified by:
      size in class HttpHeaders
    • contains

      public boolean contains(java.lang.String name, java.lang.String value, boolean ignoreCase)
      Overrides:
      contains in class HttpHeaders
      See Also:
    • contains

      public boolean contains(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase)
      Description copied from class: HttpHeaders
      Returns true if a header with the name and value exists, false otherwise.

      If ignoreCase is true then a case insensitive compare is done on the value.

      Overrides:
      contains in class HttpHeaders
      Parameters:
      name - the name of the header to find
      value - the value of the header to find
      ignoreCase - true then a case insensitive compare is run to compare values. otherwise a case sensitive compare is run to compare values.
    • names

      public java.util.Set<java.lang.String> names()
      Description copied from class: HttpHeaders
      Returns a new Set that contains the names of all headers in this object. Note that modifying the returned Set will not affect the state of this object. If you intend to enumerate over the header entries only, use HttpHeaders.iterator() instead, which has much less overhead.
      Specified by:
      names in class HttpHeaders
    • equals

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

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

      public HttpHeaders copy()
      Description copied from class: HttpHeaders
      Returns a deep copy of the passed in HttpHeaders.
      Overrides:
      copy in class HttpHeaders
    • valueConverter

      static ValueConverter<java.lang.CharSequence> valueConverter()
    • valueValidator

      static DefaultHeaders.ValueValidator<java.lang.CharSequence> valueValidator(boolean validate)
    • nameValidator

      static DefaultHeaders.NameValidator<java.lang.CharSequence> nameValidator(boolean validate)