Represents a client-side HTTP request.

Instances are created by an 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 end methods should be called.

Nothing is actually sent until the request has been internally assigned an HTTP connection.

The 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 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 WriteStream so it can be used with Pump to pump data with flow control.

An example of using this class is as follows:

no subtypes hierarchy

HttpClientRequest(HttpClientRequest unknown)
Inherited Attributes
Attributes inherited from: Object
hash, string
continueHandlershared default HttpClientRequest continueHandler(Anything()? handler)

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

You can then continue to write data to the request body and later end it. This is normally used in conjunction with the sendHead method to force the request header to be written before the request has ended.

drainHandlershared actual default HttpClientRequest 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 has been reduced to maxSize / 2. See Pump for an example of this being used.

endshared actual default void end()

Ends the request. If no data has been written to the request body, and sendHead has not been called then the actual request won't get written until this method gets called.

Once the request has ended, it cannot be used any more,

endshared actual default void end(Buffer chunk)

Same as 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

endshared default void end(String chunk)

Same as end but writes a String in UTF-8 encoding

endshared default void end(String chunk, String enc)

Same as end but writes a String with the specified encoding

endHandlershared actual default HttpClientRequest endHandler(Anything()? endHandler)

Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.

exceptionHandlershared actual default HttpClientRequest exceptionHandler(Anything(Throwable)? handler)

Set an exception handler.

handlershared actual default HttpClientRequest handler(Anything(HttpClientResponse)? handler)

Set a data handler. As data is read, the handler will be called with the data.

headersshared default MultiMap headers()

@return The HTTP headers

isChunkedshared default Boolean isChunked()

@return Is the request chunked?

methodshared default HttpMethod method()

The HTTP method for the request.

pauseshared actual default HttpClientRequest pause()

Pause the ReadSupport. While it's paused, no data will be sent to the dataHandler

putHeadershared default HttpClientRequest putHeader(String name, String value)

Put an HTTP header

  • name

    The header name

  • value

    The header value

resumeshared actual default HttpClientRequest resume()

Resume reading. If the ReadSupport has been paused, reading will recommence on it.

sendHeadshared default HttpClientRequest sendHead()

Forces the head of the request to be written before end is called on the request or any data is written to it.

This is normally used to implement HTTP 100-continue handling, see for more information.

setChunkedshared default HttpClientRequest setChunked(Boolean chunked)

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

  • chunked

    true if chunked encoding

setTimeoutshared default HttpClientRequest setTimeout(Integer timeoutMs)

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

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

  • timeoutMs

    The quantity of time in milliseconds.

setWriteQueueMaxSizeshared actual default HttpClientRequest setWriteQueueMaxSize(Integer maxSize)

Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize bytes in the write queue. This is used as an indicator by classes such as Pump to provide flow control.

urishared default String uri()

@return The URI of the request.

writeshared actual default HttpClientRequest write(Buffer data)

@throws java.lang.IllegalStateException when no response handler is set

writeshared default HttpClientRequest write(String chunk)

Write a String to the request body, encoded as UTF-8.

writeshared default HttpClientRequest write(String chunk, String enc)

Write a String to the request body, encoded using the encoding enc.

writeQueueFullshared actual default Boolean writeQueueFull()

This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize

Inherited Methods
Methods inherited from: Object
Methods inherited from: ReadStream<T>
Methods inherited from: StreamBase
Methods inherited from: WriteStream<T>