wilton/httpClient
HTTP client.
More...
Functions | |
Undefined | closeQueue (Function|Undefined callback) |
Close requests queue for this thread. | |
Object | enqueueRequest (String url, Object options, Function|Undefined callback) |
Submit request to queue. | |
Undefined | initQueue (Object options, Function|Undefined callback) |
Initialize requests queue for this thread. | |
Array | pollQueue (Object options, Function|Undefined callback) |
Poll requests queue. | |
Object | sendFile (String url, Object options, Function|Undefined callback) |
Send specified file to server. | |
Object | sendFileByParts (String url, Object options, Function|Undefined callback) |
Send specified file to server by parts. | |
Object | sendRequest (String url, Object options, Function|Undefined callback) |
Send HTTP request to server. |
This module allows to send HTTP requests.
By default HTTP connections are cached into the single process-wide connection pool and can be reused from different threads.
This module supports HTTPS and request with X.509
client certificates.
Usage example:
Undefined httpClient::closeQueue | ( | Function|Undefined | callback | ) |
Closes requests queue and de-allocates system resources used. If not called - resources cleanup will be done automatically on shutdown.
Must be called from the same thread queue was initialized from.
callback | Function|Undefined callback to receive result or error |
Undefined
Object httpClient::enqueueRequest | ( | String | url, |
Object | options, | ||
Function|Undefined | callback | ||
) |
Submits specified request to the queue for execution. initQueue
must be called in the same thread before using this function.
url | String URL of the HTTP server |
options | Object configuration object, see supported options in sendRequest() function doc |
callback | Function|Undefined callback to receive result or error |
Object
enqueued request, requestId
is unique for the given queue Undefined httpClient::initQueue | ( | Object | options, |
Function|Undefined | callback | ||
) |
Initializes HTTP requests queue allowing to use enqueueRequest
and pollQueue
operations. Queue is bound to the thread it is initialized from and can be used only from it.
closeQueue
must be called from the same thread to de-allocate resources, alternatively resources cleanup will be done automatically on shutdown.
options | Object configuration object, see possible options below. |
callback | Function|Undefined callback to receive result or error |
Undefined
options
Number
max allowed number of milliseconds to wait for activity on one of running requests, default value: 100
Number
max number of connections to a single host, default value: 0 (unlimited)
Number
max number of simultaneously open connections, default value: 0 (unlimited)
Number
max number of simultaneously open connections may be kept in connection cache after completed use, default value: 4 times the number of simultaneously run requests Array httpClient::pollQueue | ( | Object | options, |
Function|Undefined | callback | ||
) |
Polls requests queue allowing enqued requests to perform the work. initQueue
must be called in the same thread before using this function.
options | Object currently not supported |
callback | Function|Undefined callback to receive result or error |
Array
list of the responses for requests, that finished execution, see details on the structure of each response in sendRequest()
function Object httpClient::sendFile | ( | String | url, |
Object | options, | ||
Function|Undefined | callback | ||
) |
Sends specified file to server using POST
request method by default.
Specified file is read in streaming mode without loading the whole file into memory.
url | String URL of the HTTP server |
options | Object configuration object, see file-specific options below; see other supported options in sendRequest() function doc |
callback | Function|Undefined callback to receive result or error |
Object
response object, see details in sendRequest()
functionOptions
String
path to file to sendBoolean|Undefined
whether to delete the file after sending, default value: false
Object httpClient::sendFileByParts | ( | String | url, |
Object | options, | ||
Function|Undefined | callback | ||
) |
Sends specified file to server using POST
request method by default. File splitted into parts.
Specified file is read in streaming mode without loading the whole file into memory.
url | String URL of the HTTP server |
options | Object configuration object, see details in sendRequest() function and also sendOptions Object configuration object, see possible options below. |
callback | Function|Undefined callback to receive result or error |
Object
response object, see details below0 Array
Array of response objects, see details in
sendRequest()function | strings with error messages
1 Array
... 2 Array
... ...
sendOptions
String
name of file that will be created on server to store sended dataconsumer threads wakeup timeout, in milliseconds, default value:
10000, equal to 10 seconds.
__maxChunkSize__
Numbermaximum size of sent chunk
__fileSize__
Number|Undefinedthe size of the file being sent
__filePath__
String|Undefinedpath to file that will be sent.
__url__
String|Undefined` URL of the HTTP server Object httpClient::sendRequest | ( | String | url, |
Object | options, | ||
Function|Undefined | callback | ||
) |
Sends HTTP request to server, received response can be stored in-memory or in the specified file (in this case response will be written into the file in streaming mode).
url | String URL of the HTTP server |
options | Object configuration object, see possible options below |
callback | Function|Undefined callback to receive result or error |
Object
response object with the following fields:Boolean
true
if the connection to server was successful, false
otherwiseString
data decoded as a String
with invalid UTF-8
code sequences replaced with 0xFFFD
Function
parses the contents of data
field as a JSON, resulting JSON object is cached for this response instance - the same object is returned for the following json()
invocationsObject
response headers in "Header-Name": "value"
formatString
final URL (after possible redirection) that was usedNumber
HTTP response status codeNumber
time that request have taken, in secondsNumber
time spent in DNS lookup, in secondsNumber
time spent establishing the connection, in secondsNumber
time until the SSL handshake is completed, in secondsNumber
time until the file transfer start, in secondsNumber
time until the first byte is received, in secondsNumber
time for all redirection steps, in secondsNumber
number of redirectsNumber
download speed, in bytes per secondNumber
upload speed, in bytes per secondNumber
size of response headers, in bytesNumber
size of sent request, in bytesNumber
result of the certificate verificationNumber
error code returned by OSNumber
number of created connectionsString
IP address of last connectionNumbrer
TCP port of last connectionOptions
String|Object|Undefined
data to send in request body, specified object will be converted to JSONObject|Undefined
request metadataObject|Undefined
request headers in "Header-Name": "value"
formatString|Undefined
HTTP method to use for this request, default value is GET
, if request data
is not specified, POST
otherwiseBoolean|Undefined
whether to throw an Error
on connection fail, default value: true
Boolean|Undefined
whether to throw an Error
, if response status code >=400
is returned, default value: true
Number|Undefined
maximum number of response headers to receive, subsequent headers will be ignored, default value: 128
Number|Undefined
consumer threads wakeup timeout, in milliseconds, default value: 100
String|Undefined
path to file to send, only supported with enqueueRequest
String|Undefined
path to file where to write the response bodyBoolean|Undefined
whether to use HTTP 1.0
protocol closing the connection after the request, default value: false
Boolean|Undefined
whether to swith off the progress meter, default value true
Boolean|Undefined
whether to disable OS-signals handling, default value: true
Boolean|Undefined
whether to close the connection and throw an Error
on response code >=400
,default value: false
Boolean|Undefined
whether to not handle "dot sequences" in request URL, default value: true
Boolean|Undefined
whether to set the TCP_NODELAY
connection option, default value: false
Boolean|Undefined
whether to use TCK keep-alive probing, default value: false
Number|Undefined
TCP keep-alive idle time wait, in seconds, default value: 300
Number|Undefined
TCP keep-alive interval, in seconds, default value: 300
Number|Undefined
timeout for the connect phase, in milliseconds, default value: 10000
Number|Undefined
maximum time the request is allowed to take, in milliseconds, default value: 15000
Number|Undefined
preferred receive buffer size, in bytes, default value: 16384
String|Undefined
enables automatic decompression of HTTP downloads, default value: gzip
Boolean|Undefined
whether to follow HTTP 3xx
redirects, default value: true
Number|Undefined
maximum number of redirects allowed, default value: 32
String|Undefined
user-agent string to send, default value: empty stringNumber|Undefined
rate limit data upload speed, in bytes per second, default value: 0
(disabled)Number|Undefined
rate limit data download speed, in bytes per second, default value: 0
(disabled)String|Undefined
path to SSL client certificate fileString|Undefined
type of the client SSL certificateString|Undefined
path to private keyfile for TLS and SSL client certificateString|Undefined
type of the private key fileString|Undefined
passphrase to private keyBoolean|Undefined
whether to require TLS connection rejectin older SSL algorithms, default value: false
Boolean|Undefined
whether to verify the certificate's name against host, default value: false
Boolean|Undefined
whether to verify the peer's SSL certificate, default value: false
Boolean|Undefined
whether to verify the peer certificate's status, default value: false
String|Undefined
path to Certificate Authority (CA) bundleString|Undefined
path to CRL fileString|Undefined
ciphers to use for TLSBoolean|Undefined
whether to encode response data into hexadecimal format