public class DefaultHttpServerResponse extends java.lang.Object implements HttpServerResponse
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the underlying TCP connection
|
HttpServerResponse |
closeHandler(Handler<java.lang.Void> handler)
Set a close handler for the response.
|
HttpServerResponse |
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. |
HttpServerResponse |
exceptionHandler(Handler<java.lang.Throwable> handler)
Set an exception handler.
|
int |
getStatusCode()
The HTTP status code of the response.
|
java.lang.String |
getStatusMessage()
The HTTP status message of the response.
|
MultiMap |
headers() |
boolean |
isChunked()
Is the response chunked?
|
DefaultHttpServerResponse |
putHeader(java.lang.String key,
java.lang.Iterable<java.lang.String> values)
Put an HTTP header - fluent API
|
DefaultHttpServerResponse |
putHeader(java.lang.String key,
java.lang.String value)
Put an HTTP header - fluent API
|
DefaultHttpServerResponse |
putTrailer(java.lang.String key,
java.lang.Iterable<java.lang.String> values)
Put an HTTP trailer - fluent API
|
DefaultHttpServerResponse |
putTrailer(java.lang.String key,
java.lang.String 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 |
sendFile(java.lang.String filename,
java.lang.String notFoundResource)
Same as
HttpServerResponse.sendFile(String) but also takes the path to a resource to serve if the resource is not found |
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. |
HttpServerResponse |
setStatusCode(int statusCode)
Set the status code
|
HttpServerResponse |
setStatusMessage(java.lang.String statusMessage)
Set the status message
|
HttpServerResponse |
setWriteQueueMaxSize(int size)
Set the maximum size of the write queue to
maxSize. |
MultiMap |
trailers() |
DefaultHttpServerResponse |
write(Buffer chunk)
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,
java.lang.String enc)
Write a
String to the response body, encoded using the encoding enc. |
boolean |
writeQueueFull()
This will return
true if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int) |
public MultiMap headers()
headers in interface HttpServerResponsepublic MultiMap trailers()
trailers in interface HttpServerResponsepublic int getStatusCode()
HttpServerResponse200 representing OK.getStatusCode in interface HttpServerResponsepublic HttpServerResponse setStatusCode(int statusCode)
HttpServerResponsesetStatusCode in interface HttpServerResponsepublic java.lang.String getStatusMessage()
HttpServerResponseHttpServerResponse.setStatusCode(int) has been set to.getStatusMessage in interface HttpServerResponsepublic HttpServerResponse setStatusMessage(java.lang.String statusMessage)
HttpServerResponsesetStatusMessage in interface 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 interface HttpServerResponsepublic boolean isChunked()
HttpServerResponseisChunked in interface HttpServerResponsepublic DefaultHttpServerResponse putHeader(java.lang.String key, java.lang.String value)
HttpServerResponseputHeader in interface HttpServerResponsekey - The header namevalue - The header value.public DefaultHttpServerResponse putHeader(java.lang.String key, java.lang.Iterable<java.lang.String> values)
HttpServerResponseputHeader in interface HttpServerResponsekey - The header namevalues - The header values.public DefaultHttpServerResponse putTrailer(java.lang.String key, java.lang.String value)
HttpServerResponseputTrailer in interface HttpServerResponsekey - The trailer namevalue - The trailer valuepublic DefaultHttpServerResponse putTrailer(java.lang.String key, java.lang.Iterable<java.lang.String> values)
HttpServerResponseputTrailer in interface HttpServerResponsekey - The trailer namevalues - The trailer valuespublic HttpServerResponse 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.setWriteQueueMaxSize in interface WriteStream<HttpServerResponse>public boolean writeQueueFull()
WriteStreamtrue if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int)writeQueueFull in interface WriteStream<HttpServerResponse>public HttpServerResponse drainHandler(Handler<java.lang.Void> handler)
WriteStreamPump for an example of this being used.drainHandler in interface WriteStream<HttpServerResponse>public HttpServerResponse exceptionHandler(Handler<java.lang.Throwable> handler)
ExceptionSupportexceptionHandler in interface ExceptionSupport<HttpServerResponse>public HttpServerResponse closeHandler(Handler<java.lang.Void> handler)
HttpServerResponsecloseHandler in interface HttpServerResponsepublic DefaultHttpServerResponse write(Buffer chunk)
HttpServerResponseBuffer to the response body.write in interface HttpServerResponsewrite in interface WriteStream<HttpServerResponse>public DefaultHttpServerResponse write(java.lang.String chunk, java.lang.String enc)
HttpServerResponseString to the response body, encoded using the encoding enc.write in interface HttpServerResponsepublic DefaultHttpServerResponse write(java.lang.String chunk)
HttpServerResponseString to the response body, encoded in UTF-8.write in interface HttpServerResponsepublic void end(java.lang.String chunk)
HttpServerResponseHttpServerResponse.end(Buffer) but writes a String with the default encoding before ending the response.end in interface 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 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 Content-Length header will be automatically setend in interface HttpServerResponsepublic void close()
HttpServerResponseclose in interface HttpServerResponsepublic void end()
HttpServerResponseOnce the response has ended, it cannot be used any more.
end in interface 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 interface HttpServerResponsepublic DefaultHttpServerResponse sendFile(java.lang.String filename, java.lang.String notFoundResource)
HttpServerResponseHttpServerResponse.sendFile(String) but also takes the path to a resource to serve if the resource is not foundsendFile in interface HttpServerResponse