public class PageInfo
extends java.lang.Object
implements java.io.Serializable
HttpServletResponse
.
Based on net.sf.ehcache.constructs.web.PageInfo and grails.plugin.springcache.web.HeadersCategory.Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
contentType |
protected java.util.Date |
created |
protected static int |
FOUR_KB |
protected static int |
GZIP_MAGIC_NUMBER_BYTE_1 |
protected static int |
GZIP_MAGIC_NUMBER_BYTE_2 |
protected byte[] |
gzippedBody |
protected HttpDateFormatter |
httpDateFormatter |
protected static java.util.Set<java.lang.String> |
IGNORED_INTERFACES |
protected static long |
ONE_YEAR_IN_SECONDS |
protected static java.util.regex.Pattern |
PATTERN_CACHE_DIRECTIVE |
protected java.util.Map<java.lang.String,java.io.Serializable> |
requestAttributes |
protected java.util.List<Header<? extends java.io.Serializable>> |
responseHeaders |
protected java.util.List<SerializableCookie> |
serializableCookies |
protected int |
statusCode |
protected boolean |
storeGzipped |
protected long |
timeToLiveSeconds |
protected byte[] |
ungzippedBody |
Constructor and Description |
---|
PageInfo(int statusCode,
java.lang.String contentType,
byte[] body,
boolean storeGzipped,
long timeToLiveSeconds,
java.util.Collection<Header<? extends java.io.Serializable>> headers,
java.util.Collection<javax.servlet.http.Cookie> cookies,
java.util.Map<java.lang.String,java.io.Serializable> requestAttributes)
Creates a PageInfo object representing the "page".
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
getCacheDirectives() |
java.lang.String |
getContentType() |
java.util.Date |
getCreated()
The
Date this PageInfo object was created |
long |
getDateHeader(java.lang.String headerName) |
byte[] |
getGzippedBody() |
java.lang.String |
getHeader(java.lang.String headerName) |
java.util.List<Header<? extends java.io.Serializable>> |
getHeaders() |
java.util.Map<java.lang.String,java.io.Serializable> |
getRequestAttributes() |
java.util.List<SerializableCookie> |
getSerializableCookies()
Returns the cookies of the response.
|
int |
getStatusCode()
Returns the status code of the response.
|
long |
getTimeToLiveSeconds()
The time to live in seconds.
|
byte[] |
getUngzippedBody() |
protected byte[] |
gzip(byte[] ungzipped) |
boolean |
hasGzippedBody() |
boolean |
hasUngzippedBody() |
protected boolean |
isBodyParameterGzipped()
The response body will be assumed to be gzipped if the GZIP header has been set.
|
static boolean |
isGzipped(byte[] candidate)
Checks the first two bytes of the candidate byte array for the magic
number 0x677a.
|
protected boolean |
isInvalidObject(java.lang.Object object) |
boolean |
isMatch(javax.servlet.http.HttpServletRequest request)
Returns true if the page's etag header indicates it is the same as the
copy held by the client as indicated by the request's if-none-match
header.
|
boolean |
isModified(javax.servlet.http.HttpServletRequest request)
Returns true if the page's last-modified header indicates it is newer than
the copy held by the client as indicated by the request's if-modified-since header.
|
boolean |
isOk()
Returns true if the response is Ok.
|
protected void |
setCacheableRequestAttributes(java.util.Map<java.lang.String,java.io.Serializable> attributes) |
protected void |
setTimeToLiveWithCheckForNeverExpires(long ttlSeconds)
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html To mark a
response as "never expires," an origin server sends an Expires date
approximately one year from the time the response is sent.
|
protected byte[] |
ungzip(byte[] gzipped)
A highly performant ungzip implementation.
|
protected static final java.util.regex.Pattern PATTERN_CACHE_DIRECTIVE
protected static final int FOUR_KB
protected static final int GZIP_MAGIC_NUMBER_BYTE_1
protected static final int GZIP_MAGIC_NUMBER_BYTE_2
protected static final long ONE_YEAR_IN_SECONDS
protected static final java.util.Set<java.lang.String> IGNORED_INTERFACES
protected final HttpDateFormatter httpDateFormatter
protected final java.util.List<Header<? extends java.io.Serializable>> responseHeaders
protected final java.util.List<SerializableCookie> serializableCookies
protected java.util.Map<java.lang.String,java.io.Serializable> requestAttributes
protected java.lang.String contentType
protected byte[] gzippedBody
protected byte[] ungzippedBody
protected int statusCode
protected boolean storeGzipped
protected java.util.Date created
protected long timeToLiveSeconds
public PageInfo(int statusCode, java.lang.String contentType, byte[] body, boolean storeGzipped, long timeToLiveSeconds, java.util.Collection<Header<? extends java.io.Serializable>> headers, java.util.Collection<javax.servlet.http.Cookie> cookies, java.util.Map<java.lang.String,java.io.Serializable> requestAttributes) throws AlreadyGzippedException
statusCode
- contentType
- cookies
- body
- storeGzipped
- set this to false for images and page fragments which should nevertimeToLiveSeconds
- the time to Live in seconds. 0 means maximum, which is one year per RFC2616.headers
- cookies
- requestAttributes
- AlreadyGzippedException
protected void setTimeToLiveWithCheckForNeverExpires(long ttlSeconds)
ttlSeconds
- accepts 0, which means eternal. If the time is 0 or > one year,
it is set to one year in accordance with the RFC.
Note: PageInfo does not hold a reference to the Element
and therefore does not know what the Element ttl is. It would
normally make most sense to set the TTL to the same as the
element expiry.protected byte[] gzip(byte[] ungzipped) throws java.io.IOException, AlreadyGzippedException
ungzipped
- the bytes to be gzippedjava.io.IOException
AlreadyGzippedException
protected boolean isBodyParameterGzipped()
public static boolean isGzipped(byte[] candidate)
>>14 beshort 0x677a (gzipped)
candidate
- the byte array to checkpublic java.lang.String getContentType()
public byte[] getGzippedBody()
public java.util.List<Header<? extends java.io.Serializable>> getHeaders()
public java.util.List<SerializableCookie> getSerializableCookies()
public int getStatusCode()
public byte[] getUngzippedBody() throws java.io.IOException
java.io.IOException
protected byte[] ungzip(byte[] gzipped) throws java.io.IOException
gzipped
- the gzipped contentjava.io.IOException
public boolean hasGzippedBody()
public boolean hasUngzippedBody()
public boolean isOk()
public java.util.Date getCreated()
Date
this PageInfo object was createdpublic long getTimeToLiveSeconds()
public java.util.Map<java.lang.String,java.io.Serializable> getRequestAttributes()
public java.lang.String getHeader(java.lang.String headerName)
public long getDateHeader(java.lang.String headerName)
public boolean isModified(javax.servlet.http.HttpServletRequest request)
public boolean isMatch(javax.servlet.http.HttpServletRequest request)
public java.util.Map<java.lang.String,java.lang.Object> getCacheDirectives()
protected void setCacheableRequestAttributes(java.util.Map<java.lang.String,java.io.Serializable> attributes)
protected boolean isInvalidObject(java.lang.Object object)