public class HTTPResponse extends Object
If you need to generate a HTTP Response, this class can help. Headers and mime types can be set, as well as attributes like compression and minification.
Modifier and Type | Field and Description |
---|---|
static String |
ACCECPT_RANGES
Accept-Ranges header
|
static String |
CACHE_CONTROL
Cache-Control header
|
static String |
CONNECTION
Connection header
|
static String |
CONTENT_ENCODING
Content-Encoding header
|
static String |
CONTENT_LENGTH
Content-Length header
|
static String |
CONTENT_RANGE
Content-Range header
|
static String |
CONTENT_TYPE
Content-Type header
|
static String |
ETAG_BYTES
Etag header
|
static String |
LAST_MODIFIED
Last-Modified header
|
static String |
LOCATION
Location header
|
static String |
RANGE
range header
|
static String |
RANGE_PREFIX
bytes header
|
static String |
SERVER
Server Header
|
static String |
SET_COOKIE_HEADER
Set-Cookie header
|
static String |
TRANSFER_ENCODING_BYTES
Transfer-Encoding header
|
Constructor and Description |
---|
HTTPResponse()
Creates an HTTP Response object
|
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
generateResponseBuffer()
Generate a HTTP Response from the details provided and populate a newly
created Byte Buffer
|
ByteBuffer |
generateResponseBuffer(boolean headersOnly)
Generate a HTTP Response from the details provided and populate a newly
created Byte Buffer, optionally only creating the HTTP headers.
|
HashMap<String,String> |
getHeaders()
Returns a HashMap of the existing headers
|
boolean |
isCompressionEnabled()
Indicates whether compression is enabled
|
void |
populateResponseBuffer(ByteBuffer buffer)
Generate a HTTP Response from the details provided and populate the
ByteBuffer The buffer will not be flipped for output
|
String |
removeHeader(String header)
Removes a header from the response
|
void |
setBody(ByteBuffer buffer)
Set the body of the HTTP request, the buffer needs to be positioned
correctly
|
void |
setChunkedEncoding()
Sets transfer encoding header to chunked
|
void |
setCompressionEnabled(boolean enabled)
Toggles the response to be compressed or not
|
void |
setConnectionClose()
Sets the connection header to close
|
void |
setConnectionKeepAlive()
Sets the Keep-Alive header
|
void |
setContentLength(int length)
Sets the content length header
|
void |
setContentRange(com.pushtechnology.diffusion.http.HTTPByteRange byteRange)
Sets the content range header
|
void |
setCookie(String token)
Sets the session cookie header
|
void |
setCorsResponseOrigin(String origin)
Sets the cors response origin header
|
void |
setETag(String etag)
Sets the Etag header
|
void |
setHeader(String header,
String value)
Adds a header to the response
|
void |
setHeadResponse()
If this method is called, then the resulting response will be a HEAD
response only
|
void |
setLastModifiedDate(long date)
Sets the Last Modified header to the date supplied
|
void |
setMimeType(String type)
Change the default mime type
|
void |
setNoCache()
Sets cache control to no-store, no-cache
|
void |
setResponseCode(int responseCode)
Set the response code for the HTTP response, default is 200
|
void |
setServer()
Sets the server header to Diffusion
|
public static final String RANGE
public static final String RANGE_PREFIX
public static final String CONTENT_LENGTH
public static final String CONTENT_TYPE
public static final String CACHE_CONTROL
public static final String TRANSFER_ENCODING_BYTES
public static final String LAST_MODIFIED
public static final String LOCATION
public static final String CONTENT_ENCODING
public static final String ETAG_BYTES
public static final String SERVER
public static final String SET_COOKIE_HEADER
public static final String CONNECTION
public static final String ACCECPT_RANGES
public static final String CONTENT_RANGE
public boolean isCompressionEnabled()
public void setMimeType(String type)
type
- the mime typepublic void setResponseCode(int responseCode)
responseCode
- the response codepublic void setHeadResponse()
public void setCompressionEnabled(boolean enabled)
enabled
- true to set compression enabled.public void setLastModifiedDate(long date)
date
- the last modified data to setpublic void setHeader(String header, String value)
header
- the headervalue
- the header valuepublic String removeHeader(String header)
header
- the header to removepublic void setETag(String etag)
etag
- the valuepublic HashMap<String,String> getHeaders()
public void setConnectionKeepAlive()
public void setConnectionClose()
public void setNoCache()
public void setChunkedEncoding()
public void setCookie(String token)
token
- the tokenpublic void setServer()
public void setCorsResponseOrigin(String origin)
origin
- the origin header valuepublic void setContentLength(int length)
length
- the content lengthpublic void setContentRange(com.pushtechnology.diffusion.http.HTTPByteRange byteRange)
byteRange
- the content rangepublic void populateResponseBuffer(ByteBuffer buffer) throws IOException
buffer
- the buffer to populateIOException
- if population of buffer failspublic ByteBuffer generateResponseBuffer() throws IOException
IOException
- if generation of response buffer failspublic ByteBuffer generateResponseBuffer(boolean headersOnly) throws IOException
headersOnly
- true if only headers are to be createdIOException
- if generation of buffer failspublic void setBody(ByteBuffer buffer)
buffer
- the buffer to set the body fromCopyright © 2016 Push Technology Ltd. All Rights Reserved.