Interface RequestHeaders

All Superinterfaces:
HttpHeaders, HttpObject, Iterable<Map.Entry<AsciiString,String>>

public interface RequestHeaders extends HttpHeaders
Immutable HTTP/2 headers for an HttpRequest.
See Also:
  • Method Details

    • builder

      static RequestHeadersBuilder builder()
      Returns a new empty builder.
    • builder

      static RequestHeadersBuilder builder(HttpMethod method, String path)
      Returns a new builder with the specified HttpMethod and path.
    • of

      static RequestHeaders of(HttpMethod method, String path)
      Returns a new RequestHeaders with the specified HttpMethod and path.
    • of

      static RequestHeaders of(HttpMethod method, String path, CharSequence name, String value)
      Returns a new RequestHeaders with the specified HttpMethod, path and an additional header.
    • of

      static RequestHeaders of(HttpMethod method, String path, CharSequence name, Object value)
      Returns a new RequestHeaders with the specified HttpMethod, path and an additional header. The value is converted into a String as explained in Specifying a non-String header value.
    • of

      static RequestHeaders of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2)
      Returns a new RequestHeaders with the specified HttpMethod, path and additional headers.
    • of

      static RequestHeaders of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2)
      Returns a new RequestHeaders with the specified HttpMethod, path and additional headers. The values are converted into Strings as explained in Specifying a non-String header value.
    • of

      static RequestHeaders of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2, CharSequence name3, String value3)
      Returns a new RequestHeaders with the specified HttpMethod, path and additional headers.
    • of

      static RequestHeaders of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2, CharSequence name3, Object value3)
      Returns a new RequestHeaders with the specified HttpMethod, path and additional headers. The values are converted into Strings as explained in Specifying a non-String header value.
    • of

      static RequestHeaders of(HttpMethod method, String path, CharSequence name1, String value1, CharSequence name2, String value2, CharSequence name3, String value3, CharSequence name4, String value4)
      Returns a new RequestHeaders with the specified HttpMethod, path and additional headers.
    • of

      static RequestHeaders of(HttpMethod method, String path, CharSequence name1, Object value1, CharSequence name2, Object value2, CharSequence name3, Object value3, CharSequence name4, Object value4)
      Returns a new RequestHeaders with the specified HttpMethod, path and additional headers. The values are converted into Strings as explained in Specifying a non-String header value.
    • of

      static RequestHeaders of(HttpHeaders headers)
      Returns a new RequestHeaders copied from the specified HttpHeaders.
      Throws:
      IllegalArgumentException - if the specified HttpHeaders does not have ":method" or ":path" header.
    • toBuilder

      Description copied from interface: HttpHeaders
      Returns a new builder created from the entries of this headers.
      Specified by:
      toBuilder in interface HttpHeaders
      See Also:
    • withMutations

      default RequestHeaders withMutations(Consumer<HttpHeadersBuilder> mutator)
      Description copied from interface: HttpHeaders
      Returns a new headers which is the result from the mutation by the specified Consumer. This method is a shortcut for:
      
       builder = toBuilder();
       mutator.accept(builder);
       return builder.build();
       
      Specified by:
      withMutations in interface HttpHeaders
      See Also:
    • isEndOfStream

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

      long contentLength()
      Returns the value of the content-length header, or -1 if this value is not known.
    • contentType

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

      @Nullable @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

      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
    • getLast

      Returns the value of a header with the specified name. If there are more than one value for the specified name, the last value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the last header value if the header is found, or null if there's no such header
    • getLast

      String getLast(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 last value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      defaultValue - the default value
      Returns:
      the last 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.
    • getBoolean

      Returns the boolean 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 boolean value of the first value in insertion order or null if there is no such header or it can't be converted to boolean.
    • getBoolean

      boolean getBoolean(CharSequence name, boolean defaultValue)
      Returns the boolean 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 boolean value of the first value in insertion order or defaultValue if there is no such header or it can't be converted to boolean.
    • getLastBoolean

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

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

      Returns the int value of a header with the specified name. If there are more than one value for the specified name, the last value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the int value of the last value in insertion order or null if there is no such header or it can't be converted to int.
    • getLastInt

      int getLastInt(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 last 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 last value in insertion order or defaultValue if there is no such header or it can't be converted to int.
    • getInt

      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

      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.
    • getLastLong

      @Nullable @Nullable Long getLastLong(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 last value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the long value of the last value in insertion order or null if there is no such header or it can't be converted to long.
    • getLastLong

      long getLastLong(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 last 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 last value in insertion order or defaultValue if there is no such header or it can't be converted to long.
    • getFloat

      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.
    • getLastFloat

      @Nullable @Nullable Float getLastFloat(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 last value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the float value of the last value in insertion order or null if there is no such header or it can't be converted to float.
    • getLastFloat

      float getLastFloat(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 last 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 last value in insertion order or defaultValue if there is no such header or it can't be converted to float.
    • getDouble

      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.
    • getLastDouble

      @Nullable @Nullable Double getLastDouble(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 last value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the double value of the last value in insertion order or null if there is no such header or it can't be converted to double.
    • getLastDouble

      double getLastDouble(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 last 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 last value in insertion order or defaultValue if there is no such header or it can't be converted to double.
    • getTimeMillis

      @Nullable @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.
    • getLastTimeMillis

      @Nullable @Nullable Long getLastTimeMillis(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 last value in insertion order is returned.
      Parameters:
      name - the name of the header to retrieve
      Returns:
      the milliseconds value of the last value in insertion order or null if there is no such header or it can't be converted to milliseconds.
    • getLastTimeMillis

      long getLastTimeMillis(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 last 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 last 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
    • containsBoolean

      boolean containsBoolean(CharSequence name, boolean 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

      Returns the value of the ":scheme" header or null if there is no such header.
    • 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

      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 @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 @Nullable 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.
    • accept

      List<MediaType> accept()
      Returns the parsed Accept header or an empty List if there is no such header. The returned MediaTypes will be sorted according to client preference.