com.holonplatform.http.internal

## Class HttpUtils

- java.lang.Object
- - com.holonplatform.http.internal.HttpUtils

- All Implemented Interfaces:
    Serializable

      public final class HttpUtils
      extends Object
      implements Serializable

  Utility class for HTTP.
  Since:
    5.0.0
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String[]` | `DATE_FORMATS` Request header date formats as specified in the HTTP RFC

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String[]` | `extractAuthorizationBasicCredentials(String header)` Extract credentials from a Basic Authorization header, if valid
    `static String` | `extractAuthorizationBearer(String header)` Try to extract the value of a Bearer Authorization header
    `static List<Locale>` | `getAcceptLanguageLocales(String header)` Try to get a list of `Locale` from HTTP request from `HttpHeaders.ACCEPT_LANGUAGE` header, if not null.
    `static Map<String,List<String>>` | `getAsMultiMap(Object payload)` Try to obtain given payload Object as a String multi map
    `static boolean` | `isBasicAuthorizationHeader(String header)` Check if given header value is a Basic authorization header
    `static boolean` | `isBearerAuthorizationHeader(String header)` Check if given header value is a Bearer authorization header
    `static boolean` | `isEmpty(String headerValue)` Check if given value is null or empty
    `static boolean` | `isSecure(URI uri)` Check if given URI is "secure", i.e.
    `static Date` | `parseHeaderDate(String headerValue)` Get a header date value as `Date`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DATE_FORMATS

          public static final String[] DATE_FORMATS

      Request header date formats as specified in the HTTP RFC
      See Also:
        Section 7.1.1.1 of RFC 7231

  - ### Method Detail

    - #### isSecure

          public static boolean isSecure(URI uri)

      Check if given URI is "secure", i.e. has HTTPS as scheme
      Parameters:
        `uri` - URI to check
      Returns:
        `true` if URI has HTTPS as scheme

    - #### parseHeaderDate

          public static Date parseHeaderDate(String headerValue)

      Get a header date value as `Date`
      Parameters:
        `headerValue` - Header
      Returns:
        Date or `null` if header is null or invalid

    - #### getAcceptLanguageLocales

          public static List<Locale> getAcceptLanguageLocales(String header)

      Try to get a list of `Locale` from HTTP request from `HttpHeaders.ACCEPT_LANGUAGE` header, if not null. If more than one language is specified in Accept-Language header, returned Locales will be ordered relying on quality parameter, if specified.
      Parameters:
        `header` - Accept-Language header
      Returns:
        List of Locale for the languages of the Accept-Language header, if any. If header is not present, an empty list is returned.

    - #### isBearerAuthorizationHeader

          public static boolean isBearerAuthorizationHeader(String header)

      Check if given header value is a Bearer authorization header
      Parameters:
        `header` - Header value
      Returns:
        `true` if header starts with Bearer prefix

    - #### isBasicAuthorizationHeader

          public static boolean isBasicAuthorizationHeader(String header)

      Check if given header value is a Basic authorization header
      Parameters:
        `header` - Header value
      Returns:
        `true` if header starts with Basic prefix

    - #### extractAuthorizationBearer

          public static String extractAuthorizationBearer(String header)

      Try to extract the value of a Bearer Authorization header
      Parameters:
        `header` - Header value
      Returns:
        Extracted bearer value, or `null` if header is null or invalid

    - #### extractAuthorizationBasicCredentials

          public static String[] extractAuthorizationBasicCredentials(String header)

      Extract credentials from a Basic Authorization header, if valid
      Parameters:
        `header` - Header value
      Returns:
        A string array with username at index 0 and password at index 1, or null if header is not valid or it is not a Basic authorization header

    - #### getAsMultiMap

          public static Map<String,List<String>> getAsMultiMap(Object payload)

      Try to obtain given payload Object as a String multi map
      Parameters:
        `payload` - Payload (may be null)
      Returns:
        Optional String multi map

    - #### isEmpty

          public static boolean isEmpty(String headerValue)

      Check if given value is null or empty
      Parameters:
        `headerValue` - Header value
      Returns:
        `true` if value is null or empty

Copyright © 2019 The Holon Platform. All rights reserved.