Class HttpServerResponse
- java.lang.Object
-
- io.vertx.reactivex.core.http.HttpServerResponse
-
- All Implemented Interfaces:
StreamBase
,WriteStream<Buffer>
public class HttpServerResponse extends Object implements WriteStream<Buffer>
Represents a server-side HTTP response.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.
It implements
NOTE: This class has been automatically generated from theWriteStream
so it can be used withPipe
to pipe data with flow control.original
non RX-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<HttpServerResponse>
__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description HttpServerResponse(HttpServerResponse delegate)
HttpServerResponse(Object delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HttpServerResponse
addCookie(Cookie cookie)
Add a cookie.HttpServerResponse
bodyEndHandler(Handler<Void> handler)
Provides a handler that will be called after the last part of the body is written to the wire.long
bytesWritten()
void
close()
Deprecated.boolean
closed()
HttpServerResponse
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.HttpServerResponse
drainHandler(Handler<Void> handler)
Set a drain handler on the stream.void
end()
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
end(Handler<AsyncResult<Void>> handler)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
end(Buffer chunk)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
end(Buffer chunk, Handler<AsyncResult<Void>> handler)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
end(String chunk)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
end(String chunk, Handler<AsyncResult<Void>> handler)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
end(String chunk, String enc)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
end(String chunk, String enc, Handler<AsyncResult<Void>> handler)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesboolean
ended()
HttpServerResponse
endHandler(Handler<Void> handler)
Set an end handler for the response.boolean
equals(Object o)
HttpServerResponse
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the write stream.HttpServerResponse
getDelegate()
int
getStatusCode()
String
getStatusMessage()
int
hashCode()
MultiMap
headers()
HttpServerResponse
headersEndHandler(Handler<Void> handler)
Provide a handler that will be called just before the headers are written to the wire.boolean
headWritten()
boolean
isChunked()
static HttpServerResponse
newInstance(HttpServerResponse arg)
Future<HttpServerResponse>
push(HttpMethod method, HostAndPort authority, String path, MultiMap headers)
Same aspush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
but with anhandler
called when the operation completesHttpServerResponse
push(HttpMethod method, String path)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.HttpServerResponse
push(HttpMethod method, String path, Handler<AsyncResult<HttpServerResponse>> handler)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.HttpServerResponse
push(HttpMethod method, String path, MultiMap headers)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.HttpServerResponse
push(HttpMethod method, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.HttpServerResponse
push(HttpMethod method, String host, String path)
HttpServerResponse
push(HttpMethod method, String host, String path, Handler<AsyncResult<HttpServerResponse>> handler)
HttpServerResponse
push(HttpMethod method, String host, String path, MultiMap headers)
Push a response to the client.HttpServerResponse
push(HttpMethod method, String host, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler)
Push a response to the client.HttpServerResponse
putHeader(CharSequence name, CharSequence value)
LikeputHeader(java.lang.String, java.lang.String)
but using CharSequenceHttpServerResponse
putHeader(CharSequence name, Iterable<CharSequence> values)
LikeputHeader(java.lang.String, java.lang.String)
but with CharSequence IterableHttpServerResponse
putHeader(String name, Iterable<String> values)
LikeputHeader(java.lang.String, java.lang.String)
but providing multiple values via a String IterableHttpServerResponse
putHeader(String name, String value)
Put an HTTP headerHttpServerResponse
putTrailer(CharSequence name, CharSequence value)
LikeputTrailer(java.lang.String, java.lang.String)
but using CharSequenceHttpServerResponse
putTrailer(CharSequence name, Iterable<CharSequence> value)
LikeputTrailer(java.lang.String, java.lang.String)
but with CharSequence IterableHttpServerResponse
putTrailer(String name, Iterable<String> values)
LikeputTrailer(java.lang.String, java.lang.String)
but providing multiple values via a String IterableHttpServerResponse
putTrailer(String name, String value)
Put an HTTP trailerCookie
removeCookie(String name)
Expire a cookie, notifying a User Agent to remove it from its cookie jar.Cookie
removeCookie(String name, boolean invalidate)
Remove a cookie from the cookie set.Cookie
removeCookie(String name, String domain, String path)
Expires a cookie from the cookie set.Cookie
removeCookie(String name, String domain, String path, boolean invalidate)
Remove a cookie from the cookie set.Set<Cookie>
removeCookies(String name)
Expire all cookies, notifying a User Agent to remove it from its cookie jar.Set<Cookie>
removeCookies(String name, boolean invalidate)
Remove all cookies from the cookie set.boolean
reset()
Reset this HTTP/2 stream with the error code0
.boolean
reset(long code)
Reset this response:io.reactivex.Completable
rxEnd()
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesio.reactivex.Completable
rxEnd(Buffer chunk)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesio.reactivex.Completable
rxEnd(String chunk)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesio.reactivex.Completable
rxEnd(String chunk, String enc)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesio.reactivex.Single<HttpServerResponse>
rxPush(HttpMethod method, String path)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.io.reactivex.Single<HttpServerResponse>
rxPush(HttpMethod method, String path, MultiMap headers)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.io.reactivex.Single<HttpServerResponse>
rxPush(HttpMethod method, String host, String path)
io.reactivex.Single<HttpServerResponse>
rxPush(HttpMethod method, String host, String path, MultiMap headers)
Push a response to the client.io.reactivex.Completable
rxSend()
Send the request with an empty body.io.reactivex.Completable
rxSend(io.reactivex.Flowable<Buffer> body)
Send the request with a streambody
.io.reactivex.Completable
rxSend(Buffer body)
Send the request with a bufferbody
.io.reactivex.Completable
rxSend(ReadStream<Buffer> body)
Send the request with a streambody
.io.reactivex.Completable
rxSend(String body)
Send the request with a stringbody
.io.reactivex.Completable
rxSendFile(String filename)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.io.reactivex.Completable
rxSendFile(String filename, long offset)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.io.reactivex.Completable
rxSendFile(String filename, long offset, long length)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.io.reactivex.Completable
rxWrite(Buffer data)
Same as but with anhandler
called when the operation completesio.reactivex.Completable
rxWrite(String chunk)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesio.reactivex.Completable
rxWrite(String chunk, String enc)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesio.reactivex.Completable
rxWriteEarlyHints(MultiMap headers)
Same aswriteEarlyHints(io.vertx.reactivex.core.MultiMap, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
send()
Send the request with an empty body.void
send(io.reactivex.Flowable<Buffer> body)
Send the request with a streambody
.void
send(io.reactivex.Flowable<Buffer> body, Handler<AsyncResult<Void>> handler)
Send the request with a streambody
.void
send(Handler<AsyncResult<Void>> handler)
Send the request with an empty body.void
send(Buffer body)
Send the request with a bufferbody
.void
send(Buffer body, Handler<AsyncResult<Void>> handler)
Send the request with a bufferbody
.void
send(ReadStream<Buffer> body)
Send the request with a streambody
.void
send(ReadStream<Buffer> body, Handler<AsyncResult<Void>> handler)
Send the request with a streambody
.void
send(String body)
Send the request with a stringbody
.void
send(String body, Handler<AsyncResult<Void>> handler)
Send the request with a stringbody
.HttpServerResponse
sendFile(String filename)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.HttpServerResponse
sendFile(String filename, long offset)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.HttpServerResponse
sendFile(String filename, long offset, long length)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.HttpServerResponse
sendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.HttpServerResponse
sendFile(String filename, long offset, Handler<AsyncResult<Void>> resultHandler)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.HttpServerResponse
sendFile(String filename, Handler<AsyncResult<Void>> resultHandler)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.HttpServerResponse
setChunked(boolean chunked)
Ifchunked
istrue
, 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.HttpServerResponse
setStatusCode(int statusCode)
Set the status code.HttpServerResponse
setStatusMessage(String statusMessage)
Set the status messageHttpServerResponse
setStreamPriority(StreamPriority streamPriority)
Sets the priority of the associated streamHttpServerResponse
setWriteQueueMaxSize(int maxSize)
Set the maximum size of the write queue tomaxSize
.int
streamId()
WriteStreamObserver<Buffer>
toObserver()
String
toString()
WriteStreamSubscriber<Buffer>
toSubscriber()
MultiMap
trailers()
void
write(Buffer data)
Same as but with anhandler
called when the operation completesvoid
write(Buffer data, Handler<AsyncResult<Void>> handler)
Same as but with anhandler
called when the operation completesvoid
write(String chunk)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
write(String chunk, Handler<AsyncResult<Void>> handler)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
write(String chunk, String enc)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
write(String chunk, String enc, Handler<AsyncResult<Void>> handler)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesHttpServerResponse
writeContinue()
Used to write an interim 100 Continue response to signify that the client should send the rest of the request.HttpServerResponse
writeCustomFrame(int type, int flags, Buffer payload)
Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.HttpServerResponse
writeCustomFrame(HttpFrame frame)
LikewriteCustomFrame(int, int, io.vertx.reactivex.core.buffer.Buffer)
but with anHttpFrame
.void
writeEarlyHints(MultiMap headers)
Same aswriteEarlyHints(io.vertx.reactivex.core.MultiMap, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesvoid
writeEarlyHints(MultiMap headers, Handler<AsyncResult<Void>> handler)
Same aswriteEarlyHints(io.vertx.reactivex.core.MultiMap, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completesboolean
writeQueueFull()
This will returntrue
if there are more bytes in the write queue than the value set usingsetWriteQueueMaxSize(int)
-
-
-
Field Detail
-
__TYPE_ARG
public static final TypeArg<HttpServerResponse> __TYPE_ARG
-
-
Constructor Detail
-
HttpServerResponse
public HttpServerResponse(HttpServerResponse delegate)
-
HttpServerResponse
public HttpServerResponse(Object delegate)
-
-
Method Detail
-
getDelegate
public HttpServerResponse getDelegate()
- Specified by:
getDelegate
in interfaceStreamBase
- Specified by:
getDelegate
in interfaceWriteStream<Buffer>
-
toObserver
public WriteStreamObserver<Buffer> toObserver()
-
toSubscriber
public WriteStreamSubscriber<Buffer> toSubscriber()
-
write
public void write(Buffer data, Handler<AsyncResult<Void>> handler)
Same as but with anhandler
called when the operation completes- Specified by:
write
in interfaceWriteStream<Buffer>
- Parameters:
data
-handler
-
-
write
public void write(Buffer data)
Same as but with anhandler
called when the operation completes- Specified by:
write
in interfaceWriteStream<Buffer>
- Parameters:
data
-
-
rxWrite
public io.reactivex.Completable rxWrite(Buffer data)
Same as but with anhandler
called when the operation completes- Specified by:
rxWrite
in interfaceWriteStream<Buffer>
- Parameters:
data
-- Returns:
-
end
public void end(Handler<AsyncResult<Void>> handler)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Specified by:
end
in interfaceWriteStream<Buffer>
- Parameters:
handler
-
-
end
public void end()
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Specified by:
end
in interfaceWriteStream<Buffer>
-
rxEnd
public io.reactivex.Completable rxEnd()
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Specified by:
rxEnd
in interfaceWriteStream<Buffer>
- Returns:
-
writeQueueFull
public boolean writeQueueFull()
This will returntrue
if there are more bytes in the write queue than the value set usingsetWriteQueueMaxSize(int)
- Specified by:
writeQueueFull
in interfaceWriteStream<Buffer>
- Returns:
true
if write queue is full
-
exceptionHandler
public HttpServerResponse exceptionHandler(Handler<Throwable> handler)
Description copied from interface:WriteStream
Set an exception handler on the write stream.- Specified by:
exceptionHandler
in interfaceStreamBase
- Specified by:
exceptionHandler
in interfaceWriteStream<Buffer>
- Parameters:
handler
- the exception handler- Returns:
- a reference to this, so the API can be used fluently
-
setWriteQueueMaxSize
public HttpServerResponse setWriteQueueMaxSize(int maxSize)
Description copied from interface:WriteStream
Set the maximum size of the write queue tomaxSize
. You will still be able to write to the stream even if there is more thanmaxSize
items in the write queue. This is used as an indicator by classes such asPipe
to provide flow control. The value is defined by the implementation of the stream, e.g in bytes for aNetSocket
, etc...- Specified by:
setWriteQueueMaxSize
in interfaceWriteStream<Buffer>
- Parameters:
maxSize
- the max size of the write stream- Returns:
- a reference to this, so the API can be used fluently
-
drainHandler
public HttpServerResponse drainHandler(Handler<Void> handler)
Description copied from interface:WriteStream
Set 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. SeePipe
for 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:
drainHandler
in 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
200
representingOK
.
-
setStatusCode
public HttpServerResponse setStatusCode(int statusCode)
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
public String 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
public HttpServerResponse setStatusMessage(String statusMessage)
Set the status message- Parameters:
statusMessage
-- Returns:
- a reference to this, so the API can be used fluently
-
setChunked
public HttpServerResponse setChunked(boolean chunked)
Ifchunked
istrue
, 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-Encoding
with a value ofChunked
will be automatically inserted in the response.If
chunked
isfalse
, 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-Length
header 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
public MultiMap headers()
- Returns:
- The HTTP headers
-
putHeader
public HttpServerResponse putHeader(String name, String value)
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
public MultiMap trailers()
- Returns:
- The HTTP trailers
-
putTrailer
public HttpServerResponse putTrailer(String name, String value)
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
public HttpServerResponse 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.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
public HttpServerResponse endHandler(Handler<Void> handler)
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
-
write
public void write(String chunk, String enc, Handler<AsyncResult<Void>> handler)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-enc
-handler
-
-
write
public void write(String chunk, String enc)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-enc
-
-
rxWrite
public io.reactivex.Completable rxWrite(String chunk, String enc)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-enc
-- Returns:
-
write
public void write(String chunk, Handler<AsyncResult<Void>> handler)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-handler
-
-
write
public void write(String chunk)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-
-
rxWrite
public io.reactivex.Completable rxWrite(String chunk)
Same aswrite(io.vertx.reactivex.core.buffer.Buffer, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-- Returns:
-
writeContinue
public HttpServerResponse 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
-
writeEarlyHints
public void writeEarlyHints(MultiMap headers, Handler<AsyncResult<Void>> handler)
Same aswriteEarlyHints(io.vertx.reactivex.core.MultiMap, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
headers
- headers to writehandler
-
-
writeEarlyHints
public void writeEarlyHints(MultiMap headers)
Same aswriteEarlyHints(io.vertx.reactivex.core.MultiMap, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
headers
- headers to write
-
rxWriteEarlyHints
public io.reactivex.Completable rxWriteEarlyHints(MultiMap headers)
Same aswriteEarlyHints(io.vertx.reactivex.core.MultiMap, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
headers
- headers to write- Returns:
-
end
public void end(String chunk, Handler<AsyncResult<Void>> handler)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-handler
-
-
end
public void end(String chunk)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-
-
rxEnd
public io.reactivex.Completable rxEnd(String chunk)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-- Returns:
-
end
public void end(String chunk, String enc, Handler<AsyncResult<Void>> handler)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-enc
-handler
-
-
end
public void end(String chunk, String enc)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-enc
-
-
rxEnd
public io.reactivex.Completable rxEnd(String chunk, String enc)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Parameters:
chunk
-enc
-- Returns:
-
end
public void end(Buffer chunk, Handler<AsyncResult<Void>> handler)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Specified by:
end
in interfaceWriteStream<Buffer>
- Parameters:
chunk
-handler
-
-
end
public void end(Buffer chunk)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Specified by:
end
in interfaceWriteStream<Buffer>
- Parameters:
chunk
-
-
rxEnd
public io.reactivex.Completable rxEnd(Buffer chunk)
Same asend(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but with anhandler
called when the operation completes- Specified by:
rxEnd
in interfaceWriteStream<Buffer>
- Parameters:
chunk
-- Returns:
-
send
public void send(Handler<AsyncResult<Void>> handler)
Send the request with an empty body.- Parameters:
handler
- the completion handler
-
send
public void send()
Send the request with an empty body.
-
rxSend
public io.reactivex.Completable rxSend()
Send the request with an empty body.- Returns:
-
send
public void send(String body, Handler<AsyncResult<Void>> handler)
Send the request with a stringbody
.- Parameters:
body
-handler
- the completion handler
-
send
public void send(String body)
Send the request with a stringbody
.- Parameters:
body
-
-
rxSend
public io.reactivex.Completable rxSend(String body)
Send the request with a stringbody
.- Parameters:
body
-- Returns:
-
send
public void send(Buffer body, Handler<AsyncResult<Void>> handler)
Send the request with a bufferbody
.- Parameters:
body
-handler
- the completion handler
-
send
public void send(Buffer body)
Send the request with a bufferbody
.- Parameters:
body
-
-
rxSend
public io.reactivex.Completable rxSend(Buffer body)
Send the request with a bufferbody
.- Parameters:
body
-- Returns:
-
send
public void send(ReadStream<Buffer> body, Handler<AsyncResult<Void>> handler)
Send the request with a streambody
.If the
HttpHeaders
is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders
.- Parameters:
body
-handler
- the completion handler
-
send
public void send(ReadStream<Buffer> body)
Send the request with a streambody
.If the
HttpHeaders
is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders
.- Parameters:
body
-
-
rxSend
public io.reactivex.Completable rxSend(ReadStream<Buffer> body)
Send the request with a streambody
.If the
HttpHeaders
is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders
.- Parameters:
body
-- Returns:
-
send
public void send(io.reactivex.Flowable<Buffer> body, Handler<AsyncResult<Void>> handler)
Send the request with a streambody
.If the
HttpHeaders
is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders
.- Parameters:
body
-handler
- the completion handler
-
send
public void send(io.reactivex.Flowable<Buffer> body)
Send the request with a streambody
.If the
HttpHeaders
is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders
.- Parameters:
body
-
-
rxSend
public io.reactivex.Completable rxSend(io.reactivex.Flowable<Buffer> body)
Send the request with a streambody
.If the
HttpHeaders
is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunkedHttpHeaders
.- Parameters:
body
-- Returns:
-
sendFile
public HttpServerResponse sendFile(String filename, Handler<AsyncResult<Void>> resultHandler)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serveresultHandler
- handler that will be called on completion- Returns:
- a reference to this, so the API can be used fluently
-
sendFile
public HttpServerResponse sendFile(String filename)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serve- Returns:
- a reference to this, so the API can be used fluently
-
rxSendFile
public io.reactivex.Completable rxSendFile(String filename)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serve- Returns:
- a reference to this, so the API can be used fluently
-
sendFile
public HttpServerResponse sendFile(String filename, long offset, Handler<AsyncResult<Void>> resultHandler)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serveoffset
- the offset to serve fromresultHandler
- handler that will be called on completion- Returns:
- a reference to this, so the API can be used fluently
-
sendFile
public HttpServerResponse sendFile(String filename, long offset)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serveoffset
- the offset to serve from- Returns:
- a reference to this, so the API can be used fluently
-
rxSendFile
public io.reactivex.Completable rxSendFile(String filename, long offset)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serveoffset
- the offset to serve from- Returns:
- a reference to this, so the API can be used fluently
-
sendFile
public HttpServerResponse sendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serveoffset
- the offset to serve fromlength
- length the number of bytes to sendresultHandler
- handler that will be called on completion- Returns:
- a reference to this, so the API can be used fluently
-
sendFile
public HttpServerResponse sendFile(String filename, long offset, long length)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serveoffset
- the offset to serve fromlength
- length the number of bytes to send- Returns:
- a reference to this, so the API can be used fluently
-
rxSendFile
public io.reactivex.Completable rxSendFile(String filename, long offset, long length)
LikesendFile(java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>>)
but providing a handler which will be notified once the file has been completely written to the wire.- Parameters:
filename
- path to the file to serveoffset
- the offset to serve fromlength
- length the number of bytes to send- Returns:
- a reference to this, so the API can be used fluently
-
close
@Deprecated public void close()
Deprecated.Close the underlying TCP connection corresponding to the request.
-
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
public HttpServerResponse headersEndHandler(Handler<Void> handler)
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
public HttpServerResponse bodyEndHandler(Handler<Void> handler)
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 int streamId()
- Returns:
- the id of the stream of this response, for HTTP/1.x
-
push
public HttpServerResponse push(HttpMethod method, String host, String path, Handler<AsyncResult<HttpServerResponse>> handler)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with no headers.- Parameters:
method
-host
-path
-handler
-- Returns:
-
push
public HttpServerResponse push(HttpMethod method, String host, String path)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with no headers.- Parameters:
method
-host
-path
-- Returns:
-
rxPush
public io.reactivex.Single<HttpServerResponse> rxPush(HttpMethod method, String host, String path)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with no headers.- Parameters:
method
-host
-path
-- Returns:
-
push
public HttpServerResponse push(HttpMethod method, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.- Parameters:
method
-path
-headers
-handler
-- Returns:
-
push
public HttpServerResponse push(HttpMethod method, String path, MultiMap headers)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.- Parameters:
method
-path
-headers
-- Returns:
-
rxPush
public io.reactivex.Single<HttpServerResponse> rxPush(HttpMethod method, String path, MultiMap headers)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.- Parameters:
method
-path
-headers
-- Returns:
-
push
public HttpServerResponse push(HttpMethod method, String path, Handler<AsyncResult<HttpServerResponse>> handler)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.- Parameters:
method
-path
-handler
-- Returns:
-
push
public HttpServerResponse push(HttpMethod method, String path)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.- Parameters:
method
-path
-- Returns:
-
rxPush
public io.reactivex.Single<HttpServerResponse> rxPush(HttpMethod method, String path)
Likepush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
with the host copied from the current request.- Parameters:
method
-path
-- Returns:
-
push
public HttpServerResponse push(HttpMethod method, String host, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler)
Push a response to the client. Thehandler
will 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. Thehandler
may 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 requesthost
-path
- the path of the promised requestheaders
- the headers of the promised requesthandler
- the handler notified when the response can be written- Returns:
- a reference to this, so the API can be used fluently
-
push
public HttpServerResponse push(HttpMethod method, String host, String path, MultiMap headers)
Push a response to the client. Thehandler
will 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. Thehandler
may 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 requesthost
-path
- the path of the promised requestheaders
- the headers of the promised request- Returns:
- a reference to this, so the API can be used fluently
-
rxPush
public io.reactivex.Single<HttpServerResponse> rxPush(HttpMethod method, String host, String path, MultiMap headers)
Push a response to the client. Thehandler
will 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. Thehandler
may 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 requesthost
-path
- the path of the promised requestheaders
- the headers of the promised request- Returns:
- a reference to this, so the API can be used fluently
-
push
public Future<HttpServerResponse> push(HttpMethod method, HostAndPort authority, String path, MultiMap headers)
Same aspush(io.vertx.core.http.HttpMethod, java.lang.String, java.lang.String, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.reactivex.core.http.HttpServerResponse>>)
but with anhandler
called when the operation completes- Parameters:
method
-authority
-path
-headers
-- Returns:
-
reset
public boolean reset()
Reset this HTTP/2 stream with the error code0
.- Returns:
-
reset
public boolean reset(long code)
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
false
is returned as indicator.- Parameters:
code
- the error code- Returns:
true
when reset has been performed
- for HTTP/2, send an HTTP/2 reset frame with the specified error
-
writeCustomFrame
public HttpServerResponse writeCustomFrame(int type, int flags, Buffer payload)
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
public HttpServerResponse writeCustomFrame(HttpFrame frame)
LikewriteCustomFrame(int, int, io.vertx.reactivex.core.buffer.Buffer)
but with anHttpFrame
.- Parameters:
frame
- the frame to write- Returns:
-
setStreamPriority
public HttpServerResponse setStreamPriority(StreamPriority streamPriority)
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
public HttpServerResponse addCookie(Cookie cookie)
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
public Cookie removeCookie(String name)
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(java.lang.String)
- Parameters:
name
- the name of the cookie- Returns:
- the cookie, if it existed, or null
-
removeCookie
public Cookie removeCookie(String name, boolean invalidate)
Remove a cookie from the cookie set. If invalidate istrue
then 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(java.lang.String)
- Parameters:
name
- the name of the cookieinvalidate
-- Returns:
- the cookie, if it existed, or
null
-
removeCookies
public Set<Cookie> removeCookies(String name)
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
public Set<Cookie> removeCookies(String name, boolean invalidate)
Remove all cookies from the cookie set. If invalidate istrue
then 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
public Cookie removeCookie(String name, String domain, String path)
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
public Cookie removeCookie(String name, String domain, String path, boolean invalidate)
Remove a cookie from the cookie set. If invalidate istrue
then 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
-
putHeader
public HttpServerResponse putHeader(CharSequence name, CharSequence value)
LikeputHeader(java.lang.String, java.lang.String)
but using CharSequence- Parameters:
name
-value
-- Returns:
-
putHeader
public HttpServerResponse putHeader(String name, Iterable<String> values)
LikeputHeader(java.lang.String, java.lang.String)
but providing multiple values via a String Iterable- Parameters:
name
-values
-- Returns:
-
putHeader
public HttpServerResponse putHeader(CharSequence name, Iterable<CharSequence> values)
LikeputHeader(java.lang.String, java.lang.String)
but with CharSequence Iterable- Parameters:
name
-values
-- Returns:
-
putTrailer
public HttpServerResponse putTrailer(CharSequence name, CharSequence value)
LikeputTrailer(java.lang.String, java.lang.String)
but using CharSequence- Parameters:
name
-value
-- Returns:
-
putTrailer
public HttpServerResponse putTrailer(String name, Iterable<String> values)
LikeputTrailer(java.lang.String, java.lang.String)
but providing multiple values via a String Iterable- Parameters:
name
-values
-- Returns:
-
putTrailer
public HttpServerResponse putTrailer(CharSequence name, Iterable<CharSequence> value)
LikeputTrailer(java.lang.String, java.lang.String)
but with CharSequence Iterable- Parameters:
name
-value
-- Returns:
-
newInstance
public static HttpServerResponse newInstance(HttpServerResponse arg)
-
-