Interface HttpHeadersBuilder

All Superinterfaces:
Iterable<Map.Entry<AsciiString,​String>>
All Known Subinterfaces:
RequestHeadersBuilder, ResponseHeadersBuilder

public interface HttpHeadersBuilder
Builds an HttpHeaders.
See Also:
HttpHeaders.builder(), HttpHeaders.toBuilder()
  • Method Details

    • build

      HttpHeaders build()
      Returns a newly created HttpHeaders with the entries in this builder.
    • sizeHint

      HttpHeadersBuilder sizeHint​(int sizeHint)
      Specifies the hint about the number of headers which may improve the memory efficiency and performance of the underlying data structure.
      Returns:
      this
      Throws:
      IllegalStateException - if the hint was specified too late after the underlying data structure has been fully initialized.
    • endOfStream

      HttpHeadersBuilder endOfStream​(boolean endOfStream)
      Sets whether the headers will be the last frame in an HTTP/2 stream.
    • contentType

      HttpHeadersBuilder contentType​(MediaType contentType)
      Sets the "content-type" header.
    • contentDisposition

      HttpHeadersBuilder contentDisposition​(ContentDisposition contentDisposition)
      Sets the "content-disposition" header.
    • getAndRemove

      @Nullable String getAndRemove​(CharSequence name)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      Returns:
      the first header value or null if there is no such header
    • getAndRemove

      String getAndRemove​(CharSequence name, String defaultValue)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      defaultValue - the default value
      Returns:
      the first header value or defaultValue if there is no such header
    • getAllAndRemove

      List<String> getAllAndRemove​(CharSequence name)
      Removes all the headers with the specified name and returns the removed header values.
      Parameters:
      name - the header name
      Returns:
      a List of header values or an empty List if no values are found.
    • getIntAndRemove

      @Nullable Integer getIntAndRemove​(CharSequence name)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      Returns:
      the int value of the first value in insertion order or null if there is no such value or it can't be converted into int.
    • getIntAndRemove

      int getIntAndRemove​(CharSequence name, int defaultValue)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      defaultValue - the default value
      Returns:
      the int value of the first value in insertion order or defaultValue if there is no such value or it can't be converted into int.
    • getLongAndRemove

      @Nullable Long getLongAndRemove​(CharSequence name)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      Returns:
      the long value of the first value in insertion order or null if there is no such value or it can't be converted into long.
    • getLongAndRemove

      long getLongAndRemove​(CharSequence name, long defaultValue)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      defaultValue - the default value
      Returns:
      the long value of the first value in insertion order or defaultValue if there is no such value or it can't be converted into long.
    • getFloatAndRemove

      @Nullable Float getFloatAndRemove​(CharSequence name)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      Returns:
      the float value of the first value in insertion order or null if there is no such value or it can't be converted into float.
    • getFloatAndRemove

      float getFloatAndRemove​(CharSequence name, float defaultValue)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      defaultValue - the default value
      Returns:
      the float value of the first value in insertion order or defaultValue if there is no such value or it can't be converted into float.
    • getDoubleAndRemove

      @Nullable Double getDoubleAndRemove​(CharSequence name)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      Returns:
      the double value of the first value in insertion order or null if there is no such value or it can't be converted into double.
    • getDoubleAndRemove

      double getDoubleAndRemove​(CharSequence name, double defaultValue)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      defaultValue - the default value
      Returns:
      the double value of the first value in insertion order or defaultValue if there is no such value or it can't be converted into double.
    • getTimeMillisAndRemove

      @Nullable Long getTimeMillisAndRemove​(CharSequence name)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      Returns:
      the milliseconds value of the first value in insertion order or null if there is no such value or it can't be converted into milliseconds.
    • getTimeMillisAndRemove

      long getTimeMillisAndRemove​(CharSequence name, long defaultValue)
      Removes all the headers with the specified name and returns the header value which was added first.
      Parameters:
      name - the header name
      defaultValue - the default value
      Returns:
      the milliseconds value of the first value in insertion order or defaultValue if there is no such value or it can't be converted into milliseconds.
    • add

      HttpHeadersBuilder add​(CharSequence name, String value)
      Adds a new header with the specified name and value.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • add

      Adds new headers with the specified name and values. This method is semantically equivalent to
      
       for (String value : values) {
           builder.add(name, value);
       }
       
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • add

      HttpHeadersBuilder add​(CharSequence name, String... values)
      Adds new headers with the specified name and values. This method is semantically equivalent to
      
       for (String value : values) {
           builder.add(name, value);
       }
       
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • add

      HttpHeadersBuilder add​(Iterable<? extends Map.Entry<? extends CharSequence,​String>> entries)
      Adds all header names and values of the specified entries.
      Returns:
      this
      Throws:
      IllegalArgumentException - if entries == this.
    • addObject

      HttpHeadersBuilder addObject​(CharSequence name, Object value)
      Adds a new header. The specified header value is converted into a String, as explained in Specifying a non-String header value.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addObject

      HttpHeadersBuilder addObject​(CharSequence name, Iterable<?> values)
      Adds a new header with the specified name and values. The specified header values are converted into Strings, as explained in Specifying a non-String header value. This method is equivalent to:
      
       for (Object v : values) {
           builder.addObject(name, v);
       }
       
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • addObject

      HttpHeadersBuilder addObject​(CharSequence name, Object... values)
      Adds a new header with the specified name and values. The specified header values are converted into Strings, as explained in Specifying a non-String header value. This method is equivalent to:
      
       for (Object v : values) {
           builder.addObject(name, v);
       }
       
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • addObject

      HttpHeadersBuilder addObject​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> entries)
      Adds all header names and values of the specified entries. The specified header values are converted into Strings, as explained in Specifying a non-String header value.
      Returns:
      this
      Throws:
      IllegalArgumentException - if entries == this.
    • addInt

      HttpHeadersBuilder addInt​(CharSequence name, int value)
      Adds a new header.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addLong

      HttpHeadersBuilder addLong​(CharSequence name, long value)
      Adds a new header.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addFloat

      HttpHeadersBuilder addFloat​(CharSequence name, float value)
      Adds a new header.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addDouble

      HttpHeadersBuilder addDouble​(CharSequence name, double value)
      Adds a new header.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addTimeMillis

      HttpHeadersBuilder addTimeMillis​(CharSequence name, long value)
      Adds a new header.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • set

      HttpHeadersBuilder set​(CharSequence name, String value)
      Sets a header with the specified name and value. Any existing headers with the same name are overwritten.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • set

      Sets a new header with the specified name and values. This method is equivalent to
      
       builder.remove(name);
       for (String v : values) {
           builder.add(name, v);
       }
       
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • set

      HttpHeadersBuilder set​(CharSequence name, String... values)
      Sets a header with the specified name and values. Any existing headers with the specified name are removed. This method is equivalent to:
      
       builder.remove(name);
       for (String v : values) {
           builder.add(name, v);
       }
       
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • set

      HttpHeadersBuilder set​(Iterable<? extends Map.Entry<? extends CharSequence,​String>> entries)
      Retains all current headers but calls set(CharSequence, String) for each header in the specified entries.
      Parameters:
      entries - the headers used to set the header values
      Returns:
      this
    • setIfAbsent

      HttpHeadersBuilder setIfAbsent​(Iterable<? extends Map.Entry<? extends CharSequence,​String>> entries)
      Copies the entries missing in this headers from the specified entries. This method is a shortcut for:
      
       headers.names().forEach(name -> {
           if (!builder.contains(name)) {
               builder.set(name, headers.getAll(name));
           }
       });
       
      Returns:
      this
    • setObject

      HttpHeadersBuilder setObject​(CharSequence name, Object value)
      Sets a new header. Any existing headers with the specified name are removed. The specified header value is converted into a String, as explained in Specifying a non-String header value.
      Parameters:
      name - the header name
      value - the value of the header
      Returns:
      this
    • setObject

      HttpHeadersBuilder setObject​(CharSequence name, Iterable<?> values)
      Sets a header with the specified name and values. Any existing headers with the specified name are removed. The specified header values are converted into Strings, as explained in Specifying a non-String header value. This method is equivalent to:
      
       builder.remove(name);
       for (Object v : values) {
           builder.addObject(name, v);
       }
       
      Parameters:
      name - the header name
      values - the values of the header
      Returns:
      this
    • setObject

      HttpHeadersBuilder setObject​(CharSequence name, Object... values)
      Sets a header with the specified name and values. Any existing headers with the specified name are removed. The specified header values are converted into Strings, as explained in Specifying a non-String header value. This method is equivalent to:
      
       builder.remove(name);
       for (Object v : values) {
           builder.addObject(name, v);
       }
       
      Parameters:
      name - the header name
      values - the values of the header
      Returns:
      this
    • setObject

      HttpHeadersBuilder setObject​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> entries)
      Retains all current headers but calls setObject(CharSequence, Object) for each entry in the specified entries. The specified header values are converted into Strings, as explained in Specifying a non-String header value.
      Parameters:
      entries - the headers used to set the values in this instance
      Returns:
      this
    • setInt

      HttpHeadersBuilder setInt​(CharSequence name, int value)
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • setLong

      HttpHeadersBuilder setLong​(CharSequence name, long value)
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • setFloat

      HttpHeadersBuilder setFloat​(CharSequence name, float value)
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • setDouble

      HttpHeadersBuilder setDouble​(CharSequence name, double value)
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • setTimeMillis

      HttpHeadersBuilder setTimeMillis​(CharSequence name, long value)
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • remove

      boolean remove​(CharSequence name)
      Removes all headers with the specified name.
      Parameters:
      name - the header name
      Returns:
      true if at least one entry has been removed.
    • removeAndThen

      HttpHeadersBuilder removeAndThen​(CharSequence name)
      Removes all headers with the specified name. Unlike remove(CharSequence) this method returns itself so that the caller can chain the invocations.
      Parameters:
      name - the header name
      Returns:
      this
    • clear

      Removes all headers. After a call to this method, size() becomes 0.
      Returns:
      this
    • isEndOfStream

      boolean isEndOfStream()
      Tells whether the headers correspond to the last frame in an HTTP/2 stream.
    • contentType

      @Nullable MediaType contentType()
      Returns the parsed "content-type" header.
      Returns:
      the parsed MediaType if present and valid, or null otherwise.
    • contentDisposition

      @Nullable ContentDisposition contentDisposition()
      Returns the parsed "content-disposition" header.
      Returns:
      the parsed MediaType if present and valid. null if not present or failed to parse "content-disposition" header.
    • get

      @Nullable String get​(CharSequence name)
      Returns the value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the first header value if the header is found, or null if there's no such header
    • get

      String get​(CharSequence name, String defaultValue)
      Returns the value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the first header value or defaultValue if there is no such header
    • getAll

      List<String> getAll​(CharSequence name)
      Returns all values for the header with the specified name. The returned List can't be modified.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      a List of header values or an empty List if there is no such header.
    • getInt

      @Nullable Integer getInt​(CharSequence name)
      Returns the int value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the int value of the first value in insertion order or null if there is no such header or it can't be converted to int.
    • getInt

      int getInt​(CharSequence name, int defaultValue)
      Returns the int value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the int value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to int.
    • getLong

      @Nullable Long getLong​(CharSequence name)
      Returns the long value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the long value of the first value in insertion order or null if there is no such header or it can't be converted to long.
    • getLong

      long getLong​(CharSequence name, long defaultValue)
      Returns the long value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the long value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to long.
    • getFloat

      @Nullable Float getFloat​(CharSequence name)
      Returns the float value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the float value of the first value in insertion order or null if there is no such header or it can't be converted to float.
    • getFloat

      float getFloat​(CharSequence name, float defaultValue)
      Returns the float value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the float value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to float.
    • getDouble

      @Nullable Double getDouble​(CharSequence name)
      Returns the double value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the double value of the first value in insertion order or null if there is no such header or it can't be converted to double.
    • getDouble

      double getDouble​(CharSequence name, double defaultValue)
      Returns the double value of a header with the specified name. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the double value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to double.
    • getTimeMillis

      @Nullable Long getTimeMillis​(CharSequence name)
      Returns the value of a header with the specified name in milliseconds. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the milliseconds value of the first value in insertion order or null if there is no such header or it can't be converted to milliseconds.
    • getTimeMillis

      long getTimeMillis​(CharSequence name, long defaultValue)
      Returns the value of a header with the specified name in milliseconds. If there are more than one value for the specified name, the first value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the milliseconds value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to milliseconds.
    • contains

      boolean contains​(CharSequence name)
      Returns true if a header with the name exists, false otherwise.
      Parameters:
      name - the header name
    • contains

      boolean contains​(CharSequence name, String value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value of the header to find
    • containsObject

      boolean containsObject​(CharSequence name, Object value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsInt

      boolean containsInt​(CharSequence name, int value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsLong

      boolean containsLong​(CharSequence name, long value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsFloat

      boolean containsFloat​(CharSequence name, float value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsDouble

      boolean containsDouble​(CharSequence name, double value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • containsTimeMillis

      boolean containsTimeMillis​(CharSequence name, long value)
      Returns true if a header with the name and value exists.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      true if the header exists. false otherwise
    • size

      int size()
      Returns the number of headers.
    • isEmpty

      boolean isEmpty()
      Returns true if this headers does not contain any entries.
    • names

      Set<AsciiString> names()
      Returns a Set of all header names. The returned Set cannot be modified.
    • iterator

      Returns an Iterator that yields all header entries. The iteration order is as follows:
      1. All pseudo headers (order not specified).
      2. All non-pseudo headers (in insertion order).
      Specified by:
      iterator in interface Iterable<Map.Entry<AsciiString,​String>>
    • valueIterator

      Iterator<String> valueIterator​(CharSequence name)
      Returns an Iterator that yields all values of the headers with the specified name.
    • forEach

      void forEach​(BiConsumer<AsciiString,​String> action)
      Invokes the specified action for all header entries.
    • forEachValue

      void forEachValue​(CharSequence name, Consumer<String> action)
      Invokes the specified action for all values of the headers with the specified name.
    • stream

      default Stream<Map.Entry<AsciiString,​String>> stream()
      Returns a Stream that yields all header entries.
    • valueStream

      default Stream<String> valueStream​(CharSequence name)
      Returns a Stream that yields all values of the headers with the specified name.