Package 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 Description static interface
HttpHeaderUtils.HttpResource
A resource that has been requested by anHttpServletRequest
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 givenHttpHeaders
to theHttpServletResponse
.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 givenHttpServletRequest
to anHttpHeaders
object.
-
-
-
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 currentHttpServletRequest
servletResponse
- the currentHttpServletResponse
resource
- theHttpHeaderUtils.HttpResource
to processoutput
- whether or not to write the response data to theOutputStream
of theHttpServletResponse
, 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 theHttpHeaderUtils.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 currentHttpServletRequest
responseHeaders
- the headers of the currentHttpServletResponse
resource
- theHttpHeaderUtils.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 givenHttpServletRequest
to anHttpHeaders
object.- Parameters:
httpServletRequest
- aHttpServletRequest
- Returns:
- The immutable
HttpHeaders
-
applyHeaders
public static void applyHeaders(javax.servlet.http.HttpServletResponse httpServletResponse, org.springframework.http.HttpHeaders headers)
Applies the givenHttpHeaders
to theHttpServletResponse
.- Parameters:
httpServletResponse
- the response to set the headers forheaders
- the headers to apply
-
-