HTTP Duplex Streams2 client. By default it behaves identically to Node’s Core http.request method.
Each additional feature must be enabled explicitly via option. Some options requires additional dependencies.
Stringurl.UrlObjectStringObjectString pass URL encoded string if you want it to be RFC3986 encoded prior sendingObjectStreamBufferStringArrayPass Object for multipart/form-data body:
// set item
multipart: {photo: fs.createReadStream('cat.png')}
// pass additional info about the uploaded item
multipart: {
photo: {
value: fs.createReadStream('cat.png'),
options: {filename: 'cat.png', contentType: 'image/png', knownLength: 22025}
}
}
// pass array of values for this item
multipart: {attachments: [fs.createReadStream('cat.png'), fs.createReadStream('dog.png')]}
The item’s value can be either: Stream, Request, Buffer or String.
Pass Array for any other multipart/[TYPE], defaults to multipart/related:
// Example: Upload image to Google Drive
multipart: [
{
'Content-Type': 'application/json',
body: JSON.stringify({title: 'cat.png'})
},
{
'Content-Type': 'image/png',
body: fs.createReadStream('cat.png')
}
]
The body key is required and reserved for setting up the item’s body. It can be either: Stream, Request, Buffer or String.
Additionally you can set preambleCRLF and/or postambleCRLF to true.
{user: '', pass: '', sendImmediately: false}
Authorization: Basic ... header.sendImmediately option default to true if omitted.sendImmediately: false options requires the redirect option to be enabled.{bearer: '', sendImmediately: false}
Authorization: Bearer ... header can be set if using the bearer option.sendImmediately option from above applies here.gzip: true
content-encoding response header.gzip: 'gzip' | gzip: 'deflate'
encoding: true
utf8.encoding: 'ISO-8859-1' | encoding: 'win1251' | …
encoding: 'binary'
encoding to 'binary' when expecting binary response.truenew require('tough-cookie).CookieJar(store, options)true defaults to false if omittedbuffers the response body
function(err, res, body) by default the response buffer is decoded into string using utf8. Set the encoding property to binary if you expect binary data, or any other specific encodingtrue follow redirects for GET, HEAD, OPTIONS and TRACE requestsObject
referer header on redirectfunction (res) user defined function to check if the redirect should be allowedNumber integer containing the number of milliseconds to wait for a server to send response headers (and start the response body) before aborting the request. Note that if the underlying TCP connection cannot be established, the OS-wide TCP connection timeout will overrule the timeout optionStringurl.UrlObject{
proxy: 'http://localhost:6767'
//
proxy: url.parse('http://localhost:6767')
//
proxy: {
url: 'http://localhost:6767',
headers: {
allow: ['header-name'],
exclusive: ['header-name']
}
}
}
true{json: true}
accept: application/json header for the requestJSON or JSONP response bodies (only if the server responds with the approprite headers){json: function () {}}
JSON.parse method{qs: {sep:';', eq:':'}}
qs.parse options to use{querystring: {sep:';', eq:':', options: {}}} use the [querystring][node-querystring] module instead
querystring.parse options to use{qs: {sep:';', eq:':'}}
qs.stringify options to use{querystring: {sep:';', eq:':', options: {}}} use the [querystring][node-querystring] module instead
querystring.stringify options to usetrue tries to automatically end the request on nextTick_initialized set when the outgoing HTTP request is fully initialized_started set after first write/end_req http.ClientRequest created in HTTPDuplex_res http.IncomingMessage created in HTTPDuplex_client http or https module_redirect boolean indicating that the client is going to be redirected_redirected boolean indicating that the client is been redirected at least once_src the input read stream, usually from pipe_chunks Array - the first chunk read from the input read stream_ended whether the outgoing request has ended_auth whether basic auth is being used_timeout timeout timer instanceinitabortBuffer or String (the callback option is required)callback and the parse:{json:true} options are required)followed state variable, containing the followed redirects countsent state variable indicating whether the Basic auth is sent alreadyheader as a propertyRequires @request/log
method, url, and headersstatusCode, statusMessage, and headershttp.request method@request/core options object right before sending the requestcallback option is being used)callback and parse.json options are being used)$ DEBUG=req,res node app.js
oauth: transport_method: body requires method: POST and content-type: application/x-www-form-urlencodedoauth: signature_method: PLAINTEXT not supported with body_hash signingThis module may contain code snippets initially implemented in request by request contributors.