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
string
the absolute URI corresponding to the the HTTP request
cause() : \Exception
\Exception
the cause or null if the operation succeeded.
compose( $arg0) : \io\vertx\jphp\core\http\Future<U>
When this future (the one on which compose
is called) succeeds, the mapper
will be called with
the completed value and this mapper returns another future object. This returned future completion will complete
the future returned by this method call.
If the mapper
throws an exception, the returned future will be failed with this exception.
When this future fails, the failure will be propagated to the returned future and the mapper
will not be called.
callable
\io\vertx\jphp\core\http\Future
the composed future
connection() : \io\vertx\jphp\core\http\HttpConnection
\io\vertx\jphp\core\http\HttpConnection
the {@link HttpConnection} associated with this request
connectionHandler( $arg0) : $this
callable
$this
a 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
$this
a reference to this, so the API can be used fluently
drainHandler( $arg0) : $this
callable
$this
end( $arg0, $arg1 = null, $arg2 = null) : void
param $handler [callable] end($handler)
Same as @see \io\vertx\jphp\core\http\HttpClientRequest::end but with an handler
called when the operation completes
param $chunk [string] param $handler [callable] end($chunk, $handler)
Same as @see \io\vertx\jphp\core\http\HttpClientRequest::end but with an handler
called when the operation completes
param $chunk [Buffer] param $handler [callable] end($chunk, $handler)
Same as @see \io\vertx\jphp\core\http\HttpClientRequest::end but with an handler
called when the operation completes
param $chunk [string] param $enc [string] param $handler [callable] end($chunk, $enc, $handler)
Buffer | callable | string
callable | string
callable
exceptionHandler( $arg0) : $this
callable
$this
failed() : boolean
boolean
true if it failed or false otherwise
getHandler() : callable
callable
the handler for the result
getHost() : string
string
the request host. For HTTP/2 it returns the {@literal :authority} pseudo header otherwise it returns the {@literal Host} header
getRawMethod() : string
string
the raw value of the method this request sends
getStreamPriority() : array
array
the priority of the associated HTTP/2 stream for HTTP/2 otherwise {@code null}
headers() : \io\vertx\jphp\core\MultiMap
isChunked() : boolean
boolean
Is the request chunked?
isComplete() : boolean
boolean
true if completed, false if not
map( $arg0) : \io\vertx\jphp\core\http\Future<U>
When this future succeeds, the mapper
will be called with the completed value and this mapper
returns a value. This value will complete the future returned by this method call.
If the mapper
throws an exception, the returned future will be failed with this exception.
When this future fails, the failure will be propagated to the returned future and the mapper
will not be called.
param $mapper [callable] the mapper function map($mapper)
Map the result of a future to a specific value
.
When this future succeeds, this value
will complete the future returned by this method call.
When this future fails, the failure will be propagated to the returned future.
param $value [mixed] the value that eventually completes the mapped future map($value)
callable | mixed
\io\vertx\jphp\core\http\Future
the mapped future
mapEmpty() : \io\vertx\jphp\core\http\Future<V>
This is a conveniency for future.map((T) null)
or future.map((Void) null)
.
When this future succeeds, null
will complete the future returned by this method call.
When this future fails, the failure will be propagated to the returned future.
\io\vertx\jphp\core\http\Future
the mapped future
method() : string
string
otherwise( $arg0) : \io\vertx\jphp\core\http\Future<HttpClientResponse>
When this future fails, the mapper
will be called with the completed value and this mapper
returns a value. This value will complete the future returned by this method call.
If the mapper
throws an exception, the returned future will be failed with this exception.
When this future succeeds, the result will be propagated to the returned future and the mapper
will not be called.
param $mapper [callable] the mapper function otherwise($mapper)
Map the failure of a future to a specific value
.
When this future fails, this value
will complete the future returned by this method call.
When this future succeeds, the result will be propagated to the returned future.
param $value [HttpClientResponse] the value that eventually completes the mapped future otherwise($value)
callable | HttpClientResponse
\io\vertx\jphp\core\http\Future
the mapped future
otherwiseEmpty() : \io\vertx\jphp\core\http\Future<HttpClientResponse>
This is a convenience for future.otherwise((T) null)
.
When this future fails, the null
value will complete the future returned by this method call.
When this future succeeds, the result will be propagated to the returned future.
\io\vertx\jphp\core\http\Future
the mapped future
path() : string
string
The path part of the uri. For example /somepath/somemorepath/someresource.foo
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::setHandler method to set an handler to process the response.
callable
$this
a reference to this, so the API can be used fluently
putHeader( $arg0, $arg1) : $this
string
string
$this
a reference to this, so the API can be used fluently
query() : string
string
the query part of the uri. For example someparam=32&someotherparam=x
recover( $arg0) : \io\vertx\jphp\core\http\Future<HttpClientResponse>
If the mapper fails, then the returned future will be failed with this failure.
callable
\io\vertx\jphp\core\http\Future
A recovered future
reset( $arg0 = null) : boolean
reset()
Reset this request:
code
When 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
result() : \io\vertx\jphp\core\http\HttpClientResponse
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
$this
a reference to this, so the API can be used fluently
setChunked( $arg0) : $this
boolean
$this
a reference to this, so the API can be used fluently
setFollowRedirects( $arg0) : $this
boolean
$this
a reference to this, so the API can be used fluently
setHandler( $arg0) : $this
callable
$this
setHost( $arg0) : $this
For HTTP/2 it sets the pseudo header otherwise it sets the header
string
$this
setMaxRedirects( $arg0) : $this
integer
$this
a reference to this, so the API can be used fluently
setRawMethod( $arg0) : $this
string
$this
a reference to this, so the API can be used fluently
setStreamPriority( $arg0) : $this
This is not implemented for HTTP/1.x.
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
$this
a reference to this, so the API can be used fluently
setWriteQueueMaxSize( $arg0) : $this
integer
$this
streamId() : integer
integer
the 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
succeeded() : boolean
boolean
true if it succeded or false otherwise
uri() : string
string
The URI of the request.
write( $arg0, $arg1, $arg2 = null) : void
param $data [Buffer] param $handler [callable] write($data, $handler)
Same as @see \io\vertx\jphp\core\http\HttpClientRequest::write but with an handler
called when the operation completes
param $chunk [string] param $handler [callable] write($chunk, $handler)
Same as @see \io\vertx\jphp\core\http\HttpClientRequest::write but with an handler
called when the operation completes
param $chunk [string] param $enc [string] param $handler [callable] write($chunk, $enc, $handler)
Buffer | string
callable | string
callable
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
boolean
true if write queue is full