- All Superinterfaces:
Registry
- All Known Subinterfaces:
DefaultContext
- All Known Implementing Classes:
ForwardingContext
- Since:
- 2.0.0
- Author:
- edgar
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstant forAcceptheader.static final ZoneIdConstant for GMT.static final intConstant for default HTTP port.static final DateTimeFormatterRFC1123 date formatter.static final StringRFC1123 date pattern.static final intConstant for default HTTPS port. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTrue 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> TConvert the HTTP body to the given type.<T> TConvert the HTTP body to the given type.default <T> TConverts a value (single or hash) into the given type.<T> TconvertOrNull(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> TConvert 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> TConvert 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> TgetAttribute(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 StringGet 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.intgetPort()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.longRequestContent-Lengthheader or-1when missing.Request path without decoding (a.k.a raw Path) without query string.RequestContent-Typeheader ornullwhen missing.getRequestType(MediaType defaults) RequestContent-Typeheader ornullwhen missing.Recreates full/entire url of the current request using theHostheader.getRequestURL(String path) Recreates full/entire request url using theHostheader with a custom path/suffix.booleanTrue if response headers are cleared on application error.Get response status code.getResponseHeader(String name) Get response header.longGet response content length or-1when 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.intServer port for current request.<T> TgetUser()Current user ornullif none was set.header()Request headers asValueNode.Get a header that matches the given name.Header as single-value map.booleanTrue when request runs in IO threads.default booleanTest whenever this is a CORS preflight request.booleanTrue if response already started.booleanisSecure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.default Localelocale()Returns a locale that best matches the current request or the default locale specified byJooby.setLocales(List)or by theapplication.langconfiguration property.default Localelocale(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 ParamLookuplookup()Returns aParamLookupinstance which is a fluent interface covering the functionality of thelookup(String, ParamSource...)method.default ValueSearches for a parameter in the following order:ParamSource.PATH,ParamSource.QUERY,ParamSource.FORMreturning the first non-missingValue, or a 'missing'Valueif none found.default Valuelookup(String name, ParamSource... sources) booleanCheck if the request path matches the given pattern.onComplete(Route.Complete task) Add a complete listener.path()<T> TConvert thepathMap()to the given type.Path variable.pathMap()Path map represent all the path keys with their values.query()Query string asValueNodeobject.<T> TConvert 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?or empty string.static ContextWrap 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 a302response.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 Contextwebsocket(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 forAcceptheader.- 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
nullreference.
-
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 asValueNodeobject.- Returns:
- Query string as
ValueNodeobject.
-
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
nullreference.
-
headerMap
Header as single-value map.- Returns:
- Header as single-value map.
-
accept
True if the given type matches the `Accept` header. This method returnstrueif 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-Typeheader ornullwhen missing.- Returns:
- Request
Content-Typeheader ornullwhen missing.
-
isPreflight
default boolean isPreflight()Test whenever this is a CORS preflight request.- Returns:
- Test whenever this is a CORS preflight request.
-
getRequestType
RequestContent-Typeheader ornullwhen missing.- Parameters:
defaults- Default content type to use when the header is missing.- Returns:
- Request
Content-Typeheader ornullwhen missing.
-
getRequestLength
long getRequestLength()RequestContent-Lengthheader or-1when missing.- Returns:
- Request
Content-Lengthheader or-1when 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-Languageas a list ofLocale.LanguageRangeinstances while the second argument is a list of supported locales specified byJooby.setLocales(List)or by theapplication.langconfiguration property.The next example returns a list of matching
Localeinstances 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-Languageas a list ofLocale.LanguageRangeinstances while the second argument is a list of supported locales specified byJooby.setLocales(List)or by theapplication.langconfiguration property.The next example returns a
Localeinstance 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.langconfiguration property.- Returns:
- A matching locale.
-
getUser
@Nullable <T> T getUser()Current user ornullif none was set.- Type Parameters:
T- User type.- Returns:
- Current user or
nullif none was set.
-
setUser
Set current user.- Parameters:
user- Current user.- Returns:
- This context.
-
getRequestURL
Recreates full/entire url of the current request using theHostheader.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
Hostheader.
-
getRequestURL
Recreates full/entire request url using theHostheader 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
Hostheader.
-
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 stringfor 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
hostheader.- 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-urlencodedormultipart/form-datarequest.- 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-datarequest.- Parameters:
name- Field name.- Returns:
- Multipart value.
-
form
Convert form data to the given type.Only for
application/x-www-form-urlencodedormultipart/form-datarequest.- 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-urlencodedormultipart/form-datarequest.- Returns:
- Single-value map.
-
files
All file uploads. Only formultipart/form-datarequest.- Returns:
- All file uploads.
-
files
All file uploads that matches the given field name.Only for
multipart/form-datarequest.- 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-datarequest.- 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.FORMreturning the first non-missingValue, or a 'missing'Valueif none found. -
lookup
Searches for a parameter in the specified sources, in the specified order, returning the first non-missingValue, or a 'missing'Valueif none found.At least one
ParamSourcemust be specified.- Parameters:
name- The name of the parameter.sources- Sources to search in.- Returns:
- The first non-missing
Valueor aValuerepresenting a missing value if none found. - Throws:
IllegalArgumentException- If noParamSources are specified.
-
lookup
Returns aParamLookupinstance which is a fluent interface covering the functionality of thelookup(String, ParamSource...)method.Value foo = ctx.lookup() .inQuery() .inPath() .get("foo");- Returns:
- A
ParamLookupinstance. - 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-1when none was set.- Returns:
- Response content length or
-1when 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 a302response.- 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
MessageEncoderandWebSocket.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.
-