Class HTTPResponse
java.lang.Object
com.pushtechnology.diffusion.api.webserver.HTTPResponse
HTTPResponse
 
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.
- Since:
- 4.1
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionGenerate a HTTP Response from the details provided and populate a newly created Byte Buffer.Returns a HashMap of the existing headers.booleanIndicates whether compression is enabled.voidpopulateResponseBuffer(ByteBuffer buffer) Generate a HTTP Response from the details provided and populate the ByteBuffer.removeHeader(String header) Removes a header from the response.voidsetBody(byte[] bytes) Set the body of the HTTP request.voidsetBody(ByteBuffer bb) Set the body of the HTTP request.voidSets transfer encoding header to chunked.voidsetCompressionEnabled(boolean enabled) Toggles the response to be compressed or not.voidSets the connection header to close.voidSets the Keep-Alive header.voidsetContentLength(int length) Sets the content length header.voidSets the session cookie header.voidsetCorsResponseOrigin(String origin) Sets the cors response origin header.voidSets the Etag header.voidAdds a header to the response.voidIf this method is called, then the resulting response will be a HEAD response only.voidsetLastModifiedDate(long date) Sets the Last Modified header to the date supplied.voidsetMimeType(String type) Change the default mime type.voidSets cache control to no-store, no-cache.voidsetResponseCode(int responseCode) Set the response code for the HTTP response, default is 200.
- 
Constructor Details- 
HTTPResponsepublic HTTPResponse()Creates an HTTP Response object.
 
- 
- 
Method Details- 
isCompressionEnabledpublic boolean isCompressionEnabled()Indicates whether compression is enabled.- Returns:
- true if compression is enabled, else false
 
- 
setMimeTypeChange the default mime type.- Parameters:
- type- the mime type
 
- 
setResponseCodepublic void setResponseCode(int responseCode) Set the response code for the HTTP response, default is 200.- Parameters:
- responseCode- the response code
- Since:
- 4.1
 
- 
setHeadResponsepublic void setHeadResponse()If this method is called, then the resulting response will be a HEAD response only.- Since:
- 4.1
 
- 
setCompressionEnabledpublic void setCompressionEnabled(boolean enabled) Toggles the response to be compressed or not.- Parameters:
- enabled- true to set compression enabled.
- Since:
- 4.1
 
- 
setLastModifiedDatepublic void setLastModifiedDate(long date) Sets the Last Modified header to the date supplied.- Parameters:
- date- the last modified data to set
- Since:
- 4.1
 
- 
setHeaderAdds a header to the response.- Parameters:
- header- the header
- value- the header value
- Since:
- 4.1
 
- 
removeHeaderRemoves a header from the response.- Parameters:
- header- the header to remove
- Returns:
- the previous value or null if not found
- Since:
- 4.1
 
- 
setETagSets the Etag header.- Parameters:
- etag- the value
- Since:
- 4.1
 
- 
getHeadersReturns a HashMap of the existing headers.- Returns:
- the headers
- Since:
- 4.1
 
- 
setConnectionKeepAlivepublic void setConnectionKeepAlive()Sets the Keep-Alive header.- Since:
- 4.1
 
- 
setConnectionClosepublic void setConnectionClose()Sets the connection header to close.- Since:
- 4.1
 
- 
setNoCachepublic void setNoCache()Sets cache control to no-store, no-cache.- Since:
- 4.1
 
- 
setChunkedEncodingpublic void setChunkedEncoding()Sets transfer encoding header to chunked.- Since:
- 4.1
 
- 
setCookieSets the session cookie header.- Parameters:
- token- the token
- Since:
- 4.1
 
- 
setCorsResponseOriginSets the cors response origin header.- Parameters:
- origin- the origin header value
- Since:
- 4.1
 
- 
setContentLengthpublic void setContentLength(int length) Sets the content length header.- Parameters:
- length- the content length
- Since:
- 4.1
 
- 
populateResponseBufferGenerate a HTTP Response from the details provided and populate the ByteBuffer. The buffer will not be flipped for output.- Parameters:
- buffer- the buffer to populate
- Throws:
- IOException- if population of buffer fails
- Since:
- 4.1
 
- 
generateResponseBufferGenerate a HTTP Response from the details provided and populate a newly created Byte Buffer.- Returns:
- a ByteBuffer which has been flipped ready for output
- Throws:
- IOException- if generation of response buffer fails
- Since:
- 4.1
 
- 
setBodySet the body of the HTTP request.- Since:
- 4.1
 
- 
setBodypublic void setBody(byte[] bytes) Set the body of the HTTP request.- Since:
- 6.5
 
 
-