
Security News
Feross on Risky Business Weekly Podcast: npm’s Ongoing Supply Chain Attacks
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
@request/core
Advanced tools
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.
String
url.Url
Object
String
Object
String
pass URL encoded string if you want it to be RFC3986 encoded prior sendingObject
Stream
Buffer
String
Array
Pass 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.true
new 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 optionString
url.Url
Object
{
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 instanceinit
abort
Buffer
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 headers
statusCode
, statusMessage
, and headers
http.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-urlencoded
oauth: signature_method: PLAINTEXT not supported with body_hash signing
This module may contain code snippets initially implemented in request by request contributors.
FAQs
HTTP Client Library
We found that @request/core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.