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.
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.
|
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.
|
String |
removeHeader(String header)
Removes a header from the response.
|
void |
setBody(byte[] bytes)
Set the body of the HTTP request.
|
void |
setBody(ByteBuffer bb)
Set the body of the HTTP request.
|
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 |
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.
|
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 setCorsResponseOrigin(String origin)
origin
- the origin header valuepublic void setContentLength(int length)
length
- the content lengthpublic 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 void setBody(ByteBuffer bb)
public void setBody(byte[] bytes)
Copyright © 2021 Push Technology Ltd. All Rights Reserved.