- All Superinterfaces:
Registry
- All Known Subinterfaces:
DefaultContext
- All Known Implementing Classes:
ForwardingContext
- Since:
- 2.0.0
- Author:
- edgar
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Constant forAccept
header.static final ZoneId
Constant for GMT.static final int
Constant for default HTTP port.static final DateTimeFormatter
RFC1123 date formatter.static final String
RFC1123 date pattern.static final int
Constant for default HTTPS port. -
Method Summary
Modifier and TypeMethodDescriptionboolean
True if the given type matches the `Accept` header.Check if the accept type list matches the given produces list and return the most specific media type from produces list.body()
HTTP body which provides access to body content.<T> T
Convert the HTTP body to the given type.<T> T
Convert the HTTP body to the given type.default <T> T
Converts a value (single or hash) into the given type.<T> T
convertOrNull
(ValueNode value, Class<T> type) Converts a value (single or hash) into the given type.Get a cookie matching the given name.Request cookies.<T> T
Convert the HTTP body to the given type.Get a decoder for the given content type or get anStatusCode.UNSUPPORTED_MEDIA_TYPE
.detach
(Route.Handler next) Tells context that response will be generated form a different thread.Dispatch context to a worker threads.Dispatch context to the given executor.A file upload that matches the given field name.files()
All file uploads.All file uploads that matches the given field name.flash()
Flash map.Get a flash attribute.form()
Get form data.<T> T
Convert form data to the given type.Get a form field that matches the given name.formMap()
Form data as single-value map.Forward executing to another route.<T> T
getAttribute
(String key) Get an attribute by his key.Context attributes (a.k.a request attributes).The certificates presented by the client for mutual TLS.default String
Get application context path (a.k.a as base path).getHost()
Return the host that this request was sent to, in general this will be the value of the Host header, minus the port specifier.Return the host and port that this request was sent to, in general this will be the value of the Host.HTTP method in upper-case form.int
getPort()
Return the port that this request was sent to.The name of the protocol the request.The IP address of the client or last proxy that sent the request.long
RequestContent-Length
header or-1
when missing.Request path without decoding (a.k.a raw Path) without query string.RequestContent-Type
header ornull
when missing.getRequestType
(MediaType defaults) RequestContent-Type
header ornull
when missing.Recreates full/entire url of the current request using theHost
header.getRequestURL
(String path) Recreates full/entire request url using theHost
header with a custom path/suffix.boolean
True if response headers are cleared on application error.Get response status code.getResponseHeader
(String name) Get response header.long
Get response content length or-1
when none was set.Get response content type.getRoute()
Matching route.Get the HTTP router (usually this represents an instance ofJooby
.HTTP scheme in lower case.Server host.int
Server port for current request.<T> T
getUser()
Current user ornull
if none was set.header()
Request headers asValueNode
.Get a header that matches the given name.Header as single-value map.boolean
True when request runs in IO threads.default boolean
Test whenever this is a CORS preflight request.boolean
True if response already started.boolean
isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.default Locale
locale()
Returns a locale that best matches the current request or the default locale specified byJooby.setLocales(List)
or by theapplication.lang
configuration property.default Locale
locale
(BiFunction<List<Locale.LanguageRange>, List<Locale>, Locale> filter) Returns a locale that best matches the current request.locales()
Returns a list of locales that best matches the current request as perLocale.filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>, java.util.Locale.FilteringMode)
.locales
(BiFunction<List<Locale.LanguageRange>, List<Locale>, List<Locale>> filter) Returns a list of locales that best matches the current request.default ParamLookup
lookup()
Returns aParamLookup
instance which is a fluent interface covering the functionality of thelookup(String, ParamSource...)
method.default Value
Searches for a parameter in the following order:ParamSource.PATH
,ParamSource.QUERY
,ParamSource.FORM
returning the first non-missingValue
, or a 'missing'Value
if none found.default Value
lookup
(String name, ParamSource... sources) boolean
Check if the request path matches the given pattern.onComplete
(Route.Complete task) Add a complete listener.path()
<T> T
Convert thepathMap()
to the given type.Path variable.pathMap()
Path map represent all the path keys with their values.query()
Query string asValueNode
object.<T> T
Convert the queryString to the given type.Get a query parameter that matches the given name.queryMap()
Query string as simple map.Query string with the leading?
static Context
Wrap a HTTP context and make read only.removeResponseHeader
(String name) Remove a response header.Clear/reset all the headers, including cookies.Render a value and send the response to client.HTTP response channel as chunker.HTTP response channel as output stream.responseStream
(MediaType contentType) HTTP response channel as output stream.responseStream
(MediaType contentType, SneakyThrows.Consumer<OutputStream> consumer) HTTP response channel as output stream.responseStream
(SneakyThrows.Consumer<OutputStream> consumer) HTTP response channel as output stream.HTTP response channel as response writer.responseWriter
(MediaType contentType) HTTP response channel as response writer.responseWriter
(MediaType contentType, SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.responseWriter
(MediaType contentType, Charset charset) HTTP response channel as response writer.responseWriter
(MediaType contentType, Charset charset, SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.responseWriter
(SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.send
(byte[] data) Send response data.send
(byte[]... data) Send response data.send
(DataBuffer data) Send response data.send
(FileDownload file) Send a file download response.send
(StatusCode statusCode) Send an empty response with the given status code.send
(InputStream input) Send response data.Send response data.Send response data.send
(ByteBuffer data) Send response data.send
(ByteBuffer[] data) Send response data.send
(FileChannel file) Send a file response.send
(ReadableByteChannel channel) Send response data.Send a file response.Send an error response.sendError
(Throwable cause, StatusCode statusCode) Send an error response.sendRedirect
(StatusCode redirect, String location) Send a redirect response.sendRedirect
(String location) Send a302
response.session()
Find a session or creates a new session.Find a session attribute using the given name.Find an existing session.setAttribute
(String key, Object value) Set an application attribute.setDefaultResponseType
(MediaType contentType) Set the default response content type header.Set the host (without the port value).Set HTTP method in upper-case form.setPathMap
(Map<String, String> pathMap) Set path map.setPort
(int port) Set port this request was sent to.setRemoteAddress
(String remoteAddress) Set IP address of client or last proxy that sent the request.setRequestPath
(String path) Set request path.setResetHeadersOnError
(boolean value) Set whenever reset/clear headers on application error.setResponseCode
(int statusCode) Set response status code.setResponseCode
(StatusCode statusCode) Set response status code.setResponseCookie
(Cookie cookie) Set/add a cookie to response.setResponseHeader
(String name, Object value) Set response header.setResponseHeader
(String name, String value) Set response header.setResponseHeader
(String name, Instant value) Set response header.setResponseHeader
(String name, Date value) Set response header.setResponseLength
(long length) Set response content length header.setResponseType
(MediaType contentType) Set response content type header.setResponseType
(MediaType contentType, Charset charset) Set response content type header.setResponseType
(String contentType) Set response content type header.Set matching route.Set HTTP scheme in lower case.Set current user.upgrade
(ServerSentEmitter.Handler handler) Perform a server-sent event handshake and upgrade HTTP GET into a Server-Sent protocol.upgrade
(WebSocket.Initializer handler) Perform a websocket handsahke and upgrade a HTTP GET into a websocket protocol.static Context
websocket
(Context ctx, WebSocket ws, boolean binary, WebSocket.WriteCallback callback) Wrap a HTTP context and make it WebSocket friendly.
-
Field Details
-
PORT
static final int PORTConstant for default HTTP port.- See Also:
-
SECURE_PORT
static final int SECURE_PORTConstant for default HTTPS port.- See Also:
-
ACCEPT
Constant forAccept
header.- See Also:
-
GMT
Constant for GMT. -
RFC1123_PATTERN
RFC1123 date pattern.- See Also:
-
RFC1123
RFC1123 date formatter.
-
-
Method Details
-
getAttributes
Context attributes (a.k.a request attributes).- Returns:
- Mutable Context attributes.
-
getAttribute
Get an attribute by his key. This is just an utility method aroundgetAttributes()
. This method look first in current context and fallback to application attributes.- Type Parameters:
T
- Attribute type.- Parameters:
key
- Attribute key.- Returns:
- Attribute value or
null
.
-
setAttribute
Set an application attribute.- Parameters:
key
- Attribute key.value
- Attribute value.- Returns:
- This router.
-
getRouter
Get the HTTP router (usually this represents an instance ofJooby
.- Returns:
- HTTP router (usually this represents an instance of
Jooby
.
-
getBufferFactory
-
forward
Forward executing to another route. We use the given path to find a matching route.NOTE: the entire handler pipeline is executed (filter, decorator, etc.).
- Parameters:
path
- Path to forward the request.- Returns:
- Forward result.
-
convert
Converts a value (single or hash) into the given type.- Type Parameters:
T
- Generic type.- Parameters:
value
- Value to convert.type
- Expected type.- Returns:
- Converted value.
-
convertOrNull
Converts a value (single or hash) into the given type.- Type Parameters:
T
- Generic type.- Parameters:
value
- Value to convert.type
- Expected type.- Returns:
- Converted value or
null
.
-
flash
Flash map.- Returns:
- Flash map.
-
flash
Get a flash attribute.- Parameters:
name
- Attribute's name.- Returns:
- Flash attribute.
-
session
Find a session or creates a new session.- Returns:
- Session.
-
session
Find a session attribute using the given name. If there is no session or attribute under that name a missing value is returned.- Parameters:
name
- Attribute's name.- Returns:
- Session's attribute or missing.
-
sessionOrNull
Find an existing session.- Returns:
- Existing session or
null
.
-
cookie
Get a cookie matching the given name.- Parameters:
name
- Cookie's name.- Returns:
- Cookie value.
-
cookieMap
Request cookies.- Returns:
- Request cookies.
-
getMethod
HTTP method in upper-case form.- Returns:
- HTTP method in upper-case form.
-
setMethod
Set HTTP method in upper-case form.- Parameters:
method
- HTTP method in upper-case form.- Returns:
- This context.
-
getRoute
Matching route.- Returns:
- Matching route.
-
matches
Check if the request path matches the given pattern.- Parameters:
pattern
- Pattern to use.- Returns:
- True if request path matches the pattern.
-
setRoute
Set matching route. This is part of public API, but shouldn't be use by application code.- Parameters:
route
- Matching route.- Returns:
- This context.
-
getContextPath
Get application context path (a.k.a as base path).- Returns:
- Application context path (a.k.a as base path).
-
getRequestPath
Request path without decoding (a.k.a raw Path) without query string.- Returns:
- Request path without decoding (a.k.a raw Path) without query string.
-
setRequestPath
Set request path. This is usually done by Web Server or framework, but by user.- Parameters:
path
- Request path.- Returns:
- This context.
-
path
Path variable. Value is decoded.- Parameters:
name
- Path key.- Returns:
- Associated value or a missing value, but never a
null
reference.
-
path
Convert thepathMap()
to the given type.- Type Parameters:
T
- Target type.- Parameters:
type
- Target type.- Returns:
- Instance of target type.
-
path
- Returns:
- A value object.
-
pathMap
Path map represent all the path keys with their values.
A call to:{ get("/:id", ctx -> ctx.pathMap()); }
GET /678
Produces a path map like:id: 678
- Returns:
- Path map from path pattern.
-
setPathMap
Set path map. This method is part of public API but shouldn't be use it by application code.- Parameters:
pathMap
- Path map.- Returns:
- This context.
-
query
Query string asValueNode
object.- Returns:
- Query string as
ValueNode
object.
-
query
Get a query parameter that matches the given name.{ get("/search", ctx -> { String q = ctx.query("q").value(); ... }); }
- Parameters:
name
- Parameter name.- Returns:
- A query value.
-
queryString
Query string with the leading?
or empty string. This is the raw query string, without decoding it.- Returns:
- Query string with the leading
?
or empty string. This is the raw query string, without decoding it.
-
query
Convert the queryString to the given type.- Type Parameters:
T
- Target type.- Parameters:
type
- Target type.- Returns:
- Query string converted to target type.
-
queryMap
Query string as simple map.
Produces/search?q=jooby&sort=name
{q: jooby, sort: name}
- Returns:
- Query string as map.
-
header
Request headers asValueNode
.- Returns:
- Request headers as
ValueNode
.
-
header
Get a header that matches the given name.- Parameters:
name
- Header name. Case insensitive.- Returns:
- A header value or missing value, never a
null
reference.
-
headerMap
Header as single-value map.- Returns:
- Header as single-value map.
-
accept
True if the given type matches the `Accept` header. This method returnstrue
if there is no accept header.- Parameters:
contentType
- Content type to match.- Returns:
- True for matching type or if content header is absent.
-
accept
Check if the accept type list matches the given produces list and return the most specific media type from produces list.- Parameters:
produceTypes
- Produced types.- Returns:
- The most specific produces type.
-
getRequestType
RequestContent-Type
header ornull
when missing.- Returns:
- Request
Content-Type
header ornull
when missing.
-
isPreflight
default boolean isPreflight()Test whenever this is a CORS preflight request.- Returns:
- Test whenever this is a CORS preflight request.
-
getRequestType
RequestContent-Type
header ornull
when missing.- Parameters:
defaults
- Default content type to use when the header is missing.- Returns:
- Request
Content-Type
header ornull
when missing.
-
getRequestLength
long getRequestLength()RequestContent-Length
header or-1
when missing.- Returns:
- Request
Content-Length
header or-1
when missing.
-
locales
@NonNull default List<Locale> locales(BiFunction<List<Locale.LanguageRange>, List<Locale>, List<Locale>> filter) Returns a list of locales that best matches the current request.The first filter argument is the value of
Accept-Language
as a list ofLocale.LanguageRange
instances while the second argument is a list of supported locales specified byJooby.setLocales(List)
or by theapplication.lang
configuration property.The next example returns a list of matching
Locale
instances using the filtering mechanism defined in RFC 4647:ctx.locales(Locale::filter)
- Parameters:
filter
- A locale filter.- Returns:
- A list of matching locales.
-
locales
Returns a list of locales that best matches the current request as perLocale.filter(java.util.List<java.util.Locale.LanguageRange>, java.util.Collection<java.util.Locale>, java.util.Locale.FilteringMode)
.- Returns:
- A list of matching locales or empty list.
- See Also:
-
locale
Returns a locale that best matches the current request.The first filter argument is the value of
Accept-Language
as a list ofLocale.LanguageRange
instances while the second argument is a list of supported locales specified byJooby.setLocales(List)
or by theapplication.lang
configuration property.The next example returns a
Locale
instance for the best-matching language tag using the lookup mechanism defined in RFC 4647.ctx.locale(Locale::lookup)
- Parameters:
filter
- A locale filter.- Returns:
- A matching locale.
-
locale
Returns a locale that best matches the current request or the default locale specified byJooby.setLocales(List)
or by theapplication.lang
configuration property.- Returns:
- A matching locale.
-
getUser
@Nullable <T> T getUser()Current user ornull
if none was set.- Type Parameters:
T
- User type.- Returns:
- Current user or
null
if none was set.
-
setUser
Set current user.- Parameters:
user
- Current user.- Returns:
- This context.
-
getRequestURL
Recreates full/entire url of the current request using theHost
header.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option.- Returns:
- Full/entire request url using the
Host
header.
-
getRequestURL
Recreates full/entire request url using theHost
header with a custom path/suffix.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option.- Parameters:
path
- Path or suffix to use, can also include query string parameters.- Returns:
- Full/entire request url using the
Host
header.
-
getRemoteAddress
The IP address of the client or last proxy that sent the request.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option.- Returns:
- The IP address of the client or last proxy that sent the request or
empty string
for interrupted requests.
-
setRemoteAddress
Set IP address of client or last proxy that sent the request.- Parameters:
remoteAddress
- Remote Address.- Returns:
- This context.
-
getHost
Return the host that this request was sent to, in general this will be the value of the Host header, minus the port specifier. Unless, it is set manually using thesetHost(String)
method.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option.- Returns:
- Return the host that this request was sent to, in general this will be the value of the Host header, minus the port specifier.
-
setHost
Set the host (without the port value).Please keep in mind this method doesn't alter/modify the
host
header.- Parameters:
host
- Host value.- Returns:
- This context.
-
getHostAndPort
Return the host and port that this request was sent to, in general this will be the value of the Host.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option.- Returns:
- Return the host that this request was sent to, in general this will be the value of the Host header.
-
getPort
int getPort()Return the port that this request was sent to. In general this will be the value of the Host header, minus the host name.If no host header is present, this method returns the value of
getServerPort()
.- Returns:
- Return the port that this request was sent to. In general this will be the value of the Host header, minus the host name.
-
setPort
Set port this request was sent to.- Parameters:
port
- Port.- Returns:
- This context.
-
getProtocol
The name of the protocol the request. Always in lower-case.- Returns:
- The name of the protocol the request. Always in lower-case.
-
getClientCertificates
The certificates presented by the client for mutual TLS. Empty if ssl is not enabled, or client authentication is not required.- Returns:
- The certificates presented by the client for mutual TLS. Empty if ssl is not enabled, or client authentication is not required.
-
getServerPort
int getServerPort()Server port for current request.- Returns:
- Server port for current request.
-
getServerHost
Server host.- Returns:
- Server host.
-
isSecure
boolean isSecure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.- Returns:
- a boolean indicating if the request was made using a secure channel
-
getScheme
HTTP scheme in lower case.- Returns:
- HTTP scheme in lower case.
-
setScheme
Set HTTP scheme in lower case.- Parameters:
scheme
- HTTP scheme in lower case.- Returns:
- This context.
-
form
Get form data.Only for
application/x-www-form-urlencoded
ormultipart/form-data
request.- Returns:
- Multipart value.
-
form
Get a form field that matches the given name.File upload retrieval is available using
file(String)
.Only for
multipart/form-data
request.- Parameters:
name
- Field name.- Returns:
- Multipart value.
-
form
Convert form data to the given type.Only for
application/x-www-form-urlencoded
ormultipart/form-data
request.- Type Parameters:
T
- Target type.- Parameters:
type
- Target type.- Returns:
- Target value.
-
formMap
Form data as single-value map.Only for
application/x-www-form-urlencoded
ormultipart/form-data
request.- Returns:
- Single-value map.
-
files
All file uploads. Only formultipart/form-data
request.- Returns:
- All file uploads.
-
files
All file uploads that matches the given field name.Only for
multipart/form-data
request.- Parameters:
name
- Field name. Please note this is the form field name, not the actual file name.- Returns:
- All file uploads.
-
file
A file upload that matches the given field name.Only for
multipart/form-data
request.- Parameters:
name
- Field name. Please note this is the form field name, not the actual file name.- Returns:
- A file upload.
-
lookup
Searches for a parameter in the following order:ParamSource.PATH
,ParamSource.QUERY
,ParamSource.FORM
returning the first non-missingValue
, or a 'missing'Value
if none found. -
lookup
Searches for a parameter in the specified sources, in the specified order, returning the first non-missingValue
, or a 'missing'Value
if none found.At least one
ParamSource
must be specified.- Parameters:
name
- The name of the parameter.sources
- Sources to search in.- Returns:
- The first non-missing
Value
or aValue
representing a missing value if none found. - Throws:
IllegalArgumentException
- If noParamSource
s are specified.
-
lookup
Returns aParamLookup
instance which is a fluent interface covering the functionality of thelookup(String, ParamSource...)
method.Value foo = ctx.lookup() .inQuery() .inPath() .get("foo");
- Returns:
- A
ParamLookup
instance. - See Also:
-
body
HTTP body which provides access to body content.- Returns:
- HTTP body which provides access to body content.
-
body
Convert the HTTP body to the given type.- Type Parameters:
T
- Conversion type.- Parameters:
type
- Reified type.- Returns:
- Instance of conversion type.
-
body
Convert the HTTP body to the given type.- Type Parameters:
T
- Conversion type.- Parameters:
type
- Reified type.- Returns:
- Instance of conversion type.
-
decode
Convert the HTTP body to the given type.- Type Parameters:
T
- Conversion type.- Parameters:
type
- Generic type.contentType
- Content type to use.- Returns:
- Instance of conversion type.
-
decoder
Get a decoder for the given content type or get anStatusCode.UNSUPPORTED_MEDIA_TYPE
.- Parameters:
contentType
- Content type.- Returns:
- MessageDecoder.
-
isInIoThread
boolean isInIoThread()True when request runs in IO threads.- Returns:
- True when request runs in IO threads.
-
dispatch
Dispatch context to a worker threads. Worker threads allow to execute blocking code. The default worker thread pool is provided by web server or by application code using theJooby.setWorker(Executor)
.Example:
get("/", ctx -> { return ctx.dispatch(() -> { // run blocking code }): });
- Parameters:
action
- Application code.- Returns:
- This context.
-
dispatch
Dispatch context to the given executor.Example:
Executor executor = ...; get("/", ctx -> { return ctx.dispatch(executor, () -> { // run blocking code }): });
- Parameters:
executor
- Executor to use.action
- Application code.- Returns:
- This context.
-
detach
Tells context that response will be generated form a different thread. This operation is similar todispatch(Runnable)
except there is no thread dispatching here.This operation integrates easily with third-party libraries like rxJava or others.
- Parameters:
next
- Application code.- Returns:
- This context.
- Throws:
Exception
- When detach operation fails.
-
upgrade
Perform a websocket handsahke and upgrade a HTTP GET into a websocket protocol.NOTE: This method is part of Public API, but shouldn't be used by client code.
- Parameters:
handler
- Web socket initializer.- Returns:
- This context.
-
upgrade
Perform a server-sent event handshake and upgrade HTTP GET into a Server-Sent protocol.NOTE: This method is part of Public API, but shouldn't be used by client code.
- Parameters:
handler
- Server-Sent event handler.- Returns:
- This context.
-
setResponseHeader
Set response header.- Parameters:
name
- Header name.value
- Header value.- Returns:
- This context.
-
setResponseHeader
Set response header.- Parameters:
name
- Header name.value
- Header value.- Returns:
- This context.
-
setResponseHeader
Set response header.- Parameters:
name
- Header name.value
- Header value.- Returns:
- This context.
-
setResponseHeader
Set response header.- Parameters:
name
- Header name.value
- Header value.- Returns:
- This context.
-
removeResponseHeader
Remove a response header.- Parameters:
name
- Header's name.- Returns:
- This context.
-
removeResponseHeaders
Clear/reset all the headers, including cookies.- Returns:
- This context.
-
setResponseLength
Set response content length header.- Parameters:
length
- Response length.- Returns:
- This context.
-
getResponseHeader
Get response header.- Parameters:
name
- Header's name.- Returns:
- Header's value (if set previously) or
null
.
-
getResponseLength
long getResponseLength()Get response content length or-1
when none was set.- Returns:
- Response content length or
-1
when none was set.
-
setResponseCookie
Set/add a cookie to response.- Parameters:
cookie
- Cookie to add.- Returns:
- This context.
-
setResponseType
Set response content type header.- Parameters:
contentType
- Content type.- Returns:
- This context.
-
setResponseType
Set response content type header.- Parameters:
contentType
- Content type.- Returns:
- This context.
-
setResponseType
Set response content type header.- Parameters:
contentType
- Content type.charset
- Charset.- Returns:
- This context.
-
setDefaultResponseType
Set the default response content type header. It is used if the response content type header was not set yet.- Parameters:
contentType
- Content type.- Returns:
- This context.
-
getResponseType
Get response content type.- Returns:
- Response content type.
-
setResponseCode
Set response status code.- Parameters:
statusCode
- Status code.- Returns:
- This context.
-
setResponseCode
Set response status code.- Parameters:
statusCode
- Status code.- Returns:
- This context.
-
getResponseCode
Get response status code.- Returns:
- Response status code.
-
render
Render a value and send the response to client.- Parameters:
value
- Object value.- Returns:
- This context.
-
responseStream
HTTP response channel as output stream. Usually for chunked responses.- Returns:
- HTTP channel as output stream. Usually for chunked responses.
-
responseStream
HTTP response channel as output stream. Usually for chunked responses.- Parameters:
contentType
- Media type.- Returns:
- HTTP channel as output stream. Usually for chunked responses.
-
responseStream
@NonNull Context responseStream(@NonNull MediaType contentType, @NonNull SneakyThrows.Consumer<OutputStream> consumer) throws Exception HTTP response channel as output stream. Usually for chunked responses.- Parameters:
contentType
- Content type.consumer
- Output stream consumer.- Returns:
- HTTP channel as output stream. Usually for chunked responses.
- Throws:
Exception
- Is something goes wrong.
-
responseStream
@NonNull Context responseStream(@NonNull SneakyThrows.Consumer<OutputStream> consumer) throws Exception HTTP response channel as output stream. Usually for chunked responses.- Parameters:
consumer
- Output stream consumer.- Returns:
- HTTP channel as output stream. Usually for chunked responses.
- Throws:
Exception
- Is something goes wrong.
-
responseSender
HTTP response channel as chunker.- Returns:
- HTTP channel as chunker. Usually for chunked response.
-
responseWriter
HTTP response channel as response writer.- Returns:
- HTTP channel as response writer. Usually for chunked response.
-
responseWriter
HTTP response channel as response writer.- Parameters:
contentType
- Content type.- Returns:
- HTTP channel as response writer. Usually for chunked response.
-
responseWriter
HTTP response channel as response writer.- Parameters:
contentType
- Content type.charset
- Charset.- Returns:
- HTTP channel as response writer. Usually for chunked response.
-
responseWriter
@NonNull Context responseWriter(@NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception HTTP response channel as response writer.- Parameters:
consumer
- Writer consumer.- Returns:
- This context.
- Throws:
Exception
- Is something goes wrong.
-
responseWriter
@NonNull Context responseWriter(@NonNull MediaType contentType, @NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception HTTP response channel as response writer.- Parameters:
contentType
- Content type.consumer
- Writer consumer.- Returns:
- This context.
- Throws:
Exception
- Is something goes wrong.
-
responseWriter
@NonNull Context responseWriter(@NonNull MediaType contentType, @Nullable Charset charset, @NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception HTTP response channel as response writer.- Parameters:
contentType
- Content type.charset
- Charset.consumer
- Writer consumer.- Returns:
- This context.
- Throws:
Exception
- Is something goes wrong.
-
sendRedirect
Send a302
response.- Parameters:
location
- Location.- Returns:
- This context.
-
sendRedirect
Send a redirect response.- Parameters:
redirect
- Redirect status code.location
- Location.- Returns:
- This context.
-
send
Send response data.- Parameters:
data
- Response. Use UTF-8 charset.- Returns:
- This context.
-
send
Send response data.- Parameters:
data
- Response.charset
- Charset.- Returns:
- This context.
-
send
Send response data.- Parameters:
data
- Response.- Returns:
- This context.
-
send
Send response data.- Parameters:
data
- Response.- Returns:
- This context.
-
send
Send response data.- Parameters:
data
- Response.- Returns:
- This context.
-
send
Send response data.- Parameters:
data
- Response.- Returns:
- This context.
-
send
Send response data.- Parameters:
data
- Response.- Returns:
- This context.
-
send
Send response data.- Parameters:
channel
- Response input.- Returns:
- This context.
-
send
Send response data.- Parameters:
input
- Response.- Returns:
- This context.
-
send
Send a file download response.- Parameters:
file
- File download.- Returns:
- This context.
-
send
Send a file response.- Parameters:
file
- File response.- Returns:
- This context.
-
send
Send a file response.- Parameters:
file
- File response.- Returns:
- This context.
-
send
Send an empty response with the given status code.- Parameters:
statusCode
- Status code.- Returns:
- This context.
-
sendError
Send an error response. Status code is computed viaRouter.errorCode(Throwable)
.- Parameters:
cause
- Error. If this is a fatal error it is going to be rethrow it.- Returns:
- This context.
-
sendError
Send an error response.- Parameters:
cause
- Error. If this is a fatal error it is going to be rethrow it.statusCode
- Status code.- Returns:
- This context.
-
isResponseStarted
boolean isResponseStarted()True if response already started.- Returns:
- True if response already started.
-
getResetHeadersOnError
boolean getResetHeadersOnError()True if response headers are cleared on application error. If none set it uses the default/global value specified byRouterOption.RESET_HEADERS_ON_ERROR
.- Returns:
- True if response headers are cleared on application error. If none set it uses the
default/global value specified by
RouterOption.RESET_HEADERS_ON_ERROR
.
-
setResetHeadersOnError
Set whenever reset/clear headers on application error.- Parameters:
value
- True for reset/clear headers.- Returns:
- This context.
-
onComplete
Add a complete listener.- Parameters:
task
- Task to execute.- Returns:
- This context.
-
readOnly
Wrap a HTTP context and make read only. Attempt to modify the HTTP response resulted in exception.- Parameters:
ctx
- Originating context.- Returns:
- Read only context.
-
websocket
@NonNull static Context websocket(@NonNull Context ctx, @NonNull WebSocket ws, boolean binary, WebSocket.WriteCallback callback) Wrap a HTTP context and make it WebSocket friendly. Attempt to modify the HTTP response is completely ignored, except forsend(byte[])
andsend(String)
which are delegated to the given web socket.This context is necessary for creating a bridge between
MessageEncoder
andWebSocket
.This method is part of Public API, but direct usage is discouraged.
- Parameters:
ctx
- Originating context.ws
- WebSocket.binary
- True for sending binary message.- Returns:
- Read only context.
-