Comparing version 2.16.6 to 2.18.0
152
index.js
@@ -24,6 +24,7 @@ // Copyright 2010-2012 Mikeal Rogers | ||
, crypto = require('crypto') | ||
, oauth = require('oauth-sign') | ||
, hawk = require('hawk') | ||
, aws = require('aws-sign') | ||
, httpSignature = require('http-signature') | ||
, uuid = require('node-uuid') | ||
@@ -36,3 +37,3 @@ , mime = require('mime') | ||
, FormData = require('form-data') | ||
, Cookie = require('cookie-jar') | ||
@@ -109,3 +110,3 @@ , CookieJar = Cookie.Jar | ||
} | ||
var reserved = Object.keys(Request.prototype) | ||
@@ -121,3 +122,3 @@ for (var i in options) { | ||
} | ||
this.init(options) | ||
@@ -132,5 +133,6 @@ } | ||
if (!options) options = {} | ||
self.method = options.method || 'GET' | ||
if (!self.method) self.method = options.method || 'GET' | ||
self.localAddress = options.localAddress | ||
debug(options) | ||
@@ -140,3 +142,3 @@ if (!self.pool && self.pool !== false) self.pool = globalPool | ||
self.__isRequestRequest = true | ||
// Protect against double callback | ||
@@ -166,3 +168,7 @@ if (!self._callback && self.callback) { | ||
} | ||
if (self.strictSSL === false) { | ||
self.rejectUnauthorized = false | ||
} | ||
if (self.proxy) { | ||
@@ -179,4 +185,5 @@ if (typeof self.proxy == 'string') self.proxy = url.parse(self.proxy) | ||
, proxyAuth: self.proxy.auth | ||
, headers: { Host: self.uri.hostname + ':' + | ||
, headers: { Host: self.uri.hostname + ':' + | ||
(self.uri.port || self.uri.protocol === 'https:' ? 443 : 80) }} | ||
, rejectUnauthorized: self.rejectUnauthorized | ||
, ca: this.ca } | ||
@@ -223,3 +230,3 @@ | ||
} | ||
self.jar(self._jar || options.jar) | ||
@@ -243,3 +250,3 @@ | ||
if (self._aborted) return | ||
if (self.req && self.req._reusedSocket && error.code === 'ECONNRESET' | ||
@@ -274,3 +281,3 @@ && self.agent.addRequestNoreuse) { | ||
} | ||
if (options.qs) self.qs(options.qs) | ||
@@ -291,7 +298,7 @@ | ||
} | ||
if (options.aws) { | ||
self.aws(options.aws) | ||
} | ||
if (options.hawk) { | ||
@@ -301,2 +308,6 @@ self.hawk(options.hawk) | ||
if (options.httpSignature) { | ||
self.httpSignature(options.httpSignature) | ||
} | ||
if (options.auth) { | ||
@@ -317,3 +328,3 @@ self.auth( | ||
if (self.proxy && !self.tunnel) self.path = (self.uri.protocol + '//' + self.uri.host + self.path) | ||
@@ -371,6 +382,2 @@ | ||
} | ||
if (self.strictSSL === false) { | ||
self.rejectUnauthorized = false | ||
} | ||
@@ -419,3 +426,3 @@ if (self.pool === false) { | ||
if (self._aborted) return | ||
if (self._form) { | ||
@@ -464,2 +471,3 @@ self.setHeaders(self._form.getHeaders()) | ||
, proxyAuth: self.proxy.auth } | ||
, rejectUnauthorized: self.rejectUnauthorized | ||
, ca: self.ca } | ||
@@ -608,3 +616,3 @@ self.agent = tunnelFn(tunnelOptions) | ||
}, self.timeout) | ||
// Set additional timeout on socket - in case if remote | ||
@@ -623,3 +631,3 @@ // server freeze after sending headers | ||
} | ||
self.req.on('error', self.clientErrorHandler) | ||
@@ -640,3 +648,3 @@ self.req.on('drain', function() { | ||
}); | ||
if (response.connection.listeners('error').indexOf(self._parserErrorHandler) === -1) { | ||
@@ -792,10 +800,12 @@ response.connection.once('error', self._parserErrorHandler) | ||
if (response.statusCode != 401) { | ||
// Remove parameters from the previous response, unless this is the second request | ||
// for a server that requires digest authentication. | ||
delete self.body | ||
delete self._form | ||
if (self.headers) { | ||
delete self.headers.host | ||
delete self.headers['content-type'] | ||
delete self.headers['content-length'] | ||
} | ||
} | ||
if (self.headers) { | ||
delete self.headers.host | ||
delete self.headers['content-type'] | ||
delete self.headers['content-length'] | ||
} | ||
self.init() | ||
@@ -819,2 +829,4 @@ return // Ignore the rest of the response | ||
self.emit('response', response) | ||
self.dests.forEach(function (dest) { | ||
@@ -834,4 +846,2 @@ self.pipeDest(dest) | ||
self.emit('response', response) | ||
if (self.callback) { | ||
@@ -879,2 +889,5 @@ var buffer = [] | ||
debug('emitting complete', self.uri.href) | ||
if(response.body == undefined && !self._json) { | ||
response.body = ""; | ||
} | ||
self.emit('complete', response, response.body) | ||
@@ -889,3 +902,3 @@ }) | ||
this._aborted = true | ||
if (this.req) { | ||
@@ -897,3 +910,3 @@ this.req.abort() | ||
} | ||
this.emit("abort") | ||
@@ -935,3 +948,3 @@ } | ||
else base = {} | ||
for (var i in q) { | ||
@@ -944,6 +957,7 @@ base[i] = q[i] | ||
} | ||
this.uri = url.parse(this.uri.href.split('?')[0] + '?' + qs.stringify(base)) | ||
this.url = this.uri | ||
this.path = this.uri.path | ||
return this | ||
@@ -956,3 +970,3 @@ } | ||
return this | ||
} | ||
} | ||
// create form-data object | ||
@@ -977,3 +991,3 @@ this._form = new FormData() | ||
} | ||
multipart.forEach(function (part) { | ||
@@ -1027,3 +1041,3 @@ var body = part.body | ||
Request.prototype.auth = function (user, pass, sendImmediately) { | ||
if (typeof user !== 'string' || typeof pass !== 'string') { | ||
if (typeof user !== 'string' || (pass !== undefined && typeof pass !== 'string')) { | ||
throw new Error('auth() received invalid user or password') | ||
@@ -1067,6 +1081,22 @@ } | ||
this.setHeader('authorization', aws.authorization(auth)) | ||
return this | ||
} | ||
Request.prototype.httpSignature = function (opts) { | ||
var req = this | ||
httpSignature.signRequest({ | ||
getHeader: function(header) { | ||
return getHeader(header, req.headers) | ||
}, | ||
setHeader: function(header, value) { | ||
req.setHeader(header, value) | ||
}, | ||
method: this.method, | ||
path: this.path | ||
}, opts) | ||
debug('httpSignature authorization', getHeader('authorization', this.headers)) | ||
return this | ||
} | ||
Request.prototype.hawk = function (opts) { | ||
@@ -1078,5 +1108,5 @@ this.headers.Authorization = hawk.client.header(this.uri, this.method, opts).field | ||
var form | ||
if (this.headers['content-type'] && | ||
if (this.headers['content-type'] && | ||
this.headers['content-type'].slice(0, 'application/x-www-form-urlencoded'.length) === | ||
'application/x-www-form-urlencoded' | ||
'application/x-www-form-urlencoded' | ||
) { | ||
@@ -1087,3 +1117,3 @@ form = qs.parse(this.body) | ||
form = qs.parse(this.uri.query) | ||
} | ||
} | ||
if (!form) form = {} | ||
@@ -1096,5 +1126,5 @@ var oa = {} | ||
if (!oa.oauth_nonce) oa.oauth_nonce = uuid().replace(/-/g, '') | ||
oa.oauth_signature_method = 'HMAC-SHA1' | ||
var consumer_secret = oa.oauth_consumer_secret | ||
@@ -1108,7 +1138,7 @@ delete oa.oauth_consumer_secret | ||
var signature = oauth.hmacsign(this.method, baseurl, oa, consumer_secret, token_secret) | ||
// oa.oauth_signature = signature | ||
for (var i in form) { | ||
if ( i.slice(0, 'oauth_') in _oauth) { | ||
// skip | ||
// skip | ||
} else { | ||
@@ -1127,7 +1157,7 @@ delete oa['oauth_'+i] | ||
var cookies | ||
if (this._redirectsFollowed === 0) { | ||
this.originalCookieHeader = this.headers.cookie | ||
} | ||
if (jar === false) { | ||
@@ -1144,3 +1174,3 @@ // disable cookies | ||
} | ||
if (cookies && cookies.length) { | ||
@@ -1302,5 +1332,5 @@ var cookieString = cookies.map(function (c) { | ||
params.options.method = 'HEAD' | ||
if (params.options.body || | ||
params.options.requestBodyStream || | ||
(params.options.json && typeof params.options.json !== 'boolean') || | ||
if (params.options.body || | ||
params.options.requestBodyStream || | ||
(params.options.json && typeof params.options.json !== 'boolean') || | ||
params.options.multipart) { | ||
@@ -1330,3 +1360,3 @@ throw new Error("HTTP HEAD requests MUST NOT include a request body.") | ||
function getSafe (self, uuid) { | ||
function getSafe (self, uuid) { | ||
if (typeof self === 'object' || typeof self === 'function') var safe = {} | ||
@@ -1336,14 +1366,14 @@ if (Array.isArray(self)) var safe = [] | ||
var recurse = [] | ||
Object.defineProperty(self, uuid, {}) | ||
var attrs = Object.keys(self).filter(function (i) { | ||
if (i === uuid) return false | ||
if (i === uuid) return false | ||
if ( (typeof self[i] !== 'object' && typeof self[i] !== 'function') || self[i] === null) return true | ||
return !(Object.getOwnPropertyDescriptor(self[i], uuid)) | ||
}) | ||
for (var i=0;i<attrs.length;i++) { | ||
if ( (typeof self[attrs[i]] !== 'object' && typeof self[attrs[i]] !== 'function') || | ||
if ( (typeof self[attrs[i]] !== 'object' && typeof self[attrs[i]] !== 'function') || | ||
self[attrs[i]] === null | ||
@@ -1361,3 +1391,3 @@ ) { | ||
} | ||
return safe | ||
@@ -1364,0 +1394,0 @@ } |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "2.16.6", | ||
"version": "2.18.0", | ||
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>", | ||
@@ -29,7 +29,8 @@ "repository": { | ||
"node-uuid": "~1.4.0", | ||
"cookie-jar": "~0.2.0", | ||
"aws-sign": "~0.2.0", | ||
"oauth-sign": "~0.2.0", | ||
"forever-agent": "~0.2.0", | ||
"tunnel-agent": "~0.2.0", | ||
"cookie-jar": "~0.3.0", | ||
"aws-sign": "~0.3.0", | ||
"oauth-sign": "~0.3.0", | ||
"http-signature": "~0.9.1", | ||
"forever-agent": "~0.3.0", | ||
"tunnel-agent": "~0.5.0", | ||
"json-stringify-safe": "~3.0.0", | ||
@@ -36,0 +37,0 @@ "qs": "~0.5.4" |
@@ -214,2 +214,4 @@ # Request -- Simplified HTTP request method | ||
* `aws` - object containing aws signing information, should have the properties `key` and `secret` as well as `bucket` unless you're specifying your bucket as part of the path, or you are making a request that doesn't use a bucket (i.e. GET Services) | ||
* `httpSignature` - Options for the [HTTP Signature Scheme](https://github.com/joyent/node-http-signature/blob/master/http_signing.md) using [Joyent's library](https://github.com/joyent/node-http-signature). The `keyId` and `key` properties must be specified. See the docs for other options. | ||
* `localAddress` - Local interface to bind for network connections. | ||
@@ -216,0 +218,0 @@ |
@@ -27,2 +27,13 @@ var assert = require('assert') | ||
if (req.url == '/post/') { | ||
var expectedContent = 'data_key=data_value'; | ||
req.on('data', function(data) { | ||
assert.equal(data, expectedContent); | ||
console.log('received request data: ' + data); | ||
}); | ||
assert.equal(req.method, 'POST'); | ||
assert.equal(req.headers['content-length'], '' + expectedContent.length); | ||
assert.equal(req.headers['content-type'], 'application/x-www-form-urlencoded; charset=utf-8'); | ||
} | ||
if (ok) { | ||
@@ -40,37 +51,75 @@ console.log('request ok'); | ||
request({ | ||
'method': 'GET', | ||
'uri': 'http://localhost:6767/test/', | ||
'auth': { | ||
'user': 'test', | ||
'pass': 'testing2', | ||
'sendImmediately': false | ||
} | ||
}, function(error, response, body) { | ||
assert.equal(response.statusCode, 200); | ||
assert.equal(numBasicRequests, 2); | ||
var tests = [ | ||
function(next) { | ||
request({ | ||
'method': 'GET', | ||
'uri': 'http://localhost:6767/test/', | ||
'auth': { | ||
'user': 'test', | ||
'pass': 'testing2', | ||
'sendImmediately': false | ||
} | ||
}, function(error, res, body) { | ||
assert.equal(res.statusCode, 200); | ||
assert.equal(numBasicRequests, 2); | ||
next(); | ||
}); | ||
}, | ||
// If we don't set sendImmediately = false, request will send basic auth | ||
request({ | ||
'method': 'GET', | ||
'uri': 'http://localhost:6767/test2/', | ||
'auth': { | ||
'user': 'test', | ||
'pass': 'testing2' | ||
} | ||
}, function(error, response, body) { | ||
assert.equal(response.statusCode, 200); | ||
assert.equal(numBasicRequests, 3); | ||
function(next) { | ||
// If we don't set sendImmediately = false, request will send basic auth | ||
request({ | ||
'method': 'GET', | ||
'uri': 'http://localhost:6767/test2/', | ||
'auth': { | ||
'user': 'test', | ||
'pass': 'testing2' | ||
} | ||
}, function(error, res, body) { | ||
assert.equal(res.statusCode, 200); | ||
assert.equal(numBasicRequests, 3); | ||
next(); | ||
}); | ||
}, | ||
function(next) { | ||
request({ | ||
'method': 'GET', | ||
'uri': 'http://test:testing2@localhost:6767/test2/' | ||
}, function(error, response, body) { | ||
assert.equal(response.statusCode, 200); | ||
}, function(error, res, body) { | ||
assert.equal(res.statusCode, 200); | ||
assert.equal(numBasicRequests, 4); | ||
next(); | ||
}); | ||
}, | ||
console.log('All tests passed'); | ||
basicServer.close(); | ||
function(next) { | ||
request({ | ||
'method': 'POST', | ||
'form': { 'data_key': 'data_value' }, | ||
'uri': 'http://localhost:6767/post/', | ||
'auth': { | ||
'user': 'test', | ||
'pass': 'testing2', | ||
'sendImmediately': false | ||
} | ||
}, function(error, res, body) { | ||
assert.equal(res.statusCode, 200); | ||
assert.equal(numBasicRequests, 6); | ||
next(); | ||
}); | ||
}); | ||
}); | ||
} | ||
]; | ||
function runTest(i) { | ||
if (i < tests.length) { | ||
tests[i](function() { | ||
runTest(i + 1); | ||
}); | ||
} else { | ||
console.log('All tests passed'); | ||
basicServer.close(); | ||
} | ||
} | ||
runTest(0); |
@@ -35,1 +35,9 @@ var request = request = require('../index') | ||
}, 1) | ||
// Test modifying the qs after creating the request | ||
var req6 = request.get({ uri: 'http://www.google.com', qs: {}}); | ||
req6.qs({ q: "test" }); | ||
process.nextTick(function() { | ||
assert.equal('/?q=test', req6.path); | ||
}); |
@@ -34,10 +34,14 @@ // test that we can tunnel a https request over an http proxy | ||
squid.on('error', function (c) { | ||
console.error('squid: error '+c) | ||
if (c && !ready) { | ||
notInstalled() | ||
return | ||
} | ||
}) | ||
squid.on('exit', function (c) { | ||
console.error('squid: exit '+c) | ||
if (c && !ready) { | ||
console.error('squid must be installed to run this test.') | ||
console.error('skipping this test. please install squid and run again if you need to test tunneling.') | ||
c = null | ||
hadError = null | ||
process.exit(0) | ||
notInstalled() | ||
return | ||
@@ -65,1 +69,9 @@ } | ||
}, 100) | ||
function notInstalled() { | ||
console.error('squid must be installed to run this test.') | ||
console.error('skipping this test. please install squid and run again if you need to test tunneling.') | ||
c = null | ||
hadError = null | ||
process.exit(0) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
196505
52
3153
345
12
23
+ Addedhttp-signature@~0.9.1
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.2(transitive)
+ Addedaws-sign@0.3.0(transitive)
+ Addedcookie-jar@0.3.0(transitive)
+ Addedctype@0.5.2(transitive)
+ Addedforever-agent@0.3.0(transitive)
+ Addedhttp-signature@0.9.11(transitive)
+ Addedoauth-sign@0.3.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedtunnel-agent@0.5.0(transitive)
- Removedaws-sign@0.2.1(transitive)
- Removedcookie-jar@0.2.0(transitive)
- Removedforever-agent@0.2.0(transitive)
- Removedoauth-sign@0.2.0(transitive)
- Removedtunnel-agent@0.2.0(transitive)
Updatedaws-sign@~0.3.0
Updatedcookie-jar@~0.3.0
Updatedforever-agent@~0.3.0
Updatedoauth-sign@~0.3.0
Updatedtunnel-agent@~0.5.0