Represents a server-side HTTP response.
An instance of this is created and associated to every instance of
see |
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 @see \io\vertx\jphp\core\streams\WriteStream so it can be used with |
---|---|
see |
to pump data with flow control. |
package |
Default |
__construct()
bodyEndHandler( $arg0) : $this
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.
callable
$this
a reference to this, so the API can be used fluently
bytesWritten() : integer
integer
the total number of bytes written for the body of the response.
close() : void
closed() : boolean
boolean
has the underlying TCP connection corresponding to the request already been closed?
closeHandler( $arg0) : $this
For HTTP/1.x it is called when the connection is closed before end()
is called, therefore it is not
guaranteed to be called.
For HTTP/2 it is called when the related stream is closed, and therefore it will be always be called.
callable
$this
a reference to this, so the API can be used fluently
drainHandler( $arg0) : $this
callable
$this
end( $arg0 = null, $arg1 = null) : void
Once the response has ended, it cannot be used any more. end() Same as @see \io\vertx\jphp\core\http\HttpServerResponse::end but writes a String in UTF-8 encoding before ending the response. param $chunk [string] the string to write before ending the response end($chunk) Same as @see \io\vertx\jphp\core\http\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. param $chunk [Buffer] the buffer to write before ending the response end($chunk) Same as @see \io\vertx\jphp\core\http\HttpServerResponse::end but writes a String with the specified encoding before ending the response. param $chunk [string] the string to write before ending the response param $enc [string] the encoding to use end($chunk, $enc)
Buffer | string
string
ended() : boolean
boolean
has the response already ended?
endHandler( $arg0) : $this
callable
$this
a reference to this, so the API can be used fluently
exceptionHandler( $arg0) : $this
callable
$this
getStatusCode() : integer
integer
the HTTP status code of the response. The default is {@code 200} representing {@code OK}.
getStatusMessage() : string
string
the HTTP status message of the response. If this is not specified a default value will be used depending on what {@link #setStatusCode} has been set to.
headers() : \io\vertx\jphp\core\MultiMap
headersEndHandler( $arg0) : $this
callable
$this
a reference to this, so the API can be used fluently
headWritten() : boolean
boolean
have the headers for the response already been written?
isChunked() : boolean
boolean
is the response chunked?
push( $arg0, $arg1, $arg2, $arg3 = null, $arg4 = null) : $this
param $method [string] param $path [string] param $handler [callable] push($method, $path, $handler)
Like @see \io\vertx\jphp\core\http\HttpServerResponse::push with no headers.
param $method [string] param $host [string] param $path [string] param $handler [callable] push($method, $host, $path, $handler)
Like @see \io\vertx\jphp\core\http\HttpServerResponse::push with the host copied from the current request.
param $method [string] param $path [string] param $headers [MultiMap] param $handler [callable] push($method, $path, $headers, $handler)
Push a response to the client.
The handler
will be notified with a success when the push can be sent and with
a failure when the client has disabled push or reset the push before it has been sent.
The handler
may be queued if the client has reduced the maximum number of streams the server can push
concurrently.
Push can be sent only for peer initiated streams and if the response is not ended.
param $method [string] the method of the promised request param $host [string] the host of the promised request param $path [string] the path of the promised request param $headers [MultiMap] the headers of the promised request param $handler [callable] the handler notified when the response can be written push($method, $host, $path, $headers, $handler)
string
string
MultiMap | callable | string
MultiMap | callable
callable
$this
putHeader( $arg0, $arg1) : $this
string
string
$this
a reference to this, so the API can be used fluently
putTrailer( $arg0, $arg1) : $this
string
string
$this
a reference to this, so the API can be used fluently
reset( $arg0 = null) : void
reset()
Reset this HTTP/2 stream with the error code
.
param $code [integer] the error code reset($code)
integer
sendFile( $arg0, $arg1 = null, $arg2 = null, $arg3 = null) : $this
param $filename [string] path to the file to serve sendFile($filename)
Same as @see \io\vertx\jphp\core\http\HttpServerResponse::sendFile using length @code{Long.MAX_VALUE} which means until the end of the file.
param $filename [string] path to the file to serve param $offset [integer] offset to start serving from sendFile($filename, $offset)
Like @see \io\vertx\jphp\core\http\HttpServerResponse::sendFile but providing a handler which will be notified once the file has been completely written to the wire.
param $filename [string] path to the file to serve param $resultHandler [callable] handler that will be called on completion sendFile($filename, $resultHandler)
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.
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.
param $filename [string] path to the file to serve param $offset [integer] offset to start serving from param $length [integer] the number of bytes to send sendFile($filename, $offset, $length)
Like @see \io\vertx\jphp\core\http\HttpServerResponse::sendFile but providing a handler which will be notified once the file has been completely written to the wire.
param $filename [string] path to the file to serve param $offset [integer] the offset to serve from param $resultHandler [callable] handler that will be called on completion sendFile($filename, $offset, $resultHandler)
Like @see \io\vertx\jphp\core\http\HttpServerResponse::sendFile but providing a handler which will be notified once the file has been completely written to the wire.
param $filename [string] path to the file to serve param $offset [integer] the offset to serve from param $length [integer] the length to serve to param $resultHandler [callable] handler that will be called on completion sendFile($filename, $offset, $length, $resultHandler)
string
callable | integer
callable | integer
callable
$this
a reference to this, so the API can be used fluently
setChunked( $arg0) : $this
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.
boolean
$this
a reference to this, so the API can be used fluently
setStatusCode( $arg0) : $this
integer
$this
a reference to this, so the API can be used fluently
setStatusMessage( $arg0) : $this
string
$this
a reference to this, so the API can be used fluently
setStreamPriority( $arg0) : $this
StreamPriority | array
$this
setWriteQueueMaxSize( $arg0) : $this
integer
$this
streamId() : integer
integer
the id of the stream of this response, {@literal -1} for HTTP/1.x
trailers() : \io\vertx\jphp\core\MultiMap
write( $arg0, $arg1 = null) : $this
Write a \java.lang.String to the response body, encoded in UTF-8.
param $chunk [string] the string to write write($chunk)
Write a \java.lang.String to the response body, encoded using the encoding enc
.
param $chunk [string] the string to write param $enc [string] the encoding to use write($chunk, $enc)
Buffer | string
string
$this
writeContinue() : $this
Must only be used if the request contains an "Expect:100-Continue" header
$this
a reference to this, so the API can be used fluently
writeCustomFrame( $arg0, $arg1 = null, $arg2 = null) : $this
param $frame [HttpFrame] the frame to write writeCustomFrame($frame)
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.
param $type [integer] the 8-bit frame type param $flags [integer] the 8-bit frame flags param $payload [Buffer] the frame payload writeCustomFrame($type, $flags, $payload)
integer | HttpFrame
integer
Buffer
$this
writeQueueFull() : boolean
boolean
true if write queue is full