public class DefaultHttpServerResponse extends HttpServerResponse
statusCode, statusMessage| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the underlying TCP connection
|
void |
closeHandler(Handler<java.lang.Void> handler)
Set a close handler for the response.
|
void |
drainHandler(Handler<java.lang.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(java.lang.String chunk)
Same as
HttpServerResponse.end(Buffer) but writes a String with the default encoding before ending the response. |
void |
end(java.lang.String chunk,
java.lang.String enc)
Same as
HttpServerResponse.end(Buffer) but writes a String with the specified encoding before ending the response. |
void |
exceptionHandler(Handler<java.lang.Exception> handler)
Set an exception handler on the stream
|
java.util.Map<java.lang.String,java.lang.Object> |
headers() |
DefaultHttpServerResponse |
putHeader(java.lang.String key,
java.lang.Object value)
Put an HTTP header - fluent API
|
DefaultHttpServerResponse |
putTrailer(java.lang.String key,
java.lang.Object value)
Put an HTTP trailer - fluent API
|
DefaultHttpServerResponse |
sendFile(java.lang.String filename)
Tell the kernel 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. |
DefaultHttpServerResponse |
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. |
void |
setWriteQueueMaxSize(int size)
Set the maximum size of the write queue to
maxSize. |
java.util.Map<java.lang.String,java.lang.Object> |
trailers() |
DefaultHttpServerResponse |
write(Buffer chunk)
Write a
Buffer to the response body. |
DefaultHttpServerResponse |
write(Buffer chunk,
Handler<java.lang.Void> doneHandler)
Write a
Buffer to the response body. |
DefaultHttpServerResponse |
write(java.lang.String chunk)
Write a
String to the response body, encoded in UTF-8. |
DefaultHttpServerResponse |
write(java.lang.String chunk,
Handler<java.lang.Void> doneHandler)
Write a
String to the response body, encoded in UTF-8. |
DefaultHttpServerResponse |
write(java.lang.String chunk,
java.lang.String enc)
Write a
String to the response body, encoded using the encoding enc. |
DefaultHttpServerResponse |
write(java.lang.String chunk,
java.lang.String enc,
Handler<java.lang.Void> doneHandler)
Write a
String to the response body, encoded with encoding enc. |
void |
writeBuffer(Buffer chunk)
Write some data to the stream.
|
boolean |
writeQueueFull()
This will return
true if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int) |
public java.util.Map<java.lang.String,java.lang.Object> headers()
headers in class HttpServerResponsepublic java.util.Map<java.lang.String,java.lang.Object> trailers()
trailers in class HttpServerResponsepublic DefaultHttpServerResponse 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 if any data is written the
body of the response, the total size of that data must be set in the Content-Length header before any
data is written to the response body.
An HTTP chunked response is typically used when you do not know the total size of the request body up front.
setChunked in class HttpServerResponsepublic DefaultHttpServerResponse putHeader(java.lang.String key, java.lang.Object value)
HttpServerResponseputHeader in class HttpServerResponsekey - The header namevalue - The header valuepublic DefaultHttpServerResponse putTrailer(java.lang.String key, java.lang.Object value)
HttpServerResponseputTrailer in class HttpServerResponsekey - The trailer namevalue - The trailer valuepublic void setWriteQueueMaxSize(int size)
WriteStreammaxSize. You will still be able to write to the stream even
if there is more than maxSize bytes in the write queue. This is used as an indicator by classes such as
Pump to provide flow control.public boolean writeQueueFull()
WriteStreamtrue if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int)public void drainHandler(Handler<java.lang.Void> handler)
WriteStreamPump for an example of this being used.public void exceptionHandler(Handler<java.lang.Exception> handler)
WriteStreampublic void closeHandler(Handler<java.lang.Void> handler)
HttpServerResponsecloseHandler in class HttpServerResponsepublic void writeBuffer(Buffer chunk)
WriteStreamWriteStream.writeQueueFull() method before writing. This is done automatically if using a Pump.public DefaultHttpServerResponse write(Buffer chunk)
HttpServerResponseBuffer to the response body.write in class HttpServerResponsepublic DefaultHttpServerResponse write(java.lang.String chunk, java.lang.String enc)
HttpServerResponseString to the response body, encoded using the encoding enc.write in class HttpServerResponsepublic DefaultHttpServerResponse write(java.lang.String chunk)
HttpServerResponseString to the response body, encoded in UTF-8.write in class HttpServerResponsepublic DefaultHttpServerResponse write(Buffer chunk, Handler<java.lang.Void> doneHandler)
HttpServerResponseBuffer to the response body. The doneHandler is called after the buffer is actually written to the wire.write in class HttpServerResponsepublic DefaultHttpServerResponse write(java.lang.String chunk, java.lang.String enc, Handler<java.lang.Void> doneHandler)
HttpServerResponseString to the response body, encoded with encoding enc. The doneHandler is called
after the buffer is actually written to the wire.write in class HttpServerResponsepublic DefaultHttpServerResponse write(java.lang.String chunk, Handler<java.lang.Void> doneHandler)
HttpServerResponseString to the response body, encoded in UTF-8. The doneHandler is called after the buffer
is actually written to the wire.write in class HttpServerResponsepublic void end(java.lang.String chunk)
HttpServerResponseHttpServerResponse.end(Buffer) but writes a String with the default encoding before ending the response.end in class HttpServerResponsepublic void end(java.lang.String chunk,
java.lang.String enc)
HttpServerResponseHttpServerResponse.end(Buffer) but writes a String with the specified encoding before ending the response.end in class 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 Content-Length header will be automatically setend in class HttpServerResponsepublic void close()
HttpServerResponseclose in class HttpServerResponsepublic void end()
HttpServerResponseOnce the response has ended, it cannot be used any more.
end in class HttpServerResponsepublic DefaultHttpServerResponse sendFile(java.lang.String filename)
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.sendFile in class HttpServerResponse