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:
Anything
no subtypes hierarchy
Initializer |
HttpClientRequest(HttpClientRequest unknown) |
Inherited Attributes |
Attributes inherited from: Object hash , string |
Methods | |
absoluteURI | shared default String absoluteURI() |
connection | shared default HttpConnection connection() |
connectionHandler | shared default HttpClientRequest connectionHandler(Anything(HttpConnection)? handler) Set a connection handler called when an HTTP connection has been established. Parameters:
|
continueHandler | shared default HttpClientRequest continueHandler(Anything()? handler) If you send an HTTP request with the header 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. |
drainHandler | shared 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 is ready to accept buffers again. See Pump for an example of this being used. The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced tomaxSize / 2 .
Refines WriteStream.drainHandler |
end | shared 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, Refines WriteStream.end |
end | shared 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 |
end | shared default void end(String chunk) Same as end but writes a String in UTF-8 encoding |
end | shared default void end(String chunk, String enc) Same as end but writes a String with the specified encoding |
endHandler | shared 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. Refines ReadStream.endHandler |
exceptionHandler | shared actual default HttpClientRequest exceptionHandler(Anything(Throwable)? handler) Set an exception handler. Refines StreamBase.exceptionHandler |
getHost | shared default String getHost() |
getRawMethod | shared default String getRawMethod() |
handler | shared actual default HttpClientRequest handler(Anything(HttpClientResponse)? handler) Set a data handler. As data is read, the handler will be called with the data. Refines ReadStream.handler |
headers | shared default MultiMap headers() |
isChunked | shared default Boolean isChunked() |
method | shared default HttpMethod method() The HTTP method for the request. |
path | shared default String path() |
pause | shared actual default HttpClientRequest pause() Pause the Refines ReadStream.pause |
pushHandler | shared default HttpClientRequest pushHandler(Anything(HttpClientRequest) handler) Set a push handler for this request. 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 HttpClientRequest, the following methods can be called:
In addition the handler should call the handler method to set an handler to process the response. Parameters:
|
putHeader | shared default HttpClientRequest putHeader(String name, String value) Put an HTTP header Parameters:
|
query | shared default String query() |
reset | shared default Boolean reset() Reset this stream with the error code |
reset | shared default Boolean reset(Integer code) Reset this request:
Parameters:
|
resume | shared actual default HttpClientRequest resume() Resume reading. If the Refines ReadStream.resume |
sendHead | shared 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. |
sendHead | shared default HttpClientRequest sendHead(Anything(HttpVersion) completionHandler) Like sendHead but with an handler after headers have been sent. The handler will be called with the HttpVersion if it can be determined or null otherwise. |
setChunked | shared default HttpClientRequest setChunked(Boolean chunked) If chunked is true then the request will be set into HTTP chunked mode Parameters:
|
setFollowRedirects | shared default HttpClientRequest setFollowRedirects(Boolean followRedirects) |
setHost | shared default HttpClientRequest setHost(String host) Set the request host. For HTTP/2 it sets the pseudo header otherwise it sets the header |
setRawMethod | shared default HttpClientRequest setRawMethod(String method) Set the value the method to send when the method is used. Parameters:
|
setTimeout | shared 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
Calling this method more than once has the effect of canceling any existing timeout and starting the timeout from scratch. Parameters:
|
setWriteQueueMaxSize | shared actual default HttpClientRequest setWriteQueueMaxSize(Integer maxSize) Set the maximum size of the write queue to Refines WriteStream.setWriteQueueMaxSize |
streamId | shared default Integer streamId() |
uri | shared default String uri() |
write | shared actual default HttpClientRequest write(Buffer data) |
write | shared default HttpClientRequest write(String chunk) Write a |
write | shared default HttpClientRequest write(String chunk, String enc) Write a |
writeCustomFrame | shared default HttpClientRequest writeCustomFrame(HttpFrame frame) Like writeCustomFrame but with an HttpFrame. Parameters:
|
writeCustomFrame | shared default HttpClientRequest writeCustomFrame(Integer type, Integer flags, Buffer payload) 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 sendHead should be used for this purpose. Parameters:
|
writeQueueFull | shared actual default Boolean writeQueueFull() This will return Refines WriteStream.writeQueueFull |
Inherited Methods |
Methods inherited from: Object equals |
Methods inherited from: ReadStream<T> |
Methods inherited from: StreamBase |
Methods inherited from: WriteStream<T> |