new HttpClientRequest()
Represents a client-side HTTP request. Instances are created by an
module:vertx/http.HttpClient
instance, via one of the methods
corresponding to the specific HTTP methods, or the generic module:vertx/http.HttpClient#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
module:vertx/http.HttpClientRequest#end
method should be called.
The headers of the request are actually sent either when the
module:vertx/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 mixes in module:vertx/streams~WriteStream
so it can be used with
module:vertx/pump~Pump
to pump data with flow control.
An example of using this class is as follows:
Parameters:
Name | Type | Description |
---|---|---|
org.vertx.java.core.http.HttpClientRequest |
the underlying Java proxy |
- Source:
Example
var console = require('vertx/console');
var req = httpClient.post("/some-url", function(response) {
console.log("Got response: " + response.statusCode);
}
});
req.headers().add("Content-Length", 5);
req.end(new Buffer('hello');
Extends
Methods
-
chunked(chunked) → {boolean|module:vertx/http.HttpClientRequest}
-
Sets or gets whether the request should used HTTP chunked encoding or not.
Parameters:
Name Type Argument Description chunked
boolean <optional>
If val is true, this request will use HTTP chunked encoding, and each call to write to the body will correspond to a new HTTP chunk sent on the wire. If chunked encoding is used the HTTP header 'Transfer-Encoding' with a value of 'Chunked' will be automatically inserted in the request. If chunked
is not provided, returns the current value.- Source:
Returns:
- Type
- boolean | module:vertx/http.HttpClientRequest
-
continueHandler(handler) → {module:vertx/http.HttpClientRequest}
-
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 send_head method to force the request header to be written before the request has ended.
Parameters:
Name Type Description handler
Handler The handler - Source:
Returns:
-
drainHandler(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
module:vertx/pump~Pump
for an example of this being used.Parameters:
Name Type Description handler
Handler the handler to call when the stream has been drained - Inherited From:
- Source:
-
end(chunk, encoding)
-
Ends the request. If no data has been written to the request body, and send_head 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, and if keep alive is true the underlying connection will be returned to the HttpClient pool so it can be assigned to another request.
Parameters:
Name Type Argument Description chunk
string <optional>
The data to write encoding
string <optional>
The charset to use if data is written - Source:
-
exceptionHandler(handler)
-
Set an exception handler on the stream
Parameters:
Name Type Description handler
Handler the handler to call when an exception occurs - Inherited From:
- Source:
-
headers() → {module:vertx/multi_map~MultiMap}
-
Returns the headers for the requests
- Source:
Returns:
The headers -
putHeader(name, value) → {module:vertx/http.HttpClientRequest}
-
Put a header on the request
Parameters:
Name Type Description name
string The header name value
string The header value - Source:
Returns:
-
sendHead() → {module:vertx/http.HttpClientRequest}
-
Forces the head of the request to be written before end is called on the request. This is normally used to implement HTTP 100-continue handling.
- Source:
- See:
-
- module:vertx/http.HttpClientRequest#continue_handler
Returns:
-
timeout(timeout) → {module:vertx/http.HttpClientRequest}
-
Set's the amount of time after which if a response is not received an exception 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.
Parameters:
Name Type Description timeout
number The amount of time in milliseconds to wait before timing out - Source:
Returns:
-
write(chunk, encoding) → {module:vertx/http.HttpClientRequest}
-
Write to the request body
Parameters:
Name Type Argument Description chunk
string the data to write encoding
string <optional>
the data encoding (default is UTF-8) - Source:
Returns:
-
writeQueueFull()
-
This will return
true
if there are more bytes in the write queue than the value set usingwriteQueueMaxSize
- Inherited From:
- Source:
-
writeQueueMaxSize(size)
-
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 thanmaxSize
bytes in the write queue. This is used as an indicator by classes such asPump
to provide flow control.Parameters:
Name Type Description size
number the size of the write queue - Inherited From:
- Source: