Interface RequestHeadersBuilder

All Superinterfaces:
HttpHeadersBuilder, Iterable<Map.Entry<AsciiString,​String>>

public interface RequestHeadersBuilder
extends HttpHeadersBuilder
Builds a RequestHeaders.
See Also:
RequestHeaders.builder(), RequestHeaders.toBuilder()
  • Method Details

    • build

      Returns a newly created RequestHeaders with the entries in this builder.
      Specified by:
      build in interface HttpHeadersBuilder
      Throws:
      IllegalStateException - if this builder does not have ":method" and ":path" headers set.
    • method

      RequestHeadersBuilder method​(HttpMethod method)
      Sets the ":method" header.
    • path

      Sets the ":path" header.
    • scheme

      RequestHeadersBuilder scheme​(String scheme)
      Sets the ":scheme" header.
    • scheme

      default RequestHeadersBuilder scheme​(SessionProtocol sessionProtocol)
      Sets the ":scheme" header from the specified SessionProtocol.
    • authority

      RequestHeadersBuilder authority​(String authority)
      Sets the ":authority" header.
    • authority

      default RequestHeadersBuilder authority​(Endpoint endpoint)
      Sets the ":authority" header from the specified Endpoint.
      Throws:
      IllegalArgumentException - if the specified Endpoint refers to a group
    • acceptLanguages

      RequestHeadersBuilder acceptLanguages​(Iterable<Locale.LanguageRange> acceptedLanguages)
      Sets the "accept-language" header.
      Parameters:
      acceptedLanguages - the accepted languages.
      Returns:
      this
    • acceptLanguages

      default RequestHeadersBuilder acceptLanguages​(Locale.LanguageRange... acceptedLanguages)
      Sets the "accept-language" header.
      Parameters:
      acceptedLanguages - the accepted languages.
      Returns:
      this
    • cookie

      RequestHeadersBuilder cookie​(Cookie cookie)
      Sets the cookie header.
    • cookies

      RequestHeadersBuilder cookies​(Iterable<? extends Cookie> cookies)
      Sets the cookie header.
    • cookies

      RequestHeadersBuilder cookies​(Cookie... cookies)
      Sets the cookie header.
    • sizeHint

      RequestHeadersBuilder sizeHint​(int sizeHint)
      Description copied from interface: HttpHeadersBuilder
      Specifies the hint about the number of headers which may improve the memory efficiency and performance of the underlying data structure.
      Specified by:
      sizeHint in interface HttpHeadersBuilder
      Returns:
      this
    • endOfStream

      RequestHeadersBuilder endOfStream​(boolean endOfStream)
      Description copied from interface: HttpHeadersBuilder
      Sets whether the headers will be the last frame in an HTTP/2 stream.
      Specified by:
      endOfStream in interface HttpHeadersBuilder
    • contentType

      RequestHeadersBuilder contentType​(MediaType contentType)
      Description copied from interface: HttpHeadersBuilder
      Sets the "content-type" header.
      Specified by:
      contentType in interface HttpHeadersBuilder
    • contentDisposition

      RequestHeadersBuilder contentDisposition​(ContentDisposition contentDisposition)
      Description copied from interface: HttpHeadersBuilder
      Sets the "content-disposition" header.
      Specified by:
      contentDisposition in interface HttpHeadersBuilder
    • add

      Description copied from interface: HttpHeadersBuilder
      Adds a new header with the specified name and value.
      Specified by:
      add in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • add

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

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

      RequestHeadersBuilder add​(Iterable<? extends Map.Entry<? extends CharSequence,​String>> entries)
      Description copied from interface: HttpHeadersBuilder
      Adds all header names and values of the specified entries.
      Specified by:
      add in interface HttpHeadersBuilder
      Returns:
      this
    • addObject

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

      RequestHeadersBuilder addObject​(CharSequence name, Iterable<?> values)
      Description copied from interface: HttpHeadersBuilder
      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);
       }
       
      Specified by:
      addObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • addObject

      RequestHeadersBuilder addObject​(CharSequence name, Object... values)
      Description copied from interface: HttpHeadersBuilder
      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);
       }
       
      Specified by:
      addObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • addObject

      RequestHeadersBuilder addObject​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> entries)
      Description copied from interface: HttpHeadersBuilder
      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.
      Specified by:
      addObject in interface HttpHeadersBuilder
      Returns:
      this
    • addInt

      RequestHeadersBuilder addInt​(CharSequence name, int value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addInt in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addLong

      RequestHeadersBuilder addLong​(CharSequence name, long value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addLong in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addFloat

      RequestHeadersBuilder addFloat​(CharSequence name, float value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addFloat in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addDouble

      RequestHeadersBuilder addDouble​(CharSequence name, double value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addDouble in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • addTimeMillis

      RequestHeadersBuilder addTimeMillis​(CharSequence name, long value)
      Description copied from interface: HttpHeadersBuilder
      Adds a new header.
      Specified by:
      addTimeMillis in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • set

      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name and value. Any existing headers with the same name are overwritten.
      Specified by:
      set in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • set

      Description copied from interface: HttpHeadersBuilder
      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);
       }
       
      Specified by:
      set in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • set

      RequestHeadersBuilder set​(CharSequence name, String... values)
      Description copied from interface: HttpHeadersBuilder
      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);
       }
       
      Specified by:
      set in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the header values
      Returns:
      this
    • set

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

      RequestHeadersBuilder setIfAbsent​(Iterable<? extends Map.Entry<? extends CharSequence,​String>> entries)
      Description copied from interface: HttpHeadersBuilder
      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));
           }
       });
       
      Specified by:
      setIfAbsent in interface HttpHeadersBuilder
      Returns:
      this
    • setObject

      RequestHeadersBuilder setObject​(CharSequence name, Object value)
      Description copied from interface: HttpHeadersBuilder
      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.
      Specified by:
      setObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the value of the header
      Returns:
      this
    • setObject

      RequestHeadersBuilder setObject​(CharSequence name, Iterable<?> values)
      Description copied from interface: HttpHeadersBuilder
      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);
       }
       
      Specified by:
      setObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the values of the header
      Returns:
      this
    • setObject

      RequestHeadersBuilder setObject​(CharSequence name, Object... values)
      Description copied from interface: HttpHeadersBuilder
      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);
       }
       
      Specified by:
      setObject in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      values - the values of the header
      Returns:
      this
    • setObject

      RequestHeadersBuilder setObject​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> entries)
      Description copied from interface: HttpHeadersBuilder
      Retains all current headers but calls HttpHeadersBuilder.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.
      Specified by:
      setObject in interface HttpHeadersBuilder
      Parameters:
      entries - the headers used to set the values in this instance
      Returns:
      this
    • setInt

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

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

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

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

      RequestHeadersBuilder setTimeMillis​(CharSequence name, long value)
      Description copied from interface: HttpHeadersBuilder
      Sets a header with the specified name to value. This will remove all previous values associated with name.
      Specified by:
      setTimeMillis in interface HttpHeadersBuilder
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this
    • removeAndThen

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

      Description copied from interface: HttpHeadersBuilder
      Removes all headers. After a call to this method, size() becomes 0.
      Specified by:
      clear in interface HttpHeadersBuilder
      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.
    • uri

      URI uri()
      Returns the request URI generated from the ":scheme", ":authority" and ":path" headers.
      Throws:
      IllegalStateException - if any of the required headers do not exist or the resulting URI is not valid.
    • method

      HttpMethod method()
      Returns the value of the ":method" header as an HttpMethod. HttpMethod.UNKNOWN is returned if the value is not defined in HttpMethod.
      Throws:
      IllegalStateException - if there is no such header.
    • path

      String path()
      Returns the value of the ":path" header.
      Throws:
      IllegalStateException - if there is no such header.
    • scheme

      @Nullable String scheme()
      Returns the value of the ":scheme" header or null if there is no such header.
    • authority

      @Nullable String authority()
      Returns the value of the ":authority" for HTTP/2 request or "Host" header for HTTP/1.1. null if there is no such headers.
    • acceptLanguages

      @Nullable List<Locale.LanguageRange> acceptLanguages()
      Returns a list of Locale.LanguageRanges that are specified in HttpHeaderNames.ACCEPT_LANGUAGE in the order of client preferences.
      Returns:
      All Locale.LanguageRanges of all matching headers or null if there is a parsing error or if there is no header.
    • selectLocale

      @Nullable Locale selectLocale​(Iterable<Locale> supportedLocales)
      Matches the Locales supported by the server to the HttpHeaderNames.ACCEPT_LANGUAGE and returns the best match according to client preference. It does this via Basic Filtering each Locale.LanguageRange and picking the first match. This is the "classic" algorithm described in RFC2616 Accept-Language (obsoleted) and also referenced in RFC7231 Accept-Language. See also Locale.lookup(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>) for another algorithm.
      Parameters:
      supportedLocales - a Iterable of Locales supported by the server.
      Returns:
      The best matching Locale or null if no locale matches.
    • selectLocale

      @Nullable default Locale selectLocale​(Locale... supportedLocales)
      Matches the Locales supported by the server to the HttpHeaderNames.ACCEPT_LANGUAGE and returns the best match according to client preference. It does this via Basic Filtering each Locale.LanguageRange and picking the first match. This is the "classic" algorithm described in RFC2616 Accept-Language (obsoleted) and also referenced in RFC7231 Accept-Language. See also Locale.lookup(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>) for another algorithm.
      Parameters:
      supportedLocales - Locales supported by the server.
      Returns:
      The best matching Locale or null if no locale matches.
    • cookies

      Cookies cookies()
      Returns the parsed cookie header.
      Returns:
      a Cookies or an empty Cookies if there is no such header.