Class 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 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 Description
      protected static org.apache.commons.lang3.time.FastDateFormat HTTP_DATE  
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpHeaderUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void applyHeaders​(javax.servlet.http.HttpServletResponse httpServletResponse, org.springframework.http.HttpHeaders headers)
      Applies the given HttpHeaders to the HttpServletResponse.
      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 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 org.springframework.http.HttpHeaders parse​(javax.servlet.http.HttpServletRequest httpServletRequest)
      Parses the string-based HTTP headers of the given HttpServletRequest to an HttpHeaders object.
    • Field Detail

      • 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