Package reactor.netty.http.server
Interface HttpServerResponse
- All Superinterfaces:
ConnectionInformation
,HttpInfos
,HttpServerInfos
,NettyOutbound
,Publisher<Void>
An Http Reactive Channel with several accessors related to HTTP flow: headers, params,
URI, method, websocket...
- Since:
- 0.5
- Author:
- Stephane Maldini
-
Method Summary
Modifier and TypeMethodDescriptionAdds an outbound cookie.addHeader
(CharSequence name, CharSequence value) Adds an outbound HTTP header, appending the value if the header already exist.chunkedTransfer
(boolean chunked) Sets Transfer-Encoding header.compression
(boolean compress) Enables/Disables compression handling (gzip/deflate) for the underlying response.boolean
Returns true if headers and status have been sent to the client.header
(CharSequence name, CharSequence value) Sets an outbound HTTP header, replacing any pre-existing value.headers
(HttpHeaders headers) Sets outbound HTTP headers, replacing any pre-existing value for these headers.keepAlive
(boolean keepAlive) Sets the requestkeepAlive
if true otherwise remove the existing connection keep alive header.Returns the outbound HTTP headers, sent back to the clients.send()
Sends the HTTP headers and empty content thus delimiting a full empty body http response.Returns aNettyOutbound
successful on committed response.Sends 404 statusHttpResponseStatus.NOT_FOUND
.sendRedirect
(String location) Sends redirect statusHttpResponseStatus.FOUND
along with a location header to the remote client.sendWebsocket
(BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> websocketHandler) Upgrades the connection to websocket.sendWebsocket
(BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> websocketHandler, WebsocketServerSpec websocketServerSpec) Upgrades the connection to websocket.sse()
Adds "text/event-stream" content-type for Server-Sent Events.status()
Returns the assigned HTTP status.default HttpServerResponse
status
(int status) Sets an HTTP status to be sent along with the headers.status
(HttpResponseStatus status) Sets an HTTP status to be sent along with the headers.trailerHeaders
(Consumer<? super HttpHeaders> trailerHeaders) Callback for setting outbound trailer headers.withConnection
(Consumer<? super Connection> withConnection) Call the passed callback with aConnection
to operate on the underlyingChannel
state.Methods inherited from interface reactor.netty.http.server.ConnectionInformation
connectionHostAddress, connectionRemoteAddress, connectionScheme, hostAddress, hostName, hostPort, remoteAddress, scheme
Methods inherited from interface reactor.netty.http.HttpInfos
cookies, fullPath, isKeepAlive, isWebsocket, method, path, requestId, uri, version
Methods inherited from interface reactor.netty.http.server.HttpServerInfos
allCookies
Methods inherited from interface reactor.netty.NettyOutbound
alloc, neverComplete, send, send, sendByteArray, sendFile, sendFile, sendFileChunked, sendGroups, sendObject, sendObject, sendObject, sendString, sendString, sendUsing, subscribe, then, then, then
-
Method Details
-
addCookie
Adds an outbound cookie.- Returns:
- this
HttpServerResponse
-
addHeader
Adds an outbound HTTP header, appending the value if the header already exist.- Parameters:
name
- header namevalue
- header value- Returns:
- this
HttpServerResponse
-
chunkedTransfer
Sets Transfer-Encoding header.- Parameters:
chunked
- true if Transfer-Encoding: chunked- Returns:
- this
HttpServerResponse
-
withConnection
Description copied from interface:NettyOutbound
Call the passed callback with aConnection
to operate on the underlyingChannel
state.- Specified by:
withConnection
in interfaceNettyOutbound
- Parameters:
withConnection
- connection callback- Returns:
- the
Connection
-
compression
Enables/Disables compression handling (gzip/deflate) for the underlying response.- Parameters:
compress
- should handle compression- Returns:
- this
HttpServerResponse
-
hasSentHeaders
boolean hasSentHeaders()Returns true if headers and status have been sent to the client.- Returns:
- true if headers and status have been sent to the client
-
header
Sets an outbound HTTP header, replacing any pre-existing value.- Parameters:
name
- headers keyvalue
- header value- Returns:
- this
HttpServerResponse
-
headers
Sets outbound HTTP headers, replacing any pre-existing value for these headers.- Parameters:
headers
- netty headers map- Returns:
- this
HttpServerResponse
-
keepAlive
Sets the requestkeepAlive
if true otherwise remove the existing connection keep alive header.- Returns:
- this
HttpServerResponse
-
responseHeaders
HttpHeaders responseHeaders()Returns the outbound HTTP headers, sent back to the clients.- Returns:
- headers sent back to the clients
-
send
Sends the HTTP headers and empty content thus delimiting a full empty body http response.- Returns:
- a
Mono
successful on committed response - See Also:
-
sendHeaders
NettyOutbound sendHeaders()Returns aNettyOutbound
successful on committed response.- Returns:
- a
NettyOutbound
successful on committed response
-
sendNotFound
Sends 404 statusHttpResponseStatus.NOT_FOUND
.- Returns:
- a
Mono
successful on flush confirmation
-
sendRedirect
Sends redirect statusHttpResponseStatus.FOUND
along with a location header to the remote client.- Parameters:
location
- the location to redirect to- Returns:
- a
Mono
successful on flush confirmation
-
sendWebsocket
default Mono<Void> sendWebsocket(BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> websocketHandler) Upgrades the connection to websocket. AMono
completing when the upgrade is confirmed, then the provided callback is invoked, if the upgrade is not successful the returnedMono
fails.- Parameters:
websocketHandler
- the I/O handler for websocket transport- Returns:
- a
Mono
completing when upgrade is confirmed, otherwise fails
-
sendWebsocket
Mono<Void> sendWebsocket(BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> websocketHandler, WebsocketServerSpec websocketServerSpec) Upgrades the connection to websocket. AMono
completing when the upgrade is confirmed, then the provided callback is invoked, if the upgrade is not successful the returnedMono
fails.- Parameters:
websocketHandler
- the I/O handler for websocket transportwebsocketServerSpec
-WebsocketServerSpec
for websocket configuration- Returns:
- a
Mono
completing when upgrade is confirmed, otherwise fails - Since:
- 0.9.5
-
sse
HttpServerResponse sse()Adds "text/event-stream" content-type for Server-Sent Events.- Returns:
- this
HttpServerResponse
-
status
HttpResponseStatus status()Returns the assigned HTTP status.- Returns:
- the assigned HTTP status
-
status
Sets an HTTP status to be sent along with the headers.- Parameters:
status
- an HTTP status to be sent along with the headers- Returns:
- this
HttpServerResponse
-
status
Sets an HTTP status to be sent along with the headers.- Parameters:
status
- an HTTP status to be sent along with the headers- Returns:
- this
HttpServerResponse
-
trailerHeaders
Callback for setting outbound trailer headers. The callback is invoked when the response is about to be completed.Note:Only headers names declared with
HttpHeaderNames.TRAILER
are accepted.Note:Trailer headers are sent only when a message body is encoded with the chunked transfer coding
Note:The headers below cannot be sent as trailer headers:
- Age
- Cache-Control
- Content-Encoding
- Content-Length
- Content-Range
- Content-Type
- Date
- Expires
- Location
- Retry-After
- Trailer
- Transfer-Encoding
- Vary
- Warning
- Parameters:
trailerHeaders
- netty headers map- Returns:
- this
HttpServerResponse
- Since:
- 1.0.12
-