Class HttpHeaders

Object
se.curity.identityserver.sdk.http.HttpHeaders

public class HttpHeaders extends Object
A read-only view of a set of HTTP headers.

To create a new instance of this class, use the provided HttpHeaders.Builder class.

For convenience, this class provides the build() static method to create an empty builder, as well as a builder() instance method, which copies the headers contained in an instance of HttpHeaders into the initial HttpHeaders.Builder's state.

  • Field Details

  • Method Details

    • headerIsCommaSeparated

      public static boolean headerIsCommaSeparated(String name)
      Returns a boolean for whether the header allows multiple comma separated values.
      Parameters:
      name - the name of the header to be asserted for allowing multiple comma separated values.
      Returns:
      true or false if the header allows multiple comma separated values
      Since:
      4.0.0
    • headerIsSemicolonSeparated

      public static boolean headerIsSemicolonSeparated(String name)
      Returns a boolean for whether the header allows multiple semicolon separated values.
      Parameters:
      name - the name of the header to be asserted for allowing multiple semicolon separated values.
      Returns:
      true or false if the header allows multiple semicolon separated values
      Since:
      4.0.0
    • allValues

      public List<String> allValues(String name)
      Returns an unmodifiable List of all of the values of the given named header.
      Parameters:
      name - the header name
      Returns:
      a List of String header values
    • firstValue

      @Nullable public @Nullable String firstValue(String name)
      Returns an optional String containing the first value of the given named (and possibly multi-valued) header.
      Parameters:
      name - the header name
      Returns:
      the first named value, if it exists
      See Also:
    • firstValueAsLong

      @Nullable public @Nullable Long firstValueAsLong(String name)
      Returns an optional Long containing the first value of the named header field. If the header is not present, then the return value is null. If the header is present but contains a value that does not parse as a Long value, then an exception is thrown.
      Parameters:
      name - the header name
      Returns:
      the first named value as a long, if it exists
      Throws:
      NumberFormatException - if a value is found, but does not parse as a Long
    • singleValueOrError

      @Nullable public @Nullable String singleValueOrError(String name) throws MultipleHeadersException
      Returns an optional String containing the single value of the given named header.

      This method does not allow multiple values to be provided for this header.

      Parameters:
      name - of the header
      Returns:
      the value of the header, if it exists and is a single value
      Throws:
      MultipleHeadersException - in case more than one value exists for the header
    • map

      public Map<String,List<String>> map()
      Returns an unmodifiable multi Map view of this HttpHeaders. This interface should only be used when it is required to iterate over the entire set of headers.

      All header names are returned using capitalized words.

      Returns:
      the Map of headers
    • builder

      public HttpHeaders.Builder builder()
      Create a new HttpHeaders.Builder, setting its initial state with all the headers contained in this instance of HttpHeaders.
      Returns:
      a new builder with this header contents.
    • from

      public static HttpHeaders from(Function<String,List<String>> headerValuesSupplier, Iterable<String> headerNames)
      Create a HttpHeaders instance based on an external source of header values.

      The supplier is used to fetch header values lazily. Once the values of a header are obtained, they are cached internally and will no longer be requested from the supplier.

      Parameters:
      headerValuesSupplier - lazy loader of header values. All header names will be requested using capitalized words, eg. Some-Header.
      headerNames - name of all headers that can be supplied. The names are not case-sensitive.
      Returns:
      a HttpHeaders instance backed by the provided supplier of header values.
    • build

      public static HttpHeaders.Builder build()
      Creates and returns a new Builder.
      Returns:
      a builder