public class HttpServerResponseImpl extends Object implements HttpServerResponse
Modifier and Type | Method and Description |
---|---|
HttpServerResponse |
bodyEndHandler(Handler<Void> handler)
Provide a handler that will be called just before the last part of the body is written to the wire
and the response is ended.
|
void |
close()
Close the underlying TCP connection corresponding to the request.
|
HttpServerResponse |
closeHandler(Handler<Void> handler)
Set a close handler for the response.
|
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(String chunk)
Same as
HttpServerResponse.end(Buffer) but writes a String in UTF-8 encoding before ending the response. |
void |
end(String chunk,
String enc)
Same as
HttpServerResponse.end(Buffer) but writes a String with the specified encoding before ending the response. |
boolean |
ended() |
HttpServerResponse |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the write stream.
|
int |
getStatusCode() |
String |
getStatusMessage() |
MultiMap |
headers() |
HttpServerResponse |
headersEndHandler(Handler<Future> handler)
Provide a handler that will be called just before the headers are written to the wire.
|
boolean |
headWritten() |
boolean |
isChunked() |
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 |
HttpServerResponseImpl |
putHeader(String key,
Iterable<String> values)
Like
HttpServerResponse.putHeader(String, String) but providing multiple values via a String Iterable |
HttpServerResponseImpl |
putHeader(String key,
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 |
HttpServerResponseImpl |
putTrailer(String key,
Iterable<String> values)
Like
HttpServerResponse.putTrailer(String, String) but providing multiple values via a String Iterable |
HttpServerResponseImpl |
putTrailer(String key,
String value)
Put an HTTP trailer
|
HttpServerResponseImpl |
sendFile(String filename)
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,
Handler<AsyncResult<Void>> resultHandler)
Like
HttpServerResponse.sendFile(String) but providing a handler which will be notified once the file has been completely
written to the wire. |
HttpServerResponseImpl |
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 |
setWriteQueueMaxSize(int size)
Set the maximum size of the write queue to
maxSize . |
MultiMap |
trailers() |
HttpServerResponseImpl |
write(Buffer chunk)
Write some data to the stream.
|
HttpServerResponseImpl |
write(String chunk)
Write a
String to the response body, encoded in UTF-8. |
HttpServerResponseImpl |
write(String chunk,
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 HttpServerResponse
public MultiMap trailers()
trailers
in interface HttpServerResponse
public int getStatusCode()
getStatusCode
in interface HttpServerResponse
200
representing OK
.public HttpServerResponse setStatusCode(int statusCode)
HttpServerResponse
setStatusCode
in interface HttpServerResponse
public String getStatusMessage()
getStatusMessage
in interface HttpServerResponse
HttpServerResponse.setStatusCode(int)
has been set to.public HttpServerResponse setStatusMessage(String statusMessage)
HttpServerResponse
setStatusMessage
in interface HttpServerResponse
public HttpServerResponseImpl 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 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 HttpServerResponse
public boolean isChunked()
isChunked
in interface HttpServerResponse
public HttpServerResponseImpl putHeader(String key, String value)
HttpServerResponse
putHeader
in interface HttpServerResponse
key
- the header namevalue
- the header value.public HttpServerResponseImpl putHeader(String key, Iterable<String> values)
HttpServerResponse
HttpServerResponse.putHeader(String, String)
but providing multiple values via a String IterableputHeader
in interface HttpServerResponse
public HttpServerResponseImpl putTrailer(String key, String value)
HttpServerResponse
putTrailer
in interface HttpServerResponse
key
- the trailer namevalue
- the trailer valuepublic HttpServerResponseImpl putTrailer(String key, Iterable<String> values)
HttpServerResponse
HttpServerResponse.putTrailer(String, String)
but providing multiple values via a String IterableputTrailer
in interface HttpServerResponse
public HttpServerResponse putHeader(CharSequence name, CharSequence value)
HttpServerResponse
HttpServerResponse.putHeader(String, String)
but using CharSequenceputHeader
in interface HttpServerResponse
public HttpServerResponse putHeader(CharSequence name, Iterable<CharSequence> values)
HttpServerResponse
HttpServerResponse.putHeader(String, Iterable)
but with CharSequence IterableputHeader
in interface HttpServerResponse
public HttpServerResponse putTrailer(CharSequence name, CharSequence value)
HttpServerResponse
HttpServerResponse.putTrailer(String, String)
but using CharSequenceputTrailer
in interface HttpServerResponse
public HttpServerResponse putTrailer(CharSequence name, Iterable<CharSequence> value)
HttpServerResponse
HttpServerResponse.putTrailer(String, Iterable)
but with CharSequence IterableputTrailer
in interface HttpServerResponse
public HttpServerResponse 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.setWriteQueueMaxSize
in interface HttpServerResponse
setWriteQueueMaxSize
in interface WriteStream<Buffer>
size
- the max size of the write streampublic boolean writeQueueFull()
WriteStream
true
if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int)
writeQueueFull
in interface WriteStream<Buffer>
public HttpServerResponse drainHandler(Handler<Void> handler)
WriteStream
Pump
for an example of this being used.drainHandler
in interface HttpServerResponse
drainHandler
in interface WriteStream<Buffer>
handler
- the handlerpublic HttpServerResponse exceptionHandler(Handler<Throwable> handler)
WriteStream
exceptionHandler
in interface HttpServerResponse
exceptionHandler
in interface StreamBase
exceptionHandler
in interface WriteStream<Buffer>
handler
- the exception handlerpublic HttpServerResponse closeHandler(Handler<Void> handler)
HttpServerResponse
closeHandler
in interface HttpServerResponse
handler
- the handlerpublic HttpServerResponseImpl write(Buffer chunk)
WriteStream
WriteStream.writeQueueFull()
method before writing. This is done automatically if using a Pump
.write
in interface HttpServerResponse
write
in interface WriteStream<Buffer>
chunk
- the data to writepublic HttpServerResponseImpl write(String chunk, String enc)
HttpServerResponse
String
to the response body, encoded using the encoding enc
.write
in interface HttpServerResponse
chunk
- the string to writeenc
- the encoding to usepublic HttpServerResponseImpl write(String chunk)
HttpServerResponse
String
to the response body, encoded in UTF-8.write
in interface HttpServerResponse
chunk
- the string to writepublic void end(String chunk)
HttpServerResponse
HttpServerResponse.end(Buffer)
but writes a String in UTF-8 encoding before ending the response.end
in interface HttpServerResponse
chunk
- the string to write before ending the responsepublic void end(String chunk, String enc)
HttpServerResponse
HttpServerResponse.end(Buffer)
but writes a String with the specified encoding before ending the response.end
in interface HttpServerResponse
chunk
- the string to write before ending the responseenc
- the encoding to usepublic 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 @code{Content-Length} header will be automatically set.end
in interface HttpServerResponse
chunk
- the buffer to write before ending the responsepublic void close()
HttpServerResponse
close
in interface HttpServerResponse
public void end()
HttpServerResponse
Once the response has ended, it cannot be used any more.
end
in interface HttpServerResponse
public HttpServerResponseImpl sendFile(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.The actual serve is asynchronous and may not complete until some time after this method has returned.
sendFile
in interface HttpServerResponse
filename
- path to the file to servepublic HttpServerResponse sendFile(String filename, Handler<AsyncResult<Void>> resultHandler)
HttpServerResponse
HttpServerResponse.sendFile(String)
but providing a handler which will be notified once the file has been completely
written to the wire.sendFile
in interface HttpServerResponse
filename
- path to the file to serveresultHandler
- handler that will be called on completionpublic boolean ended()
ended
in interface HttpServerResponse
public boolean headWritten()
headWritten
in interface HttpServerResponse
public HttpServerResponse headersEndHandler(Handler<Future> handler)
HttpServerResponse
This provides a hook allowing you to add any more headers or do any more operations before this occurs. The handler will be passed a future, when you've completed the work you want to do you should complete (or fail) the future. This can be done after the handler has returned.
headersEndHandler
in interface HttpServerResponse
handler
- the handlerpublic HttpServerResponse bodyEndHandler(Handler<Void> handler)
HttpServerResponse
This provides a hook allowing you to do any more operations before this occurs.
bodyEndHandler
in interface HttpServerResponse
handler
- the handlerCopyright © 2015. All Rights Reserved.