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 HttpServerResponse
public java.util.Map<java.lang.String,java.lang.Object> trailers()
trailers
in class HttpServerResponse
public DefaultHttpServerResponse setChunked(boolean chunked)
HttpServerResponse
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.
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 HttpServerResponse
public DefaultHttpServerResponse putHeader(java.lang.String key, java.lang.Object value)
HttpServerResponse
putHeader
in class HttpServerResponse
key
- The header namevalue
- The header valuepublic DefaultHttpServerResponse putTrailer(java.lang.String key, java.lang.Object value)
HttpServerResponse
putTrailer
in class HttpServerResponse
key
- The trailer namevalue
- The trailer valuepublic void setWriteQueueMaxSize(int size)
WriteStream
maxSize
. 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()
WriteStream
true
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)
WriteStream
Pump
for an example of this being used.public void exceptionHandler(Handler<java.lang.Exception> handler)
WriteStream
public void closeHandler(Handler<java.lang.Void> handler)
HttpServerResponse
closeHandler
in class HttpServerResponse
public void writeBuffer(Buffer chunk)
WriteStream
WriteStream.writeQueueFull()
method before writing. This is done automatically if using a Pump
.public DefaultHttpServerResponse write(Buffer chunk)
HttpServerResponse
Buffer
to the response body.write
in class HttpServerResponse
public DefaultHttpServerResponse write(java.lang.String chunk, java.lang.String enc)
HttpServerResponse
String
to the response body, encoded using the encoding enc
.write
in class HttpServerResponse
public DefaultHttpServerResponse write(java.lang.String chunk)
HttpServerResponse
String
to the response body, encoded in UTF-8.write
in class HttpServerResponse
public DefaultHttpServerResponse write(Buffer chunk, Handler<java.lang.Void> doneHandler)
HttpServerResponse
Buffer
to the response body. The doneHandler
is called after the buffer is actually written to the wire.write
in class HttpServerResponse
public DefaultHttpServerResponse write(java.lang.String chunk, java.lang.String enc, Handler<java.lang.Void> doneHandler)
HttpServerResponse
String
to the response body, encoded with encoding enc
. The doneHandler
is called
after the buffer is actually written to the wire.write
in class HttpServerResponse
public DefaultHttpServerResponse write(java.lang.String chunk, Handler<java.lang.Void> doneHandler)
HttpServerResponse
String
to the response body, encoded in UTF-8. The doneHandler
is called after the buffer
is actually written to the wire.write
in class HttpServerResponse
public void end(java.lang.String chunk)
HttpServerResponse
HttpServerResponse.end(Buffer)
but writes a String with the default encoding before ending the response.end
in class HttpServerResponse
public void end(java.lang.String chunk, java.lang.String enc)
HttpServerResponse
HttpServerResponse.end(Buffer)
but writes a String with the specified encoding before ending the response.end
in class HttpServerResponse
public void end(Buffer chunk)
HttpServerResponse
HttpServerResponse.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 HttpServerResponse
public void close()
HttpServerResponse
close
in class HttpServerResponse
public void end()
HttpServerResponse
Once the response has ended, it cannot be used any more.
end
in class HttpServerResponse
public DefaultHttpServerResponse sendFile(java.lang.String filename)
HttpServerResponse
filename
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