org.appng.api.support

## Class HttpHeaderUtils

- java.lang.Object
- - org.appng.api.support.HttpHeaderUtils

-     public class HttpHeaderUtils
      extends Object

  Utility-class that helps dealing with several HTTP-Headers
  Author:
    Matthias Müller

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `HttpHeaderUtils.HttpResource` A resource that has been requested by an `HttpServletRequest` and eventually needs to be updated.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static org.apache.commons.lang3.time.FastDateFormat` | `HTTP_DATE`
    `static String` | `X_APPNG_REQUIRED_ROLE` Use this header in your `HttpServletResponse` to allow role based access control for cached resources

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpHeaderUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `applyHeaders(javax.servlet.http.HttpServletResponse httpServletResponse, org.springframework.http.HttpHeaders headers)` Applies the given `HttpHeaders` to the `HttpServletResponse`.
    `static byte[]` | `handleModifiedHeaders(org.springframework.http.HttpHeaders requestHeaders, org.springframework.http.HttpHeaders responseHeaders, HttpHeaderUtils.HttpResource resource)` Handles the "Last-Modified" and "If-Modified-Since" headers for the give request/response pair.
    `static byte[]` | `handleModifiedHeaders(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, HttpHeaderUtils.HttpResource resource, boolean output)` Handles the "Last-Modified" and "If-Modified-Since" headers for the give request/response pair.
    `static org.springframework.http.HttpHeaders` | `parse(javax.servlet.http.HttpServletRequest httpServletRequest)` Parses the string-based HTTP headers of the given `HttpServletRequest` to an `HttpHeaders` object.

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

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

- - ### Field Detail

    - #### X_APPNG_REQUIRED_ROLE

          public static final String X_APPNG_REQUIRED_ROLE

      Use this header in your `HttpServletResponse` to allow role based access control for cached resources
      See Also:
        Constant Field Values

    - #### HTTP_DATE

          protected static final org.apache.commons.lang3.time.FastDateFormat HTTP_DATE

  - ### Constructor Detail

    - #### HttpHeaderUtils

          public HttpHeaderUtils()

  - ### Method Detail

    - #### handleModifiedHeaders

          public static byte[] handleModifiedHeaders(javax.servlet.http.HttpServletRequest servletRequest,
                                                     javax.servlet.http.HttpServletResponse servletResponse,
                                                     HttpHeaderUtils.HttpResource resource,
                                                     boolean output)
                                              throws IOException

      Handles the "Last-Modified" and "If-Modified-Since" headers for the give request/response pair. Sets the "Last-Modified"-header for the response and reads the "If-Modified-Since"-header from the request.
      Parameters:
        `servletRequest` - the current `HttpServletRequest`
        `servletResponse` - the current `HttpServletResponse`
        `resource` - the `HttpHeaderUtils.HttpResource` to process
        `output` - whether or not to write the response data to the `OutputStream` of the `HttpServletResponse`, also setting the content-type and content length
      Returns:
        the response-data, which may have a length of 0 in case "If-Modified-Since" was set for the request and the `HttpHeaderUtils.HttpResource` has'nt been updated since then
      Throws:
        `IOException` - if an error occurred while reading/updating the `HttpHeaderUtils.HttpResource`

    - #### handleModifiedHeaders

          public static byte[] handleModifiedHeaders(org.springframework.http.HttpHeaders requestHeaders,
                                                     org.springframework.http.HttpHeaders responseHeaders,
                                                     HttpHeaderUtils.HttpResource resource)
                                              throws IOException

      Handles the "Last-Modified" and "If-Modified-Since" headers for the give request/response pair. Sets the "Last-Modified"-header for the response and reads the "If-Modified-Since"-header from the request.
      Parameters:
        `requestHeaders` - the headers the current `HttpServletRequest`
        `responseHeaders` - the headers of the current `HttpServletResponse`
        `resource` - the `HttpHeaderUtils.HttpResource` to process
      Returns:
        the response-data, which may have a length of 0 in case "If-Modified-Since" was set for the request and the `HttpHeaderUtils.HttpResource` has'nt been updated since then
      Throws:
        `IOException`

    - #### parse

          public static org.springframework.http.HttpHeaders parse(javax.servlet.http.HttpServletRequest httpServletRequest)

      Parses the string-based HTTP headers of the given `HttpServletRequest` to an `HttpHeaders` object.
      Parameters:
        `httpServletRequest` - a `HttpServletRequest`
      Returns:
        The immutable `HttpHeaders`

    - #### applyHeaders

          public static void applyHeaders(javax.servlet.http.HttpServletResponse httpServletResponse,
                                          org.springframework.http.HttpHeaders headers)

      Applies the given `HttpHeaders` to the `HttpServletResponse`.
      Parameters:
        `httpServletResponse` - the response to set the headers for
        `headers` - the headers to apply

Copyright © 2011–2023 aiticon GmbH. All rights reserved.