Class HttpServerResponse
- All Implemented Interfaces:
io.vertx.lang.rx.RxDelegate, StreamBase, WriteStream<Buffer>
An instance of this is created and associated to every instance of
HttpServerRequest that.
It allows the developer to control the HTTP response that is sent back to the client for a particular HTTP request.
It contains methods that allow HTTP headers and trailers to be set, and for a body to be written out to the response.
It also allows files to be streamed by the kernel directly from disk to the
outgoing HTTP connection, bypassing user space altogether (where supported by
the underlying operating system). This is a very efficient way of
serving files from the server since buffers do not have to be read one by one
from the file and written to the outgoing socket. If the developer wants to use directly a
FileChannel and manage its lifecycle use sendFile(String).
This is not yet supported in HTTP/2 for .
It implements WriteStream so it can be used with
Pipe to pipe data with flow control.
Any response should end with a terminal action, which are end(String) or sendFile(String) for successful
completion of the request, or reset() for erroneous completion of the request, so you can only call one of
the three methods as the last step in dealing with your response, but you must call one of the three methods.
NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHttpServerResponse(HttpServerResponse delegate) HttpServerResponse(Object delegate) -
Method Summary
Modifier and TypeMethodDescriptionAdd a cookie.bodyEndHandler(Handler<Void> handler) Provides a handler that will be called after the last part of the body is written to the wire.longcancel()Attempt to cancel the request according to the semantics of the underlying HTTP implementation.booleanclosed()closeHandler(Handler<Void> handler) Set a close handler for the response, this is called when the underlying connection is closed and the response was still using the connection.drainHandler(Handler<Void> handler) Set a drain handler on the stream.end()Ends the response.Same asend(String)but writes some data to the response body before ending.Same asend(String)but writes a String in UTF-8 encoding before ending the response.Same asend(String)but writes a String with the specified encoding before ending the response.booleanended()endHandler(Handler<Void> handler) Set an end handler for the response.booleanexceptionHandler(Handler<Throwable> handler) Set an exception handler on the write stream.intinthashCode()headers()headersEndHandler(Handler<Void> handler) Provide a handler that will be called just before the headers are written to the wire.booleanbooleanstatic HttpServerResponsepush(HttpMethod method, HostAndPort authority, String path) Likepush(HttpMethod, HostAndPort, String)with no headers.push(HttpMethod method, HostAndPort authority, String path, MultiMap headers) Push a response to the client.push(HttpMethod method, String path) Likepush(HttpMethod, HostAndPort, String)with the host copied from the current request.push(HttpMethod method, String path, MultiMap headers) Likepush(HttpMethod, HostAndPort, String)with the host copied from the current request.putHeader(CharSequence name, CharSequence value) LikeputHeader(String, String)but using CharSequenceputHeader(CharSequence name, Iterable<CharSequence> values) LikeputHeader(String, String)but with CharSequence IterableLikeputHeader(String, String)but providing multiple values via a String IterablePut an HTTP headerputTrailer(CharSequence name, CharSequence value) LikeputTrailer(String, String)but using CharSequenceputTrailer(CharSequence name, Iterable<CharSequence> value) LikeputTrailer(String, String)but with CharSequence IterableputTrailer(String name, Iterable<String> values) LikeputTrailer(String, String)but providing multiple values via a String IterableputTrailer(String name, String value) Put an HTTP trailerremoveCookie(String name) Expire a cookie, notifying a User Agent to remove it from its cookie jar.removeCookie(String name, boolean invalidate) Remove a cookie from the cookie set.removeCookie(String name, String domain, String path) Expires a cookie from the cookie set.removeCookie(String name, String domain, String path, boolean invalidate) Remove a cookie from the cookie set.removeCookies(String name) Expire all cookies, notifying a User Agent to remove it from its cookie jar.removeCookies(String name, boolean invalidate) Remove all cookies from the cookie set.reset()Equivalent to callingreset()with0.reset(long code) Reset this response:rxCancel()Attempt to cancel the request according to the semantics of the underlying HTTP implementation.rxEnd()Ends the response.Same asend(String)but writes some data to the response body before ending.Same asend(String)but writes a String in UTF-8 encoding before ending the response.Same asend(String)but writes a String with the specified encoding before ending the response.rxPush(HttpMethod method, HostAndPort authority, String path) Likepush(HttpMethod, HostAndPort, String)with no headers.rxPush(HttpMethod method, HostAndPort authority, String path, MultiMap headers) Push a response to the client.rxPush(HttpMethod method, String path) Likepush(HttpMethod, HostAndPort, String)with the host copied from the current request.rxPush(HttpMethod method, String path, MultiMap headers) Likepush(HttpMethod, HostAndPort, String)with the host copied from the current request.rxReset()Equivalent to callingreset()with0.rxReset(long code) Reset this response:rxSend()Send the request with an empty body.Send the request with a streambody.Send the request with a bufferbody.Send the request with a stringbody.rxSendFile(RandomAccessFile file) Same assendFile(String)withrxSendFile(RandomAccessFile file, long offset) Same assendFile(String)withrxSendFile(RandomAccessFile file, long offset, long length) Same assendFile(String)withrxSendFile(String filename) Send the request with a streambody.rxSendFile(String filename, long offset) Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.rxSendFile(String filename, long offset, long length) Ask the OS to stream a file as specified byfilenamedirectly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system.rxSendFile(FileChannel channel) Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.rxSendFile(FileChannel channel, long offset) Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.rxSendFile(FileChannel channel, long offset, long length) Ask the OS to stream a file as specified bychanneldirectly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system).Write some data to the stream.Write aStringto the response body, encoded in UTF-8.Write aStringto the response body, encoded using the encodingenc.rxWriteAltSvc(String advertisement) Write an invalid input: '<'a href="https://datatracker.ietf.org/doc/html/rfc7838"HTTP Alternative Services advertisement for the given request and its authority, according to the underlying protocol.Used to write an interim 100 Continue response to signify that the client should send the rest of the request.rxWriteCustomFrame(int type, int flags, Buffer payload) Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.rxWriteCustomFrame(HttpFrame frame) LikewriteCustomFrame(int, int, Buffer)but with anHttpFrame.rxWriteEarlyHints(MultiMap headers) Used to write an interim 103 Early Hints response to return some HTTP headers before the final HTTP message.Send the response headers.send()Send the request with an empty body.Send the request with a streambody.Send the request with a bufferbody.Send the request with a stringbody.sendFile(RandomAccessFile file) Same assendFile(String)withsendFile(RandomAccessFile file, long offset) Same assendFile(String)withsendFile(RandomAccessFile file, long offset, long length) Same assendFile(String)withSend the request with a streambody.Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.Ask the OS to stream a file as specified byfilenamedirectly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system.sendFile(FileChannel channel) Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.sendFile(FileChannel channel, long offset) Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.sendFile(FileChannel channel, long offset, long length) Ask the OS to stream a file as specified bychanneldirectly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system).setChunked(boolean chunked) Ifchunkedistrue, this response will use HTTP chunked encoding, and each call to write to the body will correspond to a new HTTP chunk sent on the wire.setStatusCode(int statusCode) Set the status code.setStatusMessage(String statusMessage) Set the status messagesetStreamPriority(StreamPriority streamPriority) Sets the priority of the associated streamsetWriteQueueMaxSize(int maxSize) Set the maximum size of the write queue tomaxSize.longstreamId()toString()trailers()Write some data to the stream.Write aStringto the response body, encoded in UTF-8.Write aStringto the response body, encoded using the encodingenc.writeAltSvc(String advertisement) Write an invalid input: '<'a href="https://datatracker.ietf.org/doc/html/rfc7838"HTTP Alternative Services advertisement for the given request and its authority, according to the underlying protocol.Used to write an interim 100 Continue response to signify that the client should send the rest of the request.writeCustomFrame(int type, int flags, Buffer payload) Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.writeCustomFrame(HttpFrame frame) LikewriteCustomFrame(int, int, Buffer)but with anHttpFrame.writeEarlyHints(MultiMap headers) Used to write an interim 103 Early Hints response to return some HTTP headers before the final HTTP message.Send the response headers.booleanThis will returntrueif there are more bytes in the write queue than the value set usingsetWriteQueueMaxSize(int)
-
Field Details
-
__TYPE_ARG
-
-
Constructor Details
-
HttpServerResponse
-
HttpServerResponse
-
-
Method Details
-
toString
-
equals
-
hashCode
-
getDelegate
- Specified by:
getDelegatein interfaceio.vertx.lang.rx.RxDelegate- Specified by:
getDelegatein interfaceStreamBase- Specified by:
getDelegatein interfaceWriteStream<Buffer>
-
toObserver
- Specified by:
toObserverin interfaceWriteStream<Buffer>
-
toSubscriber
- Specified by:
toSubscriberin interfaceWriteStream<Buffer>
-
write
Write some data to the stream.The data is usually put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the
WriteStream.writeQueueFull()method before writing. This is done automatically if using a .When the
datais moved from the queue to the actual medium, the returned will be completed with the write result, e.g the future is succeeded when a server HTTP response buffer is written to the socket and failed if the remote client has closed the socket while the data was still pending for write.- Specified by:
writein interfaceWriteStream<Buffer>- Parameters:
data- the data to write- Returns:
- a future completed with the write result
-
rxWrite
Write some data to the stream.The data is usually put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the
WriteStream.writeQueueFull()method before writing. This is done automatically if using a .When the
datais moved from the queue to the actual medium, the returned will be completed with the write result, e.g the future is succeeded when a server HTTP response buffer is written to the socket and failed if the remote client has closed the socket while the data was still pending for write.- Specified by:
rxWritein interfaceWriteStream<Buffer>- Parameters:
data- the data to write- Returns:
- a future completed with the write result
-
writeQueueFull
public boolean writeQueueFull()This will returntrueif there are more bytes in the write queue than the value set usingsetWriteQueueMaxSize(int)- Specified by:
writeQueueFullin interfaceWriteStream<Buffer>- Returns:
trueif write queue is full
-
exceptionHandler
Description copied from interface:WriteStreamSet an exception handler on the write stream.- Specified by:
exceptionHandlerin interfaceStreamBase- Specified by:
exceptionHandlerin interfaceWriteStream<Buffer>- Parameters:
handler- the exception handler- Returns:
- a reference to this, so the API can be used fluently
-
setWriteQueueMaxSize
Description copied from interface:WriteStreamSet the maximum size of the write queue tomaxSize. You will still be able to write to the stream even if there is more thanmaxSizeitems in the write queue. This is used as an indicator by classes such asPipeto provide flow control. The value is defined by the implementation of the stream, e.g in bytes for aNetSocket, etc...- Specified by:
setWriteQueueMaxSizein interfaceWriteStream<Buffer>- Parameters:
maxSize- the max size of the write stream- Returns:
- a reference to this, so the API can be used fluently
-
drainHandler
Description copied from interface:WriteStreamSet a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. SeePipefor an example of this being used.The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to
maxSize / 2.- Specified by:
drainHandlerin interfaceWriteStream<Buffer>- Parameters:
handler- the handler- Returns:
- a reference to this, so the API can be used fluently
-
getStatusCode
public int getStatusCode()- Returns:
- the HTTP status code of the response. The default is
200representingOK.
-
setStatusCode
Set the status code. If the status message hasn't been explicitly set, a default status message corresponding to the code will be looked-up and used.- Parameters:
statusCode-- Returns:
- a reference to this, so the API can be used fluently
-
getStatusMessage
- Returns:
- the HTTP status message of the response. If this is not specified a default value will be used depending on what
setStatusCode(int)has been set to.
-
setStatusMessage
Set the status message- Parameters:
statusMessage-- Returns:
- a reference to this, so the API can be used fluently
-
setChunked
Ifchunkedistrue, this response will use HTTP chunked encoding, and each call to write to the body will correspond to a new HTTP chunk sent on the wire.If chunked encoding is used the HTTP header
Transfer-Encodingwith a value ofChunkedwill be automatically inserted in the response.If
chunkedisfalse, this response will not use HTTP chunked encoding, and therefore the total size of any data that is written in the respone body must be set in theContent-Lengthheader before any data is written out.An HTTP chunked response is typically used when you do not know the total size of the request body up front.
- Parameters:
chunked-- Returns:
- a reference to this, so the API can be used fluently
-
isChunked
public boolean isChunked()- Returns:
- is the response chunked?
-
headers
- Returns:
- The HTTP headers
-
putHeader
Put an HTTP header- Parameters:
name- the header namevalue- the header value.- Returns:
- a reference to this, so the API can be used fluently
-
trailers
- Returns:
- The HTTP trailers
-
putTrailer
Put an HTTP trailer- Parameters:
name- the trailer namevalue- the trailer value- Returns:
- a reference to this, so the API can be used fluently
-
closeHandler
Set a close handler for the response, this is called when the underlying connection is closed and the response was still using the connection.For HTTP/1.x it is called when the connection is closed before
end()is called, therefore it is not guaranteed to be called.For HTTP/2 it is called when the related stream is closed, and therefore it will be always be called.
- Parameters:
handler- the handler- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
Set an end handler for the response. This will be called when the response is disposed to allow consistent cleanup of the response.- Parameters:
handler- the handler- Returns:
- a reference to this, so the API can be used fluently
-
writeHead
Send the response headers.- Returns:
- a future notified by the success or failure of the write
-
rxWriteHead
Send the response headers.- Returns:
- a future notified by the success or failure of the write
-
write
Write aStringto the response body, encoded using the encodingenc.- Parameters:
chunk- the string to writeenc- the encoding to use- Returns:
- a future completed with the body result
-
rxWrite
Write aStringto the response body, encoded using the encodingenc.- Parameters:
chunk- the string to writeenc- the encoding to use- Returns:
- a future completed with the body result
-
write
Write aStringto the response body, encoded in UTF-8.- Parameters:
chunk- the string to write- Returns:
- a future completed with the body result
-
rxWrite
Write aStringto the response body, encoded in UTF-8.- Parameters:
chunk- the string to write- Returns:
- a future completed with the body result
-
writeContinue
Used to write an interim 100 Continue response to signify that the client should send the rest of the request. Must only be used if the request contains an "Expect:100-Continue" header- Returns:
- a reference to this, so the API can be used fluently
-
rxWriteContinue
Used to write an interim 100 Continue response to signify that the client should send the rest of the request. Must only be used if the request contains an "Expect:100-Continue" header- Returns:
- a reference to this, so the API can be used fluently
-
writeEarlyHints
Used to write an interim 103 Early Hints response to return some HTTP headers before the final HTTP message.- Parameters:
headers- headers to write- Returns:
- a future
-
rxWriteEarlyHints
Used to write an interim 103 Early Hints response to return some HTTP headers before the final HTTP message.- Parameters:
headers- headers to write- Returns:
- a future
-
end
Same asend(String)but writes a String in UTF-8 encoding before ending the response.- Parameters:
chunk- the string to write before ending the response- Returns:
- a future completed with the body result
-
rxEnd
Same asend(String)but writes a String in UTF-8 encoding before ending the response.- Parameters:
chunk- the string to write before ending the response- Returns:
- a future completed with the body result
-
end
Same asend(String)but writes a String with the specified encoding before ending the response.- Parameters:
chunk- the string to write before ending the responseenc- the encoding to use- Returns:
- a future completed with the body result
-
rxEnd
Same asend(String)but writes a String with the specified encoding before ending the response.- Parameters:
chunk- the string to write before ending the responseenc- the encoding to use- Returns:
- a future completed with the body result
-
end
Same asend(String)but writes some data to the response body before ending. If the response is not chunked and no other data has been written then the @code{Content-Length} header will be automatically set.- Specified by:
endin interfaceWriteStream<Buffer>- Parameters:
chunk- the buffer to write before ending the response- Returns:
- a future completed with the body result
-
rxEnd
Same asend(String)but writes some data to the response body before ending. If the response is not chunked and no other data has been written then the @code{Content-Length} header will be automatically set.- Specified by:
rxEndin interfaceWriteStream<Buffer>- Parameters:
chunk- the buffer to write before ending the response- Returns:
- a future completed with the body result
-
end
Ends the response. If no data has been written to the response body, the actual response won't get written until this method gets called.Once the response has ended, it cannot be used any more.
This is a terminal action, like
sendFile(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Specified by:
endin interfaceWriteStream<Buffer>- Returns:
- a future completed with the body result
-
rxEnd
Ends the response. If no data has been written to the response body, the actual response won't get written until this method gets called.Once the response has ended, it cannot be used any more.
This is a terminal action, like
sendFile(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Specified by:
rxEndin interfaceWriteStream<Buffer>- Returns:
- a future completed with the body result
-
send
Send the request with an empty body.- Returns:
- a future notified when the response has been written
-
rxSend
Send the request with an empty body.- Returns:
- a future notified when the response has been written
-
send
Send the request with a stringbody.- Parameters:
body-- Returns:
- a future notified when the response has been written
-
rxSend
Send the request with a stringbody.- Parameters:
body-- Returns:
- a future notified when the response has been written
-
send
Send the request with a bufferbody.- Parameters:
body-- Returns:
- a future notified when the response has been written
-
rxSend
Send the request with a bufferbody.- Parameters:
body-- Returns:
- a future notified when the response has been written
-
send
Send the request with a streambody.If the
HttpHeadersis set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders.- Parameters:
body-- Returns:
- a future notified when the last bytes of the response was sent
-
rxSend
Send the request with a streambody.If the
HttpHeadersis set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders.- Parameters:
body-- Returns:
- a future notified when the last bytes of the response was sent
-
sendFile
Send the request with a streambody.If the
HttpHeadersis set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
filename-- Returns:
- a future notified when the response has been written
-
rxSendFile
Send the request with a streambody.If the
HttpHeadersis set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
filename-- Returns:
- a future notified when the response has been written
-
sendFile
Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
filename- path to the file to serveoffset- offset to start serving from- Returns:
- a future completed with the body result
-
rxSendFile
Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
filename- path to the file to serveoffset- offset to start serving from- Returns:
- a future completed with the body result
-
sendFile
Ask the OS to stream a file as specified byfilenamedirectly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to serve files.The actual serve is asynchronous and may not complete until some time after this method has returned.
This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
filename- path to the file to serveoffset- offset to start serving fromlength- the number of bytes to send- Returns:
- a future completed with the body result
-
rxSendFile
Ask the OS to stream a file as specified byfilenamedirectly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to serve files.The actual serve is asynchronous and may not complete until some time after this method has returned.
This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
filename- path to the file to serveoffset- offset to start serving fromlength- the number of bytes to send- Returns:
- a future completed with the body result
-
ended
public boolean ended()- Returns:
- has the response already ended?
-
closed
public boolean closed()- Returns:
- has the underlying TCP connection corresponding to the request already been closed?
-
headWritten
public boolean headWritten()- Returns:
- have the headers for the response already been written?
-
headersEndHandler
Provide a handler that will be called just before the headers are written to the wire.This provides a hook allowing you to add any more headers or do any more operations before this occurs.
- Parameters:
handler- the handler- Returns:
- a reference to this, so the API can be used fluently
-
bodyEndHandler
Provides a handler that will be called after the last part of the body is written to the wire. The handler is called asynchronously of when the response has been received by the client. This provides a hook allowing you to do more operations once the request has been sent over the wire such as resource cleanup.- Parameters:
handler- the handler- Returns:
- a reference to this, so the API can be used fluently
-
bytesWritten
public long bytesWritten()- Returns:
- the total number of bytes written for the body of the response.
-
streamId
public long streamId()- Returns:
- the id of the stream of this response, for HTTP/1.x
-
push
Likepush(HttpMethod, HostAndPort, String)with no headers.- Parameters:
method-authority-path-- Returns:
-
rxPush
Likepush(HttpMethod, HostAndPort, String)with no headers.- Parameters:
method-authority-path-- Returns:
-
push
Likepush(HttpMethod, HostAndPort, String)with the host copied from the current request.- Parameters:
method-path-headers-- Returns:
-
rxPush
Likepush(HttpMethod, HostAndPort, String)with the host copied from the current request.- Parameters:
method-path-headers-- Returns:
-
push
Likepush(HttpMethod, HostAndPort, String)with the host copied from the current request.- Parameters:
method-path-- Returns:
-
rxPush
Likepush(HttpMethod, HostAndPort, String)with the host copied from the current request.- Parameters:
method-path-- Returns:
-
push
public Single<HttpServerResponse> push(HttpMethod method, HostAndPort authority, String path, MultiMap headers) Push a response to the client. Thehandlerwill be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent. Thehandlermay be queued if the client has reduced the maximum number of streams the server can push concurrently. Push can be sent only for peer initiated streams and if the response is not ended.- Parameters:
method- the method of the promised requestauthority- the authority of the promised requestpath- the path of the promised requestheaders- the headers of the promised request- Returns:
- a future notified when the response can be written
-
rxPush
public Single<HttpServerResponse> rxPush(HttpMethod method, HostAndPort authority, String path, MultiMap headers) Push a response to the client. Thehandlerwill be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent. Thehandlermay be queued if the client has reduced the maximum number of streams the server can push concurrently. Push can be sent only for peer initiated streams and if the response is not ended.- Parameters:
method- the method of the promised requestauthority- the authority of the promised requestpath- the path of the promised requestheaders- the headers of the promised request- Returns:
- a future notified when the response can be written
-
reset
-
rxReset
-
reset
Reset this response:- for HTTP/2, send an HTTP/2 reset frame with the specified error
code - for HTTP/1.x, close the connection when the current response has not yet been sent
falseis returned as indicator.This is a terminal action, like
end(String)andsendFile(String), so you can only call one of the three methods as the last step in dealing with your response.Stream reset should be avoided because the implementation works partially for HTTP/3 and reset error codes depends on the version of the protocol,
cancel()should be used instead.- Parameters:
code- the error code- Returns:
truewhen reset has been performed
- for HTTP/2, send an HTTP/2 reset frame with the specified error
-
rxReset
Reset this response:- for HTTP/2, send an HTTP/2 reset frame with the specified error
code - for HTTP/1.x, close the connection when the current response has not yet been sent
falseis returned as indicator.This is a terminal action, like
end(String)andsendFile(String), so you can only call one of the three methods as the last step in dealing with your response.Stream reset should be avoided because the implementation works partially for HTTP/3 and reset error codes depends on the version of the protocol,
cancel()should be used instead.- Parameters:
code- the error code- Returns:
truewhen reset has been performed
- for HTTP/2, send an HTTP/2 reset frame with the specified error
-
cancel
Attempt to cancel the request according to the semantics of the underlying HTTP implementation.- for HTTP/1.x, this closes the connection when the current request is inflight
- for HTTP/2, this performs send an HTTP/2 reset frame with the error
0x08 - for HTTP/3, this resets or abort reading the underlying QUIC stream with code
0x10c
- Returns:
- a future notifying the cancellation outcome
-
rxCancel
Attempt to cancel the request according to the semantics of the underlying HTTP implementation.- for HTTP/1.x, this closes the connection when the current request is inflight
- for HTTP/2, this performs send an HTTP/2 reset frame with the error
0x08 - for HTTP/3, this resets or abort reading the underlying QUIC stream with code
0x10c
- Returns:
- a future notifying the cancellation outcome
-
writeCustomFrame
Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.The frame is sent immediatly and is not subject to flow control.
- Parameters:
type- the 8-bit frame typeflags- the 8-bit frame flagspayload- the frame payload- Returns:
- a reference to this, so the API can be used fluently
-
rxWriteCustomFrame
Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.The frame is sent immediatly and is not subject to flow control.
- Parameters:
type- the 8-bit frame typeflags- the 8-bit frame flagspayload- the frame payload- Returns:
- a reference to this, so the API can be used fluently
-
writeCustomFrame
LikewriteCustomFrame(int, int, Buffer)but with anHttpFrame.- Parameters:
frame- the frame to write- Returns:
-
rxWriteCustomFrame
LikewriteCustomFrame(int, int, Buffer)but with anHttpFrame.- Parameters:
frame- the frame to write- Returns:
-
setStreamPriority
Sets the priority of the associated stream This is not implemented for HTTP/1.x.- Parameters:
streamPriority- the priority for this request's stream- Returns:
-
addCookie
Add a cookie. This will be sent back to the client in the response.- Parameters:
cookie- the cookie- Returns:
- a reference to this, so the API can be used fluently
-
removeCookie
Expire a cookie, notifying a User Agent to remove it from its cookie jar. NOTE: This method will only remove the first occurrence of the given name. Users probably may want to use:removeCookies(String)- Parameters:
name- the name of the cookie- Returns:
- the cookie, if it existed, or null
-
removeCookie
Remove a cookie from the cookie set. If invalidate istruethen it will expire a cookie, notifying a User Agent to remove it from its cookie jar. NOTE: This method will only expire the first occurrence of the given name. Users probably may want to use:removeCookies(String)- Parameters:
name- the name of the cookieinvalidate-- Returns:
- the cookie, if it existed, or
null
-
removeCookies
Expire all cookies, notifying a User Agent to remove it from its cookie jar. NOTE: the returned is read-only. This means any attempt to modify (add or remove to the set), will throwUnsupportedOperationException.- Parameters:
name- the name of the cookie- Returns:
- a read only set of affected cookies, if they existed, or an empty set.
-
removeCookies
Remove all cookies from the cookie set. If invalidate istruethen it will expire a cookie, notifying a User Agent to remove it from its cookie jar. NOTE: the returned is read-only. This means any attempt to modify (add or remove to the set), will throwUnsupportedOperationException.- Parameters:
name- the name of the cookieinvalidate- invalidate from the user agent- Returns:
- a read only set of affected cookies, if they existed, or an empty set.
-
removeCookie
Expires a cookie from the cookie set. This will notify a User Agent to remove it from its cookie jar.- Parameters:
name- the name of the cookiedomain- the domain of the cookiepath- the path of the cookie- Returns:
- the cookie, if it existed, or
null
-
removeCookie
Remove a cookie from the cookie set. If invalidate istruethen it will expire a cookie, notifying a User Agent to remove it from its cookie jar.- Parameters:
name- the name of the cookiedomain- the domain of the cookiepath- the path of the cookieinvalidate-- Returns:
- the cookie, if it existed, or
null
-
writeAltSvc
Write an invalid input: '<'a href="https://datatracker.ietf.org/doc/html/rfc7838"HTTP Alternative Services advertisement for the given request and its authority, according to the underlying protocol.
For HTTP/1.x this sets an
HttpHeadersheader, otherwise it writes a custom frame.Example usage:
response.writeAltSvc("h3=\":443\"")- Parameters:
advertisement- the advertisement- Returns:
-
rxWriteAltSvc
Write an invalid input: '<'a href="https://datatracker.ietf.org/doc/html/rfc7838"HTTP Alternative Services advertisement for the given request and its authority, according to the underlying protocol.
For HTTP/1.x this sets an
HttpHeadersheader, otherwise it writes a custom frame.Example usage:
response.writeAltSvc("h3=\":443\"")- Parameters:
advertisement- the advertisement- Returns:
-
putHeader
LikeputHeader(String, String)but using CharSequence- Parameters:
name-value-- Returns:
-
putHeader
LikeputHeader(String, String)but providing multiple values via a String Iterable- Parameters:
name-values-- Returns:
-
putHeader
LikeputHeader(String, String)but with CharSequence Iterable- Parameters:
name-values-- Returns:
-
putTrailer
LikeputTrailer(String, String)but using CharSequence- Parameters:
name-value-- Returns:
-
putTrailer
LikeputTrailer(String, String)but providing multiple values via a String Iterable- Parameters:
name-values-- Returns:
-
putTrailer
LikeputTrailer(String, String)but with CharSequence Iterable- Parameters:
name-value-- Returns:
-
sendFile
Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
channel- the file channel to the file to serve- Returns:
- a future completed with the body result
-
rxSendFile
Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
channel- the file channel to the file to serve- Returns:
- a future completed with the body result
-
sendFile
Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
channel- the file channel to the file to serveoffset- offset to start serving from- Returns:
- a future completed with the body result
-
rxSendFile
Same assendFile(String)using length @code{Long.MAX_VALUE} which means until the end of the file.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
channel- the file channel to the file to serveoffset- offset to start serving from- Returns:
- a future completed with the body result
-
sendFile
Ask the OS to stream a file as specified bychanneldirectly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system). Contrary tosendFile(String), the caller is responsible to closechannelwhen no more needed. This is a very efficient way to serve files.The actual serve is asynchronous and may not complete until some time after this method has returned. The developer is responsible to set the adequate Content-Type with
putHeader(String, String). If not application/octet-stream will be set as default Content-Type.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
channel- the file channel to the file to serveoffset- offset to start serving fromlength- the number of bytes to send- Returns:
- a future completed with the body result
-
rxSendFile
Ask the OS to stream a file as specified bychanneldirectly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system). Contrary tosendFile(String), the caller is responsible to closechannelwhen no more needed. This is a very efficient way to serve files.The actual serve is asynchronous and may not complete until some time after this method has returned. The developer is responsible to set the adequate Content-Type with
putHeader(String, String). If not application/octet-stream will be set as default Content-Type.This is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
channel- the file channel to the file to serveoffset- offset to start serving fromlength- the number of bytes to send- Returns:
- a future completed with the body result
-
sendFile
Same assendFile(String)withThis is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
file- the file to serve- Returns:
- a future completed with the body result
-
rxSendFile
Same assendFile(String)withThis is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
file- the file to serve- Returns:
- a future completed with the body result
-
sendFile
Same assendFile(String)withThis is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
file- the file to serveoffset- offset to start serving from- Returns:
- a future completed with the body result
-
rxSendFile
Same assendFile(String)withThis is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
file- the file to serveoffset- offset to start serving from- Returns:
- a future completed with the body result
-
sendFile
Same assendFile(String)withThis is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
file- the file to serveoffset- offset to start serving fromlength- the number of bytes to send- Returns:
- a future completed with the body result
-
rxSendFile
Same assendFile(String)withThis is a terminal action, like
end(String)andreset(), so you can only call one of the three methods as the last step in dealing with your response.- Parameters:
file- the file to serveoffset- offset to start serving fromlength- the number of bytes to send- Returns:
- a future completed with the body result
-
newInstance
-