Represents a server-side HTTP response.
An instance of this is created and associated to every instance of HttpServerRequest that.
It allows the developer to control the HTTP response that is sent back to the client for a particular HTTP request.
It contains methods that allow HTTP headers and trailers to be set, and for a body to be written out to the response.
It also allows files to be streamed by the kernel directly from disk to the outgoing HTTP connection, bypassing user space altogether (where supported by the underlying operating system). This is a very efficient way of serving files from the server since buffers do not have to be read one by one from the file and written to the outgoing socket.
It implements WriteStream so it can be used with Pump to pump data with flow control.
Anything
HttpServerResponse
Basic
Identifiable
Object
Anything
no subtypes hierarchy
Initializer |
HttpServerResponse(HttpServerResponse unknown) |
Inherited Attributes |
Attributes inherited from: Object hash , string |
Methods | |
bodyEndHandler | shared default HttpServerResponse bodyEndHandler(Anything()? handler) Provides a handler that will be called after the last part of the body is written to the wire. The handler is called asynchronously of when the response has been received by the client. This provides a hook allowing you to do more operations once the request has been sent over the wire such as resource cleanup. Parameters:
|
bytesWritten | shared default Integer bytesWritten() |
close | shared default void close() Close the underlying TCP connection corresponding to the request. |
closeHandler | shared default HttpServerResponse closeHandler(Anything()? 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.
For HTTP/1.x it is called when the connection is closed before For HTTP/2 it is called when the related stream is closed, and therefore it will be always be called. Parameters:
|
closed | shared default Boolean closed() |
drainHandler | shared actual default HttpServerResponse drainHandler(Anything()? handler) Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pump 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 tomaxSize / 2 .
Refines WriteStream.drainHandler |
end | shared actual default void end() Ends the response. If no data has been written to the response body, the actual response won't get written until this method gets called. Once the response has ended, it cannot be used any more. Refines WriteStream.end |
end | shared actual default void end(Buffer chunk) Same as 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. Parameters:
|
end | shared default void end(String chunk) Same as end but writes a String in UTF-8 encoding before ending the response. Parameters:
|
end | shared default void end(String chunk, String enc) Same as end but writes a String with the specified encoding before ending the response. Parameters:
|
endHandler | shared default HttpServerResponse endHandler(Anything()? handler) Set an end handler for the response. This will be called when the response is disposed to allow consistent cleanup of the response. Parameters:
|
ended | shared default Boolean ended() |
exceptionHandler | shared actual default HttpServerResponse exceptionHandler(Anything(Throwable)? handler) Set an exception handler. Refines StreamBase.exceptionHandler |
getStatusCode | shared default Integer getStatusCode() |
getStatusMessage | shared default String getStatusMessage() |
headWritten | shared default Boolean headWritten() |
headers | shared default MultiMap headers() |
headersEndHandler | shared default HttpServerResponse headersEndHandler(Anything()? handler) Provide a handler that will be called just before the headers are written to the wire. This provides a hook allowing you to add any more headers or do any more operations before this occurs. Parameters:
|
isChunked | shared default Boolean isChunked() |
push | shared default HttpServerResponse push(HttpMethod method, String path, Anything(Throwable|HttpServerResponse) handler) Like push with the host copied from the current request. |
push | shared default HttpServerResponse push(HttpMethod method, String host, String path, Anything(Throwable|HttpServerResponse) handler) Like push with no headers. |
push | shared default HttpServerResponse push(HttpMethod method, String path, MultiMap headers, Anything(Throwable|HttpServerResponse) handler) Like push with the host copied from the current request. |
push | shared default HttpServerResponse push(HttpMethod method, String host, String path, MultiMap headers, Anything(Throwable|HttpServerResponse) handler) Push a response to the client. The The Push can be sent only for peer initiated streams and if the response is not ended. Parameters:
|
putHeader | shared default HttpServerResponse putHeader(String name, String value) Put an HTTP header Parameters:
|
putTrailer | shared default HttpServerResponse putTrailer(String name, String value) Put an HTTP trailer Parameters:
|
reset | shared default void reset() Reset this HTTP/2 stream with the error code |
reset | shared default void reset(Integer code) Reset this HTTP/2 stream with the error Parameters:
|
sendFile | shared default HttpServerResponse sendFile(String filename) Same as sendFile using offset @code{0} which means starting from the beginning of the file. Parameters:
|
sendFile | shared default HttpServerResponse sendFile(String filename, Anything(Throwable?) resultHandler) Like sendFile but providing a handler which will be notified once the file has been completely written to the wire. Parameters:
|
sendFile | shared default HttpServerResponse sendFile(String filename, Integer offset) Same as sendFile using length @code{Long.MAX_VALUE} which means until the end of the file. Parameters:
|
sendFile | shared default HttpServerResponse sendFile(String filename, Integer offset, Anything(Throwable?) resultHandler) Like sendFile but providing a handler which will be notified once the file has been completely written to the wire. Parameters:
|
sendFile | shared default HttpServerResponse sendFile(String filename, Integer offset, Integer length) Ask the OS to stream a file as specified by The actual serve is asynchronous and may not complete until some time after this method has returned. Parameters:
|
sendFile | shared default HttpServerResponse sendFile(String filename, Integer offset, Integer length, Anything(Throwable?) resultHandler) Like sendFile but providing a handler which will be notified once the file has been completely written to the wire. Parameters:
|
setChunked | shared default HttpServerResponse setChunked(Boolean chunked) If
If chunked encoding is used the HTTP header
If An HTTP chunked response is typically used when you do not know the total size of the request body up front. |
setStatusCode | shared default HttpServerResponse setStatusCode(Integer statusCode) Set the status code. If the status message hasn't been explicitly set, a default status message corresponding to the code will be looked-up and used. |
setStatusMessage | shared default HttpServerResponse setStatusMessage(String statusMessage) Set the status message |
setWriteQueueMaxSize | shared actual default HttpServerResponse setWriteQueueMaxSize(Integer maxSize) Set the maximum size of the write queue to Refines WriteStream.setWriteQueueMaxSize |
streamId | shared default Integer streamId() |
trailers | shared default MultiMap trailers() |
write | shared actual default HttpServerResponse write(Buffer data) |
write | shared default HttpServerResponse write(String chunk) Write a Parameters:
|
write | shared default HttpServerResponse write(String chunk, String enc) Write a Parameters:
|
writeContinue | shared default HttpServerResponse writeContinue() Used to write an interim 100 Continue response to signify that the client should send the rest of the request. Must only be used if the request contains an “Expect:100-Continue” header |
writeCustomFrame | shared default HttpServerResponse writeCustomFrame(HttpFrame frame) Like writeCustomFrame but with an HttpFrame. Parameters:
|
writeCustomFrame | shared default HttpServerResponse writeCustomFrame(Integer type, Integer flags, Buffer payload) Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol. The frame is sent immediatly and is not subject to flow control. Parameters:
|
writeQueueFull | shared actual default Boolean writeQueueFull() This will return Refines WriteStream.writeQueueFull |
Inherited Methods |
Methods inherited from: Object equals |
Methods inherited from: StreamBase |
Methods inherited from: WriteStream<T> |