HttpClientRequest

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

Methods

__construct

__construct() 

absoluteURI

absoluteURI() : string

Response

string

the absolute URI corresponding to the the HTTP request

connection

connection() : \io\vertx\jphp\core\http\HttpConnection

Response

\io\vertx\jphp\core\http\HttpConnection

the {@link HttpConnection} associated with this request

Set a connection handler called when an HTTP connection has been established.

connectionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

If you send an HTTP request with the header <code>Expect</code> set to the value <code>100-continue</code> and the server responds with an interim HTTP response with a status code of <code>100</code> and a continue handler has been set using this method, then the <code>handler</code> will be called.

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.

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

drainHandler

drainHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

Ends the request. If no data has been written to the request body, and @see \io\vertx\jphp\core\http\HttpClientRequest::sendHead has not been called then the actual request won't get written until this method gets called.

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)

Arguments

$arg0

Buffer | string

$arg1

string

endHandler

endHandler( $arg0) : $this
deprecated

Arguments

$arg0

callable

Response

$this

exceptionHandler

exceptionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

fetch

fetch( $arg0) : $this
deprecated

Arguments

$arg0

integer

Response

$this

getHost

getHost() : string

Response

string

the request host. For HTTP/2 it returns the {@literal :authority} pseudo header otherwise it returns the {@literal Host} header

getRawMethod

getRawMethod() : string

Response

string

the raw value of the method this request sends

getStreamPriority

getStreamPriority() : \io\vertx\jphp\core\http\StreamPriority

Response

\io\vertx\jphp\core\http\StreamPriority

the priority of the associated HTTP/2 stream for HTTP/2 otherwise {@code null}

handler

handler( $arg0) : $this
deprecated

Arguments

$arg0

callable

Response

$this

headers

headers() : \io\vertx\jphp\core\MultiMap

Response

\io\vertx\jphp\core\MultiMap

The HTTP headers

isChunked

isChunked() : boolean

Response

boolean

Is the request chunked?

The HTTP method for the request.

method() : string

Response

string

path

path() : string

Response

string

The path part of the uri. For example /somepath/somemorepath/someresource.foo

pause

pause() : $this
deprecated

Response

$this

Set a push handler for this request.<p/>

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:

  • @see \io\vertx\jphp\core\http\HttpClientRequest::method
  • @see \io\vertx\jphp\core\http\HttpClientRequest::uri
  • @see \io\vertx\jphp\core\http\HttpClientRequest::headers
  • @see \io\vertx\jphp\core\http\HttpClientRequest::getHost

In addition the handler should call the @see \io\vertx\jphp\core\http\HttpClientRequest::handler method to set an handler to process the response.

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Put an HTTP header

putHeader( $arg0,  $arg1) : $this

Arguments

$arg0

string

$arg1

string

Response

$this

a reference to this, so the API can be used fluently

query

query() : string

Response

string

the query part of the uri. For example someparam=32&someotherparam=x

Reset this stream with the error code <code>0</code>.

reset( $arg0 = null) : boolean

reset()

Reset this request:

  • for HTTP/2, this performs send an HTTP/2 reset frame with the specified error code
  • for HTTP/1.x, this closes the connection when the current request is inflight

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)

Arguments

$arg0

integer

Response

boolean

resume

resume() : $this
deprecated

Response

$this

Forces the head of the request to be written before @see \io\vertx\jphp\core\http\HttpClientRequest::end is called on the request or any data is written to it.

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)

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

If chunked is true then the request will be set into HTTP chunked mode

setChunked( $arg0) : $this

Arguments

$arg0

boolean

Response

$this

a reference to this, so the API can be used fluently

setFollowRedirects

setFollowRedirects( $arg0) : $this

Arguments

$arg0

boolean

Response

$this

Set the request host.<p/>

setHost( $arg0) : $this

For HTTP/2 it sets the pseudo header otherwise it sets the header

Arguments

$arg0

string

Response

$this

Set the value the method to send when the method is used.

setRawMethod( $arg0) : $this

Arguments

$arg0

string

Response

$this

a reference to this, so the API can be used fluently

Sets the priority of the associated stream.

setStreamPriority( $arg0) : $this

This is not implemented for HTTP/1.x.

Arguments

$arg0

StreamPriority | array

Response

$this

Set's the amount of time after which if the request does not return any data within the timeout period an {@link java.util.concurrent.TimeoutException} will be passed to the exception handler (if provided) and the request will be closed.

setTimeout( $arg0) : $this

Calling this method more than once has the effect of canceling any existing timeout and starting the timeout from scratch.

Arguments

$arg0

integer

Response

$this

a reference to this, so the API can be used fluently

setWriteQueueMaxSize

setWriteQueueMaxSize( $arg0) : $this

Arguments

$arg0

integer

Response

$this

streamId

streamId() : integer

Response

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

uri

uri() : string

Response

string

The URI of the request.

param $data [Buffer] <b> write($data) </b>

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)

Arguments

$arg0

Buffer | string

$arg1

string

Response

$this

Like @see \io\vertx\jphp\core\http\HttpClientRequest::writeCustomFrame but with an @see \io\vertx\jphp\core\http\HttpFrame.

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)

Arguments

$arg0

integer | HttpFrame

$arg1

integer

$arg2

Buffer

Response

$this

This will return <code>true</code> if there are more bytes in the write queue than the value set using @see \io\vertx\jphp\core\http\HttpClientRequest::setWriteQueueMaxSize

writeQueueFull() : boolean

Response

boolean

true if write queue is full