Interface ResponseRequestContextAddon<R extends RequestContext<?>>
- All Known Implementing Classes:
SpincastResponseRequestContextAddon
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The placeholder to replace by the current cache buster when pushing a resource on HTTP/2. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAlert
(AlertLevel level, String message) Adds an Alert that is, in general, displayed at the top of the page to show the user an Error, a Warning or a confirmation message.void
Adds aForm
object to the response's model and links its validation messages to the default "validation" root element.void
Adds aForm
object to the response's model and links its validation messages to the specified validation element.addHeaderValue
(String name, String value) Adds a value to a response header.addHeaderValues
(String name, List<String> values) Adds a list of values to a response header.createCookie
(String name) Creates a cookie using the given name (null
value).void
Deletes all cookies! Not only the new cookies that have been added to the response, but also the cookies that have been received in the request!void
deleteCookie
(String name) Deletes a cookie.void
end()
Flushes everything and closes the response.void
flush()
Flushes the current response.void
flush
(boolean close) Flushes the current response.The charset to use to convert characters to bytes.The currentContent-Type
sent or to be send.getCookieAdded
(String name) Gets a cookie already added to the response, by its name.Gets the cookies already added to the response as a Map, using their names as the keys.The currently set gzip options.The values of a specific response header.getHeaderFirst
(String name) The first value of a specific header.The currently set response headers.getModel()
TheJsonObject
which serves as the model for the response.int
The currentstatus code
sent or to be send.byte[]
Gets the current unsent bytes (AKA the buffer).Gets the current unsent characters (AKA the buffer), using theUTF-8
encoding.getUnsentCharacters
(String encoding) Gets the current unsent characters (AKA the buffer), using the specified encoding.boolean
isClosed()
Is the response closed? If so, nothing more can be sent...boolean
Are the response headers sent? If this is the case, then the headers can't be changed anymore.IfHTTP/2
is used, you can push extra resources at the same time you response to a request.void
redirect()
Sets a temporarily redirection header (302) to the current page.void
Sets a temporarily redirection header (302).void
Sets a redirection header.void
redirect
(String newUrl, boolean permanently, FlashMessage flashMessage) Sets a redirection header, with a Flash message to display.void
redirect
(String newUrl, boolean permanently, FlashMessageLevel flashMessageType, String flashMessageText) Sets a redirection header, with a Flash message to display.void
redirect
(String newUrl, boolean permanently, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables) Sets a redirection header, with a Flash message to display.void
Sets the redirection headers with a specified3xx
status code.void
redirect
(String newUrl, int specific3xxCode, FlashMessage flashMessage) Sets the redirection headers with a specified3xx
status code, and a Flash message to display.void
redirect
(String newUrl, int specific3xxCode, FlashMessageLevel flashMessageType, String flashMessageText) Sets the redirection headers with a specified3xx
status code, and a Flash message to display.void
redirect
(String newUrl, int specific3xxCode, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables) Sets the redirection headers with a specified3xx
status code, and a Flash message to display.void
redirect
(String newUrl, FlashMessage flashMessage) Sets a temporarily redirection header (302), with a Flash message to display.void
redirect
(String newUrl, FlashMessageLevel flashMessageType, String flashMessageText) Sets a temporarily redirection header (302), with a Flash message to display.void
redirect
(String newUrl, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables) Sets a temporarily redirection header (302), with a Flash message to display.void
redirect
(String newUrl, JsonObject flashMessageVariables) Sets a temporarily redirection header (302), with a Flash variables.void
redirect
(FlashMessage flashMessage) Sets a temporarily redirection header (302) to the current page, with a Flash message to display.void
redirect
(FlashMessageLevel flashMessageType, String flashMessageText) Sets a temporarily redirection header (302) to the current page, with a Flash message to display.void
redirect
(FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables) Sets a temporarily redirection header (302) to the current page, with a Flash message to display.removeHeader
(String name) Removes an header by its name.Clears the buffer (the unsent buffer, of course).Clears the buffer (the unsent buffer, of course!), resets the cookies, the headers, theContent-Type
and sets thestatus code
back to200
.resetEverything
(boolean resetCookies) Clears the buffer (the unsent buffer, of course), the headers, theContent-Type
and sets thestatus code
back to200
.void
sendBytes
(byte[] bytes) Sends somebytes
, without flushing.void
Sends somebytes
using the specifiedContent-Type
, without flushing.void
Sends somebytes
using the specifiedContent-Type
and flushes, if specified.void
sendCharacters
(String content, String contentType) Sends a String, using the encoding returned bygetCharactersCharsetName
and using the specifiedContent-Type
, without flushing.void
sendCharacters
(String content, String contentType, boolean flush) Sends a String, using the encoding returned bygetCharactersCharsetName
and using the specifiedContent-Type
.void
Sends a String astext/html
,UTF-8
encoded, without flushing.void
Sends a String astext/html
,UTF-8
encoded, and flushes, if specified.void
sendJson()
Sends the model asapplication/json
, without flushing.void
sendJson
(boolean flush) Sends the model asapplication/json
, and flushes, if specified.void
Serializes the object toJson
and sends asapplication/json
, without flushing.void
Serializes the object toJson
, sends asapplication/json
, and flushes, if specified.void
Sends aJson
String using theapplication/json
Content-Type, without flushing.void
Sends aJson
String using theapplication/json
Content-Type, and flushes, if specified.void
Parses the given String using theTemplatingEngine
, then sends the result using the specifiedContent-Type
, without flushing.void
Parses the given String using theTemplatingEngine
, then sends the result using the specifiedContent-Type
, and flushes, if specified.void
sendParseHtml
(String html) Parses the given String using theTemplatingEngine
and the given parameters, then sends the result astext/html
,UTF-8
encoded.void
sendParseHtml
(String html, boolean flush) Parses the given String using theTemplatingEngine
and the given parameters, then sends the result astext/html
,UTF-8
encoded, and flushes, if specified.void
sendPlainText
(String string) Sends a String astext/plain
,UTF-8
encoded, without flushing.void
sendPlainText
(String string, boolean flush) Sends a String astext/plain
,UTF-8
encoded, and flushes, if specified.void
sendTemplate
(String templatePath, boolean isClasspathPath, String contentType) Finds the specified template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result using the givencontentType
, without flushing.void
sendTemplate
(String templatePath, boolean isClasspathPath, String contentType, boolean flush) Finds the specified template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result using the givencontentType
, and flushes, if specified.void
sendTemplate
(String templatePath, String contentType) Finds the specified template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result using the givencontentType
, without flushing.void
sendTemplate
(String templatePath, String contentType, boolean flush) Finds the specified template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result using the givencontentType
, and flushes, if specified.void
sendTemplateHtml
(String templatePath) Finds theHTML
template using theTemplatingEngine
, evaluates it using the model that have been added to the response, then sends the result astext/html
,UTF-8
encoded, without flushing.void
sendTemplateHtml
(String templatePath, boolean isClasspathPath) Finds theHTML
template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result astext/html
,UTF-8
encoded.void
sendTemplateHtml
(String templatePath, boolean isClasspathPath, boolean flush) Finds theHTML
template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result astext/html
,UTF-8
encoded, and flushes, if specified.void
sendXml()
Sends the model asapplication/xml
, without flushing.void
sendXml
(boolean flush) Sends the model asapplication/xml
, and flushes, if specified.void
Serializes the object toXML
and sends asapplication/xml
, without flushing.void
Serializes the object toXML
, sends asapplication/xml
, and flushes, if specified.void
Sends someXML
using theapplication/xml
Content-Type, without flushing.void
Sends someXML
using theapplication/xml
Content-Type, and flushes, if specified.setCacheSeconds
(int cacheSeconds) Adds caching headers.setCacheSeconds
(int cacheSeconds, boolean isPrivateCache) Adds caching headers for the specified number of seconds.Sets the charset to use to convert characters to bytes.setContentType
(String responseContentType) TheContent-Type
header to use for the response.void
Sets a cookie using the specified name, value and number of seconds to live.void
Sets a cookie using the specified name, value, number of seconds to live and if it's http only.void
setCookie
(String name, String value, String path, String domain, Date expires, boolean secure, boolean httpOnly, CookieSameSite cookieSameSite, boolean discard, int version) Sets a cookie, using all available configurations.void
Sets a cookie.void
setCookie10years
(String name, String value) Sets a permanent cookie (10 years) using the specified name and value.void
setCookie10yearsSafe
(String name, String value) Sets a permanent cookie (10 years) using the specified name and value.void
setCookie1year
(String name, String value) Sets a permanent cookie (1 years) using the specified name and value.void
setCookie1yearSafe
(String name, String value) Sets a permanent cookie (1 years) using the specified name and value.void
setCookieSession
(String name, String value) Sets a cookie using the specified name and value.void
setCookieSessionSafe
(String name, String value) Sets a cookie using the specified name and value.setGzipOption
(GzipOption gzipOption) Enable or disable gzipping of the response.Set the value to a response header.Set multiple values to a response header.void
setModel
(JsonObject model) Replaces the current response model completely.setStatusCode
(int statusCode) Sets the response'sstatus code
to use.
-
Field Details
-
RESOURCE_TO_PUSH_PLACEHOLDERS_CACHE_BUSTER
The placeholder to replace by the current cache buster when pushing a resource on HTTP/2.- See Also:
-
-
Method Details
-
getModel
JsonObject getModel()TheJsonObject
which serves as the model for the response. This object will be used by the templating engine or will be sent as is, often as anapplication/json
response.This object is mutable.
-
setModel
Replaces the current response model completely.Use
getModel()
instead to get the current model instance and add properties to it. -
isClosed
boolean isClosed()Is the response closed? If so, nothing more can be sent... -
end
void end()Flushes everything and closes the response. Nothing more can be sent after this (but the remainingroute handlers
will still be called). -
isHeadersSent
boolean isHeadersSent()Are the response headers sent? If this is the case, then the headers can't be changed anymore. -
sendBytes
void sendBytes(byte[] bytes) Sends somebytes
, without flushing. -
sendBytes
Sends somebytes
using the specifiedContent-Type
, without flushing. -
sendBytes
Sends somebytes
using the specifiedContent-Type
and flushes, if specified. Note that once the response is flushed, no header can be added or changed anymore. -
getCharactersCharsetName
String getCharactersCharsetName()The charset to use to convert characters to bytes. Defaults to"UTF-8"
. -
setCharactersCharsetName
Sets the charset to use to convert characters to bytes. Defaults to"UTF-8"
. Make sure you use the same charset here than the one that is sent as the"Content-Type"
header (which is also"UTF-8"
by default, if you send data usingsendPlainText()
,sendHtml()
orsendJson()
). -
sendCharacters
Sends a String, using the encoding returned bygetCharactersCharsetName
and using the specifiedContent-Type
, without flushing. -
sendCharacters
Sends a String, using the encoding returned bygetCharactersCharsetName
and using the specifiedContent-Type
. Flushes the response, if specified. Note that once the response is flushed, no header can be added or changed anymore. -
sendPlainText
Sends a String astext/plain
,UTF-8
encoded, without flushing. -
sendPlainText
Sends a String astext/plain
,UTF-8
encoded, and flushes, if specified. Note that once the response is flushed, no header can be added or changed anymore. -
sendJson
void sendJson()Sends the model asapplication/json
, without flushing. -
sendJson
void sendJson(boolean flush) Sends the model asapplication/json
, and flushes, if specified.Note that once the response is flushed, no header can be added or changed anymore.
-
sendJson
Sends aJson
String using theapplication/json
Content-Type, without flushing.Synonym of :
sendCharacters(jsonString, "application/json")
-
sendJson
Sends aJson
String using theapplication/json
Content-Type, and flushes, if specified.Note that once the response is flushed, no header can be added or changed anymore.
Synonym of :
sendCharacters(jsonString, "application/json", flush)
-
sendJson
Serializes the object toJson
and sends asapplication/json
, without flushing.If the specified Object is a
String
, it will be considered as already beingJSON
and will be send as is. -
sendJson
Serializes the object toJson
, sends asapplication/json
, and flushes, if specified.Note that once the response is flushed, no header can be added or changed anymore.
If the specified Object is a
String
, it will be considered as already beingJSON
and will be send as is. -
sendXml
void sendXml()Sends the model asapplication/xml
, without flushing. -
sendXml
void sendXml(boolean flush) Sends the model asapplication/xml
, and flushes, if specified.Note that once the response is flushed, no header can be added or changed anymore.
-
sendXml
Sends someXML
using theapplication/xml
Content-Type, without flushing.Synonym of :
sendCharacters(xml, "application/xml")
-
sendXml
Sends someXML
using theapplication/xml
Content-Type, and flushes, if specified.Note that once the response is flushed, no header can be added or changed anymore.
Synonym of :
sendCharacters(xml, "application/xml", flush)
-
sendXml
Serializes the object toXML
and sends asapplication/xml
, without flushing.If the specified Object is a
String
, it will be considered as already beingXML
and will be send as is. -
sendXml
Serializes the object toXML
, sends asapplication/xml
, and flushes, if specified.Note that once the response is flushed, no header can be added or changed anymore.
If the specified Object is a
String
, it will be considered as already beingXML
and will be send as is. -
sendHtml
Sends a String astext/html
,UTF-8
encoded, without flushing. -
sendHtml
Sends a String astext/html
,UTF-8
encoded, and flushes, if specified. Note that once the response is flushed, no header can be added or changed anymore. -
sendParse
Parses the given String using theTemplatingEngine
, then sends the result using the specifiedContent-Type
, without flushing. -
sendParse
Parses the given String using theTemplatingEngine
, then sends the result using the specifiedContent-Type
, and flushes, if specified. Note that once the response is flushed, no header can be added or changed anymore. -
sendTemplateHtml
Finds theHTML
template using theTemplatingEngine
, evaluates it using the model that have been added to the response, then sends the result astext/html
,UTF-8
encoded, without flushing.- Parameters:
templatePath
- must be a classpath's relative path.
-
sendTemplateHtml
Finds theHTML
template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result astext/html
,UTF-8
encoded.- Parameters:
isClasspathPath
- iftrue
, the 'templatePath' is considered as a classpath's relative path. Iffalse
, it is considered as an absolute file system path.
-
sendTemplateHtml
Finds theHTML
template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result astext/html
,UTF-8
encoded, and flushes, if specified. Note that once the response is flushed, no header can be added or changed anymore.- Parameters:
isClasspathPath
- iftrue
, the 'templatePath' is considered as a classpath's relative path. Iffalse
, it is considered as an absolute file system path.
-
sendTemplate
Finds the specified template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result using the givencontentType
, without flushing.- Parameters:
templatePath
- must be a classpath's relative path.
-
sendTemplate
Finds the specified template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result using the givencontentType
, and flushes, if specified. Note that once the response is flushed, no header can be added or changed anymore.- Parameters:
templatePath
- must be a classpath's relative path.
-
sendTemplate
Finds the specified template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result using the givencontentType
, without flushing.- Parameters:
isClasspathPath
- iftrue
, the 'templatePath' is considered as a classpath's relative path. Iffalse
, it is considered as an absolute file system path.
-
sendTemplate
Finds the specified template using theTemplatingEngine
, evaluates it using the given parameters, then sends the result using the givencontentType
, and flushes, if specified. Note that once the response is flushed, no header can be added or changed anymore.- Parameters:
isClasspathPath
- iftrue
, the 'templatePath' is considered as a classpath's relative path. Iffalse
, it is considered as an absolute file system path.
-
sendParseHtml
Parses the given String using theTemplatingEngine
and the given parameters, then sends the result astext/html
,UTF-8
encoded. -
sendParseHtml
Parses the given String using theTemplatingEngine
and the given parameters, then sends the result astext/html
,UTF-8
encoded, and flushes, if specified. Note that once the response is flushed, no header can be added or changed anymore. -
flush
void flush()Flushes the current response. If not already specified, a defaultstatus code
andContent-Type
will be added. Note that once the response is flushed, no header can be added or changed anymore. -
flush
void flush(boolean close) Flushes the current response. If not already specified on the response, a defaultstatus code
andcontent-type
will be added. Note that once the response is flushed, no header can be added or changed anymore.- Parameters:
close
- Iftrue
, the response will be closed and no more data can be sent. This has the same effect than callingend()
.
-
setStatusCode
Sets the response'sstatus code
to use. Uses200
by default. Note that thisstatus code
can be changed automatically if an exception is thrown. -
getStatusCode
int getStatusCode()The currentstatus code
sent or to be send. -
setContentType
TheContent-Type
header to use for the response. MostsendXXX()
methods will set this automatically. -
getContentType
String getContentType()The currentContent-Type
sent or to be send. -
redirect
void redirect()Sets a temporarily redirection header (302) to the current page.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately. -
redirect
Sets a temporarily redirection header (302) to the current page, with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately. -
redirect
Sets a temporarily redirection header (302) to the current page, with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately. -
redirect
void redirect(FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables) Sets a temporarily redirection header (302) to the current page, with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately. -
redirect
Sets a temporarily redirection header (302).This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately. -
redirect
Sets a temporarily redirection header (302), with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
flashMessage
- A Flash Message to pass to the target page.
-
redirect
Sets a temporarily redirection header (302), with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
flashMessageType
- The type of a Flash Message to pass to the target page.flashMessageText
- The text of a Flash Message to pass to the target page.
-
redirect
void redirect(String newUrl, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables) Sets a temporarily redirection header (302), with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
flashMessageType
- The type of a Flash Message to pass to the target page.flashMessageText
- The text of a Flash Message to pass to the target page.flashMessageVariables
- The variables of a Flash Message to pass to the target page.
-
redirect
Sets a temporarily redirection header (302), with a Flash variables.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
flashMessageVariables
- The variables of a Flash Message to pass to the target page.
-
redirect
Sets a redirection header.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
permanently
- Iftrue
, a301
header will be sent. Iffalse
,302
will be sent.
-
redirect
Sets a redirection header, with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
permanently
- Iftrue
, a301
header will be sent. Iffalse
,302
will be sent.flashMessage
- A Flash Message to pass to the target page.
-
redirect
void redirect(String newUrl, boolean permanently, FlashMessageLevel flashMessageType, String flashMessageText) Sets a redirection header, with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
permanently
- Iftrue
, a301
header will be sent. Iffalse
,302
will be sent.flashMessageType
- The type of a Flash Message to pass to the target page.flashMessageText
- The text of a Flash Message to pass to the target page.
-
redirect
void redirect(String newUrl, boolean permanently, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables) Sets a redirection header, with a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
permanently
- Iftrue
, a301
header will be sent. Iffalse
,302
will be sent.flashMessageType
- The type of a Flash Message to pass to the target page.flashMessageText
- The text of a Flash Message to pass to the target page.flashMessageVariables
- The variables of a Flash Message to pass to the target page.
-
redirect
Sets the redirection headers with a specified3xx
status code.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately. -
redirect
Sets the redirection headers with a specified3xx
status code, and a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
flashMessage
- A Flash Message to pass to the target page.
-
redirect
void redirect(String newUrl, int specific3xxCode, FlashMessageLevel flashMessageType, String flashMessageText) Sets the redirection headers with a specified3xx
status code, and a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
flashMessageType
- The type of a Flash Message to pass to the target page.flashMessageText
- The text of a Flash Message to pass to the target page.
-
redirect
void redirect(String newUrl, int specific3xxCode, FlashMessageLevel flashMessageType, String flashMessageText, JsonObject flashMessageVariables) Sets the redirection headers with a specified3xx
status code, and a Flash message to display.This will NOT close the response and will NOT skip the remaining handlers! Throw a
RedirectException
instead if you want to redirect the user immediately.- Parameters:
flashMessageType
- The type of a Flash Message to pass to the target page.flashMessageText
- The text of a Flash Message to pass to the target page.flashMessageVariables
- The variables of a Flash Message to pass to the target page.
-
addHeaderValue
Adds a value to a response header. If the header already has values, the new one is added. If the value isnull
, it won't be added. -
addHeaderValues
Adds a list of values to a response header. If the header already has values, the new ones are added. If the values arenull
, nothing will be added. -
setHeader
Set the value to a response header. If the header already exists, its current values are overwritten. If the value isnull
, the header will be removed (same behavior asremoveHeader(String name)
) -
setHeader
Set multiple values to a response header. If the header already exists, its current values are overwritten. If the lists isnull
or empty, the header will be removed (same behavior asremoveHeader(String name)
) -
removeHeader
Removes an header by its name. -
getHeaders
The currently set response headers. The map is mutable! Also the returned implementation is aTreeMap
with case insensitive keys. -
getHeader
The values of a specific response header. The list is mutable! The name is case insensitive. Returns an empty list if the header was not found. -
getHeaderFirst
The first value of a specific header. The name is case insensitive. Returnsnull
if the header is not found. -
resetBuffer
ResponseRequestContextAddon<R> resetBuffer()Clears the buffer (the unsent buffer, of course). -
resetEverything
ResponseRequestContextAddon<R> resetEverything()Clears the buffer (the unsent buffer, of course!), resets the cookies, the headers, theContent-Type
and sets thestatus code
back to200
. -
resetEverything
Clears the buffer (the unsent buffer, of course), the headers, theContent-Type
and sets thestatus code
back to200
.- Parameters:
resetCookies
- iftrue
, cookies that have been added on the current response will be reset too.
-
getUnsentBytes
byte[] getUnsentBytes()Gets the current unsent bytes (AKA the buffer). -
getUnsentCharacters
String getUnsentCharacters()Gets the current unsent characters (AKA the buffer), using theUTF-8
encoding. -
getUnsentCharacters
Gets the current unsent characters (AKA the buffer), using the specified encoding. -
setGzipOption
Enable or disable gzipping of the response. The default isGzipOption.DEFAULT
which will gzip the response only for someContent-Types
and only if agzip 'Accept-Encoding'
header has been received from the client. -
getGzipOption
GzipOption getGzipOption()The currently set gzip options. -
setCacheSeconds
Adds caching headers.- Parameters:
seconds
- the number of seconds this response should be cached.
-
setCacheSeconds
Adds caching headers for the specified number of seconds. Adds caching headers.- Parameters:
seconds
- the number of seconds this response should be cached.isPrivateCache
- iftrue
, the cache will be flagged as "private".
-
addAlert
Adds an Alert that is, in general, displayed at the top of the page to show the user an Error, a Warning or a confirmation message.Those alerts are available using the "spincast.alerts" templating variable. If any, a
Flash Messages
is also added to this variable. -
getCookiesAdded
Gets the cookies already added to the response as a Map, using their names as the keys.NOTE : use the
RequestRequestContextAddon.getCookiesValues()
from therequest()
add-on instead to get the cookies sent by the user! -
getCookieAdded
Gets a cookie already added to the response, by its name.NOTE : use the
RequestRequestContextAddon.getCookieValue(String)
from therequest()
add-on instead to get a cookie sent by the user!- Returns:
- the cookie or
null
if not found.
-
createCookie
Creates a cookie using the given name (null
value).By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
and the cookie is valid for the time of the session only.You have to add the cookie using the
setCookie(Cookie)
method after it is properly created. -
setCookie
Sets a cookie. -
setCookieSession
Sets a cookie using the specified name and value.By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
and the cookie is valid for the time of the session only. -
setCookieSessionSafe
Sets a cookie using the specified name and value. The cookie will be "secure", "httpOnly" and aCookieSameSite
value ofCookieSameSite.LAX
.By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
and the cookie is valid for the time of the session only. -
setCookie
Sets a cookie using the specified name, value and number of seconds to live.By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
. -
setCookie
Sets a cookie using the specified name, value, number of seconds to live and if it's http only.By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
. -
setCookie1year
Sets a permanent cookie (1 years) using the specified name and value.By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
. -
setCookie1yearSafe
Sets a permanent cookie (1 years) using the specified name and value. The cookie will be "secure", "httpOnly" and aCookieSameSite
value ofCookieSameSite.LAX
.By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
. -
setCookie10years
Sets a permanent cookie (10 years) using the specified name and value.By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
. -
setCookie10yearsSafe
Sets a permanent cookie (10 years) using the specified name and value. The cookie will be "secure", "httpOnly" and aCookieSameSite
value ofCookieSameSite.LAX
.By default, the public host (
SpincastConfig.getPublicServerHost()
) is uses as the cookie'sdomain
. -
setCookie
void setCookie(String name, String value, String path, String domain, Date expires, boolean secure, boolean httpOnly, CookieSameSite cookieSameSite, boolean discard, int version) Sets a cookie, using all available configurations. -
deleteCookie
Deletes a cookie. In fact, this sets the cookie'sexpires date
in the past so the user's browser will remove it.isExpired()
will returntrue
after you called this method. -
deleteAllCookiesUserHas
void deleteAllCookiesUserHas()Deletes all cookies! Not only the new cookies that have been added to the response, but also the cookies that have been received in the request!In fact, this method sets the
expires date
of the cookies in the past so the user's browser will remove them. -
addForm
Adds aForm
object to the response's model and links its validation messages to the default "validation" root element.In other words, adding a form will result in those elements to the response's model :
- [formName] => the form itself
- [validation] => validation messages for the form with keys such as "[formName].something" and "[formName].somethingElse".
-
addForm
Adds aForm
object to the response's model and links its validation messages to the specified validation element.In other words, adding a form will result in those elements to the response's model :
- [formName] => the form itself
- [validationElementName] => validation messages for the form with keys such as "[formName].something" and "[formName].somethingElse".
-
push
ResponseRequestContextAddon<R> push(HttpMethod httpMethod, String path, Map<String, List<String>> requestHeaders) IfHTTP/2
is used, you can push extra resources at the same time you response to a request.If the embedded server deals with a HTTTP/2 request, it will push the extra resources by itself. If it deals with an HTTP/1.X request (for example if it is behind a reverse-proxy) it will send
Link
headers to the potential proxy in front of it and it is the proxy that will be in charge of doing the actual push.Beware that pushing resources does not always result in an increase of performance and may lead to wasted bandwidth (the client may decide to not use those pushed resources).
- Parameters:
path
- The absolute path to the resource to push, starting with "/" (or it will be added). No scheme, host, port but may contain a querystring.requestHeaders
- The headers for requesting the resource. May benull
. Those headers will only be used if the embedded server pushes the resources by itself. If it is behind a reverse-proxy and ask this proxy to push the resources, those headers won't be used but a "as=" attribute may be added to help the proxy serve the proper content-type.
-