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 method. 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, the end() method 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 actually sent 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.

An example of using this class is as follows:

HttpClientRequest req = client.
  request(post, "/some-url").
  headers { "some-header"->"hello", "Content-Length"->"5" };
req.response.onComplete((HttpClientResponse resp) => print("Got response ``resp.status``"));

Instances of HttpClientRequest are not thread-safe.

By: Julien Viet

no subtypes hierarchy

HttpClientRequest(HttpClient delegate, String method, String uri)
chunkedshared actual Boolean chunked

Is the request chunked?

responseshared Promise<HttpClientResponse> response

The response promise is resolved when the http client response is available.

todo: consider provide an handler instead of having a Promise

streamshared actual WriteStream stream

The write stream of this request

Inherited Attributes
Attributes inherited from: Object
hash, string
endshared actual HttpClientRequest end(Chunk? chunk)

Ends the response. If no data has been written to the response body, the actual response won't get written until this method gets called. Once the response has ended, it cannot be used any more.

headersshared actual HttpClientRequest headers(Entries headers)

Set the response headers.

timeoutshared HttpClientRequest timeout(Integer t)

Set's the amount of time after which if a response is not received TimeoutException will be sent to the exception handler of this request. Calling this method more than once has the effect of canceling any existing timeout and starting the timeout from scratch.

  • t

    The quantity of time in milliseconds

writeshared actual HttpClientRequest write(Chunk chunk)

Write a chunk to the output body.

Inherited Methods
Methods inherited from: HttpOutput<O>
Methods inherited from: Object