public class Http2ServerResponseImpl extends Object implements HttpServerResponse
| Constructor and Description |
|---|
Http2ServerResponseImpl(Http2ServerConnection conn,
io.vertx.core.http.impl.Http2ServerStream stream,
HttpMethod method,
boolean push,
String contentEncoding,
String host) |
| Modifier and Type | Method and 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()
Close the underlying TCP connection corresponding to the request.
|
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()
Ends the response.
|
void |
end(Buffer chunk)
Same as
HttpServerResponse.end() but writes some data to the response body before ending. |
void |
end(Buffer chunk,
Handler<AsyncResult<Void>> handler)
Same as
HttpServerResponse.end(Buffer) but with an handler called when the operation completes |
void |
end(Handler<AsyncResult<Void>> handler)
Same as
WriteStream.end() but with an handler called when the operation completes |
void |
end(String chunk)
Same as
HttpServerResponse.end(Buffer) but writes a String in UTF-8 encoding before ending the response. |
void |
end(String chunk,
Handler<AsyncResult<Void>> handler)
Same as
HttpServerResponse.end(String) but with an handler called when the operation completes |
void |
end(String chunk,
String enc)
Same as
HttpServerResponse.end(Buffer) but writes a String with the specified encoding before ending the response. |
void |
end(String chunk,
String enc,
Handler<AsyncResult<Void>> handler)
Same as
HttpServerResponse.end(String, String) but with an handler called when the operation completes |
boolean |
ended() |
HttpServerResponse |
endHandler(Handler<Void> handler)
Set an end handler for the response.
|
HttpServerResponse |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the write stream.
|
int |
getStatusCode() |
String |
getStatusMessage() |
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() |
HttpServerResponse |
push(HttpMethod method,
String path,
Handler<AsyncResult<HttpServerResponse>> handler)
Like
HttpServerResponse.push(HttpMethod, String, String, MultiMap, Handler) with the host copied from the current request. |
HttpServerResponse |
push(HttpMethod method,
String path,
MultiMap headers,
Handler<AsyncResult<HttpServerResponse>> handler)
Like
HttpServerResponse.push(HttpMethod, String, String, MultiMap, Handler) with the host copied from the current request. |
HttpServerResponse |
push(HttpMethod method,
String host,
String path,
Handler<AsyncResult<HttpServerResponse>> handler)
Like
HttpServerResponse.push(HttpMethod, String, String, MultiMap, Handler) with no headers. |
HttpServerResponse |
push(HttpMethod method,
String host,
String path,
MultiMap headers,
Handler<AsyncResult<HttpServerResponse>> handler)
Push a response to the client.
The
handler 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.
The handler 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. |
HttpServerResponse |
putHeader(CharSequence name,
CharSequence value)
Like
HttpServerResponse.putHeader(String, String) but using CharSequence |
HttpServerResponse |
putHeader(CharSequence name,
Iterable<CharSequence> values)
Like
HttpServerResponse.putHeader(String, Iterable) but with CharSequence Iterable |
HttpServerResponse |
putHeader(String name,
Iterable<String> values)
Like
HttpServerResponse.putHeader(String, String) but providing multiple values via a String Iterable |
HttpServerResponse |
putHeader(String name,
String value)
Put an HTTP header
|
HttpServerResponse |
putTrailer(CharSequence name,
CharSequence value)
Like
HttpServerResponse.putTrailer(String, String) but using CharSequence |
HttpServerResponse |
putTrailer(CharSequence name,
Iterable<CharSequence> value)
Like
HttpServerResponse.putTrailer(String, Iterable) but with CharSequence Iterable |
HttpServerResponse |
putTrailer(String name,
Iterable<String> values)
Like
HttpServerResponse.putTrailer(String, String) but providing multiple values via a String Iterable |
HttpServerResponse |
putTrailer(String name,
String value)
Put an HTTP trailer
|
Cookie |
removeCookie(String name,
boolean invalidate)
Remove a cookie from the cookie set.
|
void |
reset(long code)
Reset this HTTP/2 stream with the error
code. |
HttpServerResponse |
sendFile(String filename,
long offset,
long length)
Ask the OS to stream a file as specified by
filename directly
from disk to the outgoing connection, bypassing userspace altogether
(where supported by the underlying operating system. |
HttpServerResponse |
sendFile(String filename,
long offset,
long length,
Handler<AsyncResult<Void>> resultHandler)
Like
HttpServerResponse.sendFile(String, long, long) but providing a handler which will be notified once the file has been
completely written to the wire. |
HttpServerResponse |
setChunked(boolean chunked)
If
chunked is true, 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 message
|
HttpServerResponse |
setStreamPriority(StreamPriority priority)
Sets the priority of the associated stream
This is not implemented for HTTP/1.x.
|
HttpServerResponse |
setWriteQueueMaxSize(int maxSize)
Set the maximum size of the write queue to
maxSize. |
int |
streamId() |
MultiMap |
trailers() |
HttpServerResponse |
write(Buffer chunk)
Write some data to the stream.
|
HttpServerResponse |
write(Buffer chunk,
Handler<AsyncResult<Void>> handler)
Same as
HttpServerResponse.write(Buffer) but with an handler called when the operation completes |
HttpServerResponse |
write(String chunk)
Write a
String to the response body, encoded in UTF-8. |
HttpServerResponse |
write(String chunk,
Handler<AsyncResult<Void>> handler)
Same as
HttpServerResponse.write(String) but with an handler called when the operation completes |
HttpServerResponse |
write(String chunk,
String enc)
Write a
String to the response body, encoded using the encoding enc. |
HttpServerResponse |
write(String chunk,
String enc,
Handler<AsyncResult<Void>> handler)
Same as
HttpServerResponse.write(String, String) but with an handler called when the operation completes |
HttpServerResponse |
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.
|
boolean |
writeQueueFull()
This will return
true if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitremoveCookie, reset, sendFile, sendFile, sendFile, sendFile, writeCustomFramepublic Http2ServerResponseImpl(Http2ServerConnection conn, io.vertx.core.http.impl.Http2ServerStream stream, HttpMethod method, boolean push, String contentEncoding, String host)
public HttpServerResponse exceptionHandler(Handler<Throwable> handler)
WriteStreamexceptionHandler in interface HttpServerResponseexceptionHandler in interface StreamBaseexceptionHandler in interface WriteStream<Buffer>handler - the exception handlerpublic int getStatusCode()
getStatusCode in interface HttpServerResponse200 representing OK.public HttpServerResponse setStatusCode(int statusCode)
HttpServerResponsesetStatusCode in interface HttpServerResponsepublic String getStatusMessage()
getStatusMessage in interface HttpServerResponseHttpServerResponse.setStatusCode(int) has been set to.public HttpServerResponse setStatusMessage(String statusMessage)
HttpServerResponsesetStatusMessage in interface HttpServerResponsepublic HttpServerResponse setChunked(boolean chunked)
HttpServerResponsechunked is true, 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 of Chunked will be
automatically inserted in the response.
If chunked is false, 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 the Content-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.
setChunked in interface HttpServerResponsepublic boolean isChunked()
isChunked in interface HttpServerResponsepublic MultiMap headers()
headers in interface HttpServerResponsepublic HttpServerResponse putHeader(String name, String value)
HttpServerResponseputHeader in interface HttpServerResponsename - the header namevalue - the header value.public HttpServerResponse putHeader(CharSequence name, CharSequence value)
HttpServerResponseHttpServerResponse.putHeader(String, String) but using CharSequenceputHeader in interface HttpServerResponsepublic HttpServerResponse putHeader(String name, Iterable<String> values)
HttpServerResponseHttpServerResponse.putHeader(String, String) but providing multiple values via a String IterableputHeader in interface HttpServerResponsepublic HttpServerResponse putHeader(CharSequence name, Iterable<CharSequence> values)
HttpServerResponseHttpServerResponse.putHeader(String, Iterable) but with CharSequence IterableputHeader in interface HttpServerResponsepublic MultiMap trailers()
trailers in interface HttpServerResponsepublic HttpServerResponse putTrailer(String name, String value)
HttpServerResponseputTrailer in interface HttpServerResponsename - the trailer namevalue - the trailer valuepublic HttpServerResponse putTrailer(CharSequence name, CharSequence value)
HttpServerResponseHttpServerResponse.putTrailer(String, String) but using CharSequenceputTrailer in interface HttpServerResponsepublic HttpServerResponse putTrailer(String name, Iterable<String> values)
HttpServerResponseHttpServerResponse.putTrailer(String, String) but providing multiple values via a String IterableputTrailer in interface HttpServerResponsepublic HttpServerResponse putTrailer(CharSequence name, Iterable<CharSequence> value)
HttpServerResponseHttpServerResponse.putTrailer(String, Iterable) but with CharSequence IterableputTrailer in interface HttpServerResponsepublic HttpServerResponse closeHandler(Handler<Void> handler)
HttpServerResponse
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.
closeHandler in interface HttpServerResponsehandler - the handlerpublic HttpServerResponse endHandler(Handler<Void> handler)
HttpServerResponseendHandler in interface HttpServerResponsehandler - the handlerpublic HttpServerResponse writeContinue()
HttpServerResponsewriteContinue in interface HttpServerResponsepublic HttpServerResponse write(Buffer chunk)
WriteStreamWriteStream.writeQueueFull() method before writing. This is done automatically if using a Pump.write in interface HttpServerResponsewrite in interface WriteStream<Buffer>chunk - the data to writepublic HttpServerResponse write(Buffer chunk, Handler<AsyncResult<Void>> handler)
HttpServerResponseHttpServerResponse.write(Buffer) but with an handler called when the operation completeswrite in interface HttpServerResponsewrite in interface WriteStream<Buffer>public HttpServerResponse write(String chunk, String enc)
HttpServerResponseString to the response body, encoded using the encoding enc.write in interface HttpServerResponsechunk - the string to writeenc - the encoding to usepublic HttpServerResponse write(String chunk, String enc, Handler<AsyncResult<Void>> handler)
HttpServerResponseHttpServerResponse.write(String, String) but with an handler called when the operation completeswrite in interface HttpServerResponsepublic HttpServerResponse write(String chunk)
HttpServerResponseString to the response body, encoded in UTF-8.write in interface HttpServerResponsechunk - the string to writepublic HttpServerResponse write(String chunk, Handler<AsyncResult<Void>> handler)
HttpServerResponseHttpServerResponse.write(String) but with an handler called when the operation completeswrite in interface HttpServerResponsepublic void end(String chunk)
HttpServerResponseHttpServerResponse.end(Buffer) but writes a String in UTF-8 encoding before ending the response.end in interface HttpServerResponsechunk - the string to write before ending the responsepublic void end(String chunk, Handler<AsyncResult<Void>> handler)
HttpServerResponseHttpServerResponse.end(String) but with an handler called when the operation completesend in interface HttpServerResponsepublic void end(String chunk, String enc)
HttpServerResponseHttpServerResponse.end(Buffer) but writes a String with the specified encoding before ending the response.end in interface HttpServerResponsechunk - the string to write before ending the responseenc - the encoding to usepublic void end(String chunk, String enc, Handler<AsyncResult<Void>> handler)
HttpServerResponseHttpServerResponse.end(String, String) but with an handler called when the operation completesend in interface HttpServerResponsepublic void end(Buffer chunk)
HttpServerResponseHttpServerResponse.end() 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.end in interface HttpServerResponseend in interface WriteStream<Buffer>chunk - the buffer to write before ending the responsepublic void end(Buffer chunk, Handler<AsyncResult<Void>> handler)
HttpServerResponseHttpServerResponse.end(Buffer) but with an handler called when the operation completesend in interface HttpServerResponseend in interface WriteStream<Buffer>public void end()
HttpServerResponseOnce the response has ended, it cannot be used any more.
end in interface HttpServerResponseend in interface WriteStream<Buffer>public void end(Handler<AsyncResult<Void>> handler)
WriteStreamWriteStream.end() but with an handler called when the operation completesend in interface WriteStream<Buffer>public HttpServerResponse writeCustomFrame(int type, int flags, Buffer payload)
HttpServerResponseThe frame is sent immediatly and is not subject to flow control.
writeCustomFrame in interface HttpServerResponsetype - the 8-bit frame typeflags - the 8-bit frame flagspayload - the frame payloadpublic boolean writeQueueFull()
WriteStreamtrue if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int)writeQueueFull in interface WriteStream<Buffer>public HttpServerResponse setWriteQueueMaxSize(int maxSize)
WriteStreammaxSize. You will still be able to write to the stream even
if there is more than maxSize items in the write queue. This is used as an indicator by classes such as
Pump to provide flow control.
The value is defined by the implementation of the stream, e.g in bytes for a
NetSocket, the number of Message for a
MessageProducer, etc...setWriteQueueMaxSize in interface HttpServerResponsesetWriteQueueMaxSize in interface WriteStream<Buffer>maxSize - the max size of the write streampublic HttpServerResponse drainHandler(Handler<Void> handler)
WriteStreamPump 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.drainHandler in interface HttpServerResponsedrainHandler in interface WriteStream<Buffer>handler - the handlerpublic HttpServerResponse sendFile(String filename, long offset, long length)
HttpServerResponsefilename directly
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.
sendFile in interface HttpServerResponsefilename - path to the file to serveoffset - offset to start serving fromlength - the number of bytes to sendpublic HttpServerResponse sendFile(String filename, long offset, long length, Handler<AsyncResult<Void>> resultHandler)
HttpServerResponseHttpServerResponse.sendFile(String, long, long) but providing a handler which will be notified once the file has been
completely written to the wire.sendFile in interface HttpServerResponsefilename - path to the file to serveoffset - the offset to serve fromlength - the length to serve toresultHandler - handler that will be called on completionpublic void close()
HttpServerResponseclose in interface HttpServerResponsepublic boolean ended()
ended in interface HttpServerResponsepublic boolean closed()
closed in interface HttpServerResponsepublic boolean headWritten()
headWritten in interface HttpServerResponsepublic HttpServerResponse headersEndHandler(Handler<Void> handler)
HttpServerResponseThis provides a hook allowing you to add any more headers or do any more operations before this occurs.
headersEndHandler in interface HttpServerResponsehandler - the handlerpublic HttpServerResponse bodyEndHandler(Handler<Void> handler)
HttpServerResponsebodyEndHandler in interface HttpServerResponsehandler - the handlerpublic long bytesWritten()
bytesWritten in interface HttpServerResponsepublic int streamId()
streamId in interface HttpServerResponsepublic void reset(long code)
HttpServerResponsecode.reset in interface HttpServerResponsecode - the error codepublic HttpServerResponse push(HttpMethod method, String host, String path, Handler<AsyncResult<HttpServerResponse>> handler)
HttpServerResponseHttpServerResponse.push(HttpMethod, String, String, MultiMap, Handler) with no headers.push in interface HttpServerResponsepublic HttpServerResponse push(HttpMethod method, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler)
HttpServerResponseHttpServerResponse.push(HttpMethod, String, String, MultiMap, Handler) with the host copied from the current request.push in interface HttpServerResponsepublic HttpServerResponse push(HttpMethod method, String host, String path, MultiMap headers, Handler<AsyncResult<HttpServerResponse>> handler)
HttpServerResponsehandler 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.
The handler 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.push in interface HttpServerResponsemethod - the method of the promised requesthost - the host of the promised requestpath - the path of the promised requestheaders - the headers of the promised requesthandler - the handler notified when the response can be writtenpublic HttpServerResponse push(HttpMethod method, String path, Handler<AsyncResult<HttpServerResponse>> handler)
HttpServerResponseHttpServerResponse.push(HttpMethod, String, String, MultiMap, Handler) with the host copied from the current request.push in interface HttpServerResponsepublic HttpServerResponse setStreamPriority(StreamPriority priority)
HttpServerResponsesetStreamPriority in interface HttpServerResponsepriority - the priority for this request's streampublic HttpServerResponse addCookie(Cookie cookie)
HttpServerResponseaddCookie in interface HttpServerResponsecookie - the cookiepublic Cookie removeCookie(String name, boolean invalidate)
HttpServerResponseremoveCookie in interface HttpServerResponsename - the name of the cookieCopyright © 2020. All rights reserved.