Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

request

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request - npm Package Compare versions

Comparing version 2.34.0 to 2.35.0

CHANGELOG.md

39

index.js

@@ -18,2 +18,4 @@ // Copyright 2010-2012 Mikeal Rogers

, Request = require('./request')
, util = require('util')
, _merge = require('lodash.merge')
;

@@ -25,29 +27,32 @@

function initParams(uri, options, callback) {
var opts;
if ((typeof options === 'function') && !callback) callback = options
if (options && typeof options === 'object') {
options.uri = uri
opts = util._extend({}, options);
opts.uri = uri
} else if (typeof uri === 'string') {
options = {uri:uri}
opts = {uri:uri}
} else {
options = uri
uri = options.uri
opts = util._extend({}, uri);
uri = opts.uri
}
return { uri: uri, options: options, callback: callback }
return { uri: uri, options: opts, callback: callback }
}
function request (uri, options, callback) {
var opts;
if (typeof uri === 'undefined') throw new Error('undefined is not a valid uri or options object.')
if ((typeof options === 'function') && !callback) callback = options
if (options && typeof options === 'object') {
options.uri = uri
opts = util._extend({}, options);
opts.uri = uri
} else if (typeof uri === 'string') {
options = {uri:uri}
opts = {uri:uri}
} else {
options = uri
opts = util._extend({}, uri);
}
options = copy(options)
if (callback) options.callback = callback
var r = new Request(options)
if (callback) opts.callback = callback
var r = new Request(opts)
return r

@@ -68,5 +73,3 @@ }

var params = initParams(uri, opts, callback)
for (var i in options) {
if (params.options[i] === undefined) params.options[i] = options[i]
}
params.options = _merge(options, params.options)
if(typeof requester === 'function') {

@@ -115,3 +118,7 @@ if(method === request) {

request.get = request
request.get = function (uri, options, callback) {
var params = initParams(uri, options, callback)
params.options.method = 'GET'
return requester(params)(params.uri || null, params.options, params.callback)
}
request.post = function (uri, options, callback) {

@@ -118,0 +125,0 @@ var params = initParams(uri, options, callback)

@@ -10,3 +10,3 @@ {

],
"version": "2.34.0",
"version": "2.35.0",
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>",

@@ -26,7 +26,8 @@ "repository": {

"dependencies": {
"qs": "~0.6.0",
"forever-agent": "~0.5.0",
"json-stringify-safe": "~5.0.0",
"forever-agent": "~0.5.0",
"lodash.merge": "~2.4.1",
"mime": "~1.2.9",
"node-uuid": "~1.4.0",
"mime": "~1.2.9"
"qs": "~0.6.0"
},

@@ -36,3 +37,3 @@ "optionalDependencies": {

"form-data": "~0.1.0",
"tunnel-agent": "~0.3.0",
"tunnel-agent": "~0.4.0",
"http-signature": "~0.10.0",

@@ -39,0 +40,0 @@ "oauth-sign": "~0.3.0",

@@ -111,8 +111,16 @@ # Request -- Simplified HTTP client

```javascript
var r = request.post('http://service.com/upload')
var r = request.post('http://service.com/upload', function optionalCallback (err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
})
var form = r.form()
form.append('my_field', 'my_value')
form.append('my_buffer', new Buffer([1, 2, 3]))
form.append('my_file', fs.createReadStream(path.join(__dirname, 'doodle.png'))
form.append('my_file', fs.createReadStream(path.join(__dirname, 'doodle.png')))
form.append('remote_file', request('http://google.com/doodle.png'))
// Just like always, `r` is a writable stream, and can be used as such (you have until nextTick to pipe it, etc.)
// Alternatively, you can provide a callback (that's what this example does-- see `optionalCallback` above).
```

@@ -132,5 +140,13 @@

});
// or
request.get('http://some.server.com/').auth(null, null, true, 'bearerToken');
// or
request.get('http://some.server.com/', {
'auth': {
'bearer': 'bearerToken'
}
});
```
If passed as an option, `auth` should be a hash containing values `user` || `username`, `password` || `pass`, and `sendImmediately` (optional). The method form takes parameters `auth(username, password, sendImmediately)`.
If passed as an option, `auth` should be a hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). The method form takes parameters `auth(username, password, sendImmediately)`.

@@ -141,2 +157,4 @@ `sendImmediately` defaults to `true`, which causes a basic authentication header to be sent. If `sendImmediately` is `false`, then `request` will retry with a proper authentication header after receiving a `401` response from the server (which must contain a `WWW-Authenticate` header indicating the required authentication method).

Bearer authentication is supported, and is activated when the `bearer` value is available. The value may be either a `String` or a `Function` returning a `String`. Using a function to supply the bearer token is particularly useful if used in conjuction with `defaults` to allow a single function to supply the last known token at the time or sending a request or to compute one on the fly.
## OAuth Signing

@@ -228,3 +246,3 @@

* `form` - when passed an object, this sets `body` to a querystring representation of value, and adds `Content-type: application/x-www-form-urlencoded; charset=utf-8` header. When passed no options, a `FormData` instance is returned (and is piped to request).
* `auth` - A hash containing values `user` || `username`, `password` || `pass`, and `sendImmediately` (optional). See documentation above.
* `auth` - A hash containing values `user` || `username`, `pass` || `password`, and `sendImmediately` (optional). See documentation above.
* `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header. Additionally, parses the response body as JSON.

@@ -362,3 +380,3 @@ * `multipart` - (experimental) array of objects which contains their own headers and `body` attribute. Sends `multipart/related` request. See example below.

To use a custom cookie jar (instead `request`’s global cookie jar), set `jar` to an instance of `request.jar()` (either in `defaults` or `options`)
To use a custom cookie jar (instead of `request`’s global cookie jar), set `jar` to an instance of `request.jar()` (either in `defaults` or `options`)

@@ -365,0 +383,0 @@ ```javascript

@@ -247,9 +247,9 @@ var optional = require('./lib/optional')

var self = this;
if (options.form) {
self.form(options.form)
}
if (options.qs) self.qs(options.qs)
if (self.uri.path) {

@@ -260,6 +260,6 @@ self.path = self.uri.path

}
if (self.path.length === 0) self.path = '/'
// Auth must happen last in case signing is dependent on other headers

@@ -269,26 +269,27 @@ if (options.oauth) {

}
if (options.aws) {
self.aws(options.aws)
}
if (options.hawk) {
self.hawk(options.hawk)
}
if (options.httpSignature) {
self.httpSignature(options.httpSignature)
}
if (options.auth) {
if (Object.prototype.hasOwnProperty.call(options.auth, 'username')) options.auth.user = options.auth.username
if (Object.prototype.hasOwnProperty.call(options.auth, 'password')) options.auth.pass = options.auth.password
self.auth(
options.auth.user,
options.auth.pass,
options.auth.sendImmediately
options.auth.sendImmediately,
options.auth.bearer
)
}
if (self.uri.auth && !self.hasHeader('authorization')) {

@@ -301,6 +302,6 @@ var authPieces = self.uri.auth.split(':').map(function(item){ return querystring.unescape(item) })

}
if (self.proxy && !self.tunnel) self.path = (self.uri.protocol + '//' + self.uri.host + self.path)
if (options.json) {

@@ -312,3 +313,3 @@ self.json(options.json)

}
if (self.body) {

@@ -334,3 +335,3 @@ var length = 0

}
var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol

@@ -341,10 +342,10 @@ , defaultModules = {'http:':http, 'https:':https, 'unix:':http}

self.httpModule = httpModules[protocol] || defaultModules[protocol]
if (!self.httpModule) return this.emit('error', new Error("Invalid protocol"))
if (!self.httpModule) return this.emit('error', new Error("Invalid protocol: " + protocol))
if (options.ca) self.ca = options.ca
if (!self.agent) {
if (options.agentOptions) self.agentOptions = options.agentOptions
if (options.agentClass) {

@@ -358,3 +359,3 @@ self.agentClass = options.agentClass

}
if (self.pool === false) {

@@ -373,3 +374,3 @@ self.agent = false

}
self.on('pipe', function (src) {

@@ -394,3 +395,3 @@ if (self.ntick && self._started) throw new Error("You cannot pipe to this stream after the outbound request has started.")

}
// self.on('pipe', function () {

@@ -400,6 +401,6 @@ // console.error("You have already piped to this stream. Pipeing twice is likely to break the request.")

})
process.nextTick(function () {
if (self._aborted) return
if (self._form) {

@@ -433,5 +434,5 @@ self.setHeaders(self._form.getHeaders())

})
} // End _buildRequest
self._handleUnixSocketURI = function(self){

@@ -441,11 +442,11 @@ // Parse URI and extract a socket path (tested as a valid socket using net.connect), and a http style path suffix

// and a request for '/urlpath' will be sent to the unix socket at /tmp/my.socket
self.unixsocket = true;
var full_path = self.uri.href.replace(self.uri.protocol+'/', '');
var lookup = full_path.split('/');
var error_connecting = true;
var lookup_table = {};
var lookup_table = {};
do { lookup_table[lookup.join('/')]={} } while(lookup.pop())

@@ -455,3 +456,3 @@ for (r in lookup_table){

}
function try_next(table_row){

@@ -464,5 +465,5 @@ var client = net.connect( table_row );

}
wait_for_socket_response();
response_counter = 0;

@@ -485,7 +486,7 @@

wait_for_socket_response()
else
else
set_socket_properties();
})
}
function set_socket_properties(){

@@ -502,3 +503,3 @@ var host;

var path = full_path.replace(host, '')
self.socketPath = host

@@ -515,3 +516,3 @@ self.uri.pathname = path

}
// Intercept UNIX protocol requests to change properties to match socket

@@ -523,3 +524,3 @@ if(/^unix:/.test(self.uri.protocol)){

}
}

@@ -602,2 +603,3 @@

if (this.secureProtocol) options.secureProtocol = this.secureProtocol
if (this.secureOptions) options.secureOptions = this.secureOptions
if (typeof this.rejectUnauthorized !== 'undefined') options.rejectUnauthorized = this.rejectUnauthorized

@@ -810,2 +812,7 @@

case 'bearer':
self.auth(null, null, true, self._bearer)
redirectTo = self.uri
break
case 'digest':

@@ -900,3 +907,3 @@ // TODO: More complete implementation of RFC 2617.

)
if (self.followAllRedirects && response.statusCode != 401) self.method = 'GET'
if (self.followAllRedirects && response.statusCode != 401 && response.statusCode != 307) self.method = 'GET'
// self.method = 'GET' // Force all redirects to use GET || commented out fixes #215

@@ -907,3 +914,3 @@ delete self.src

delete self._started
if (response.statusCode != 401) {
if (response.statusCode != 401 && response.statusCode != 307) {
// Remove parameters from the previous response, unless this is the second request

@@ -1166,2 +1173,3 @@ // for a server that requires digest authentication.

Object.keys(headers).forEach(function (key) {
if (key.length !== name.length) return
re = new RegExp(name, 'i')

@@ -1175,3 +1183,15 @@ match = key.match(re)

Request.prototype.auth = function (user, pass, sendImmediately) {
Request.prototype.auth = function (user, pass, sendImmediately, bearer) {
if (bearer !== undefined) {
this._bearer = bearer
this._hasAuth = true
if (sendImmediately || typeof sendImmediately == 'undefined') {
if (typeof bearer === 'function') {
bearer = bearer()
}
this.setHeader('authorization', 'Bearer ' + bearer)
this._sentAuth = true
}
return this
}
if (typeof user !== 'string' || (pass !== undefined && typeof pass !== 'string')) {

@@ -1178,0 +1198,0 @@ throw new Error('auth() received invalid user or password')

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc