Represents a client-side HTTP request.
Instances are created by an @see \io\vertx\jphp\core\http\HttpClient instance, via one of the methods corresponding to the specific HTTP methods, or the generic request methods. On creation the request will not have been written to the wire.
Once a request has been obtained, headers can be set on it, and data can be written to its body if required. Once you are ready to send the request, one of the @see \io\vertx\jphp\core\http\HttpClientRequest::end methods should be called.
Nothing is actually sent until the request has been internally assigned an HTTP connection.
The @see \io\vertx\jphp\core\http\HttpClient instance will return an instance of this class immediately, even if there are no HTTP connections available in the pool. Any requests sent before a connection is assigned will be queued internally and actually sent when an HTTP connection becomes available from the pool.
The headers of the request are queued for writing either when the @see \io\vertx\jphp\core\http\HttpClientRequest::end method is called, or, when the first part of the body is written, whichever occurs first.
This class supports both chunked and non-chunked HTTP.
It implements @see \io\vertx\jphp\core\streams\WriteStream so it can be used with
| see |
to pump data with flow control. An example of using this class is as follows:
|
|---|---|
| package |
Default |
__construct()
absoluteURI() : string
stringthe absolute URI corresponding to the the HTTP request
connection() : \io\vertx\jphp\core\http\HttpConnection
\io\vertx\jphp\core\http\HttpConnectionthe {@link HttpConnection} associated with this request
connectionHandler( $arg0) : $this
callable
$thisa reference to this, so the API can be used fluently
continueHandler( $arg0) : $this
You can then continue to write data to the request body and later end it. This is normally used in conjunction with the @see \io\vertx\jphp\core\http\HttpClientRequest::sendHead method to force the request header to be written before the request has ended.
callable
$thisa reference to this, so the API can be used fluently
drainHandler( $arg0) : $this
callable
$this
end( $arg0 = null, $arg1 = null) : void
Once the request has ended, it cannot be used any more,
end()
Same as @see \io\vertx\jphp\core\http\HttpClientRequest::end but writes a String in UTF-8 encoding
param $chunk [string]
end($chunk)
Same as @see \io\vertx\jphp\core\http\HttpClientRequest::end but writes some data to the request body before ending. If the request is not chunked and
no other data has been written then the Content-Length header will be automatically set
param $chunk [Buffer]
end($chunk)
Same as @see \io\vertx\jphp\core\http\HttpClientRequest::end but writes a String with the specified encoding
param $chunk [string]
param $enc [string]
end($chunk, $enc)
Buffer | string
string
endHandler( $arg0) : $this
| deprecated |
|---|
callable
$this
exceptionHandler( $arg0) : $this
callable
$this
fetch( $arg0) : $this
| deprecated |
|---|
integer
$this
getHost() : string
stringthe request host. For HTTP/2 it returns the {@literal :authority} pseudo header otherwise it returns the {@literal Host} header
getRawMethod() : string
stringthe raw value of the method this request sends
getStreamPriority() : \io\vertx\jphp\core\http\StreamPriority
\io\vertx\jphp\core\http\StreamPrioritythe priority of the associated HTTP/2 stream for HTTP/2 otherwise {@code null}
handler( $arg0) : $this
| deprecated |
|---|
callable
$this
headers() : \io\vertx\jphp\core\MultiMap
isChunked() : boolean
booleanIs the request chunked?
method() : string
string
path() : string
stringThe path part of the uri. For example /somepath/somemorepath/someresource.foo
pause() : $this
| deprecated | |
|---|---|
$this
pushHandler( $arg0) : $this
The handler is called when the client receives a push promise from the server. The handler can be called multiple times, for each push promise.
The handler is called with a read-only @see \io\vertx\jphp\core\http\HttpClientRequest, the following methods can be called:
In addition the handler should call the @see \io\vertx\jphp\core\http\HttpClientRequest::handler method to set an handler to process the response.
callable
$thisa reference to this, so the API can be used fluently
putHeader( $arg0, $arg1) : $this
string
string
$thisa reference to this, so the API can be used fluently
query() : string
stringthe query part of the uri. For example someparam=32&someotherparam=x
reset( $arg0 = null) : boolean
reset()
Reset this request:
codeWhen the request has not yet been sent, the request will be aborted and false is returned as indicator.
param $code [integer] the error code reset($code)
integer
boolean
resume() : $this
| deprecated | |
|---|---|
$this
sendHead( $arg0 = null) : $this
This is normally used to implement HTTP 100-continue handling, see for more information. sendHead() Like @see \io\vertx\jphp\core\http\HttpClientRequest::sendHead but with an handler after headers have been sent. The handler will be called with the \io.vertx.core.http.HttpVersion if it can be determined or null otherwise.
param $completionHandler [callable] sendHead($completionHandler)
callable
$thisa reference to this, so the API can be used fluently
setChunked( $arg0) : $this
boolean
$thisa reference to this, so the API can be used fluently
setFollowRedirects( $arg0) : $this
boolean
$this
setHost( $arg0) : $this
For HTTP/2 it sets the pseudo header otherwise it sets the header
string
$this
setRawMethod( $arg0) : $this
string
$thisa reference to this, so the API can be used fluently
setStreamPriority( $arg0) : $this
This is not implemented for HTTP/1.x.
StreamPriority | array
$this
setTimeout( $arg0) : $this
Calling this method more than once has the effect of canceling any existing timeout and starting the timeout from scratch.
integer
$thisa reference to this, so the API can be used fluently
setWriteQueueMaxSize( $arg0) : $this
integer
$this
streamId() : integer
integerthe id of the stream of this response, {@literal -1} when it is not yet determined, i.e the request has not been yet sent or it is not supported HTTP/1.x
uri() : string
stringThe URI of the request.
write( $arg0, $arg1 = null) : $this
Write a \java.lang.String to the request body, encoded as UTF-8.
param $chunk [string] write($chunk)
Write a \java.lang.String to the request body, encoded using the encoding enc.
param $chunk [string] param $enc [string] write($chunk, $enc)
Buffer | string
string
$this
writeCustomFrame( $arg0, $arg1 = null, $arg2 = null) : $this
param $frame [HttpFrame] the frame to write writeCustomFrame($frame)
Write an HTTP/2 frame to the request, allowing to extend the HTTP/2 protocol.
The frame is sent immediatly and is not subject to flow control.
This method must be called after the request headers have been sent and only for the protocol HTTP/2. The @see \io\vertx\jphp\core\http\HttpClientRequest::sendHead should be used for this purpose.
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
booleantrue if write queue is full