Socket
Socket
Sign inDemoInstall

request

Package Overview
Dependencies
0
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.9.153 to 2.9.200

tests/test-toJSON.js

127

main.js

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

}
self.on('error', self.callback.bind())
self.on('complete', self.callback.bind(self, null))
}

@@ -146,3 +148,4 @@

var tunnelOptions = { proxy: { host: self.proxy.hostname
, port: +self.proxy.port }
, port: +self.proxy.port
, proxyAuth: self.proxy.auth }
, ca: this.ca }

@@ -175,3 +178,3 @@

self.jar(options.jar)
self.jar(self._jar || options.jar)

@@ -192,7 +195,2 @@ if (!self.uri.pathname) {self.uri.pathname = '/'}

if (self.onResponse === true) {
self.onResponse = self.callback
delete self.callback
}
self.clientErrorHandler = function (error) {

@@ -210,9 +208,7 @@ if (self._aborted) return

if (self.timeout && self.timeoutTimer) {
clearTimeout(self.timeoutTimer);
self.timeoutTimer = null;
clearTimeout(self.timeoutTimer)
self.timeoutTimer = null
}
self.emit('error', error)
}
if (self.onResponse) self.on('error', function (e) {self.onResponse(e)})
if (self.callback) self.on('error', function (e) {self.callback(e)})

@@ -412,2 +408,3 @@ if (options.form) {

response.request = self
response.toJSON = toJSON

@@ -424,4 +421,4 @@ if (self.httpModule === https &&

if (self.timeout && self.timeoutTimer) {
clearTimeout(self.timeoutTimer);
self.timeoutTimer = null;
clearTimeout(self.timeoutTimer)
self.timeoutTimer = null
}

@@ -455,6 +452,8 @@

)
self.method = 'GET'; // Force all redirects to use GET
if (self.followAllRedirects) self.method = 'GET'
// self.method = 'GET'; // Force all redirects to use GET || commented out fixes #215
delete self.req
delete self.agent
delete self._started
delete self.body
if (self.headers) {

@@ -498,5 +497,2 @@ delete self.headers.host

if (self.onResponse) {
self.onResponse(null, response)
}
if (self.callback) {

@@ -533,4 +529,4 @@ var buffer = []

}
self.callback(null, response, response.body)
self.emit('complete', response, response.body)
})

@@ -553,8 +549,8 @@ }

self.req.setTimeout(self.timeout, function(){
if (self.req) {
self.req.abort()
var e = new Error("ESOCKETTIMEDOUT")
e.code = "ESOCKETTIMEDOUT"
self.emit("error", e)
}
if (self.req) {
self.req.abort()
var e = new Error("ESOCKETTIMEDOUT")
e.code = "ESOCKETTIMEDOUT"
self.emit("error", e)
}
})

@@ -612,13 +608,13 @@ }

Request.prototype.qs = function (q, clobber) {
var uri = {
protocol: this.uri.protocol,
host: this.uri.host,
pathname: this.uri.pathname,
query: clobber ? q : qs.parse(this.uri.query),
hash: this.uri.hash
};
if (!clobber) for (var i in q) uri.query[i] = q[i]
this.uri= url.parse(url.format(uri))
var base
if (!clobber && this.uri.query) base = qs.parse(this.uri.query)
else base = {}
for (var i in q) {
base[i] = q[i]
}
this.uri = url.parse(this.uri.href.split('?')[0] + '?' + qs.stringify(base))
this.url = this.uri
return this

@@ -636,5 +632,5 @@ }

if (!self.headers['content-type']) {
self.headers['content-type'] = 'multipart/related;boundary="frontier"';
self.headers['content-type'] = 'multipart/related; boundary=frontier';
} else {
self.headers['content-type'] = self.headers['content-type'].split(';')[0] + ';boundary="frontier"';
self.headers['content-type'] = self.headers['content-type'].split(';')[0] + '; boundary=frontier';
}

@@ -708,5 +704,5 @@

}
this.headers.authorization =
this.headers.Authorization =
'OAuth '+Object.keys(oa).sort().map(function (i) {return i+'="'+oauth.rfc3986(oa[i])+'"'}).join(',')
this.headers.authorization += ',oauth_signature="'+oauth.rfc3986(signature)+'"'
this.headers.Authorization += ',oauth_signature="'+oauth.rfc3986(signature)+'"'
return this

@@ -804,2 +800,3 @@ }

function request (uri, options, callback) {
if (typeof uri === 'undefined') throw new Error('undefined is not a valid uri or options object.')
if ((typeof options === 'function') && !callback) callback = options;

@@ -859,3 +856,3 @@ if (typeof options === 'object') {

params.options.method = 'POST';
return request(params.uri, params.options, params.callback)
return request(params.uri || null, params.options, params.callback)
}

@@ -865,3 +862,3 @@ request.put = function (uri, options, callback) {

params.options.method = 'PUT'
return request(params.uri, params.options, params.callback)
return request(params.uri || null, params.options, params.callback)
}

@@ -877,3 +874,3 @@ request.head = function (uri, options, callback) {

}
return request(params.uri, params.options, params.callback)
return request(params.uri || null, params.options, params.callback)
}

@@ -883,3 +880,3 @@ request.del = function (uri, options, callback) {

params.options.method = 'DELETE'
return request(params.uri, params.options, params.callback)
return request(params.uri || null, params.options, params.callback)
}

@@ -894,1 +891,43 @@ request.jar = function () {

}
// Safe toJSON
function getSafe (self, uuid) {
if (typeof self === 'object' || typeof self === 'function') var safe = {}
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 ( (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') ||
self[attrs[i]] === null
) {
safe[attrs[i]] = self[attrs[i]]
} else {
recurse.push(attrs[i])
Object.defineProperty(self[attrs[i]], uuid, {})
}
}
for (var i=0;i<recurse.length;i++) {
safe[recurse[i]] = getSafe(self[recurse[i]], uuid)
}
return safe
}
function toJSON () {
return getSafe(this, (((1+Math.random())*0x10000)|0).toString(16))
}
Request.prototype.toJSON = toJSON

@@ -11,7 +11,7 @@ var crypto = require('crypto')

return encodeURIComponent(str)
.replace('!','%21')
.replace('*','%2A')
.replace('(','%28')
.replace(')','%29')
.replace("'",'%27')
.replace(/!/g,'%21')
.replace(/\*/g,'%2A')
.replace(/\(/g,'%28')
.replace(/\)/g,'%29')
.replace(/'/g,'%27')
;

@@ -18,0 +18,0 @@ }

{ "name" : "request"
, "description" : "Simplified HTTP request client."
, "tags" : ["http", "simple", "util", "utility"]
, "version" : "2.9.153"
, "version" : "2.9.200"
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>"

@@ -6,0 +6,0 @@ , "repository" :

@@ -159,3 +159,2 @@ # Request -- Simplified HTTP request method

* `maxRedirects` - the maximum number of redirects to follow, defaults to 10.
* `onResponse` - If true the callback will be fired on the "response" event instead of "end". If a function it will be called on "response" and not effect the regular semantics of the main callback on "end".
* `encoding` - Encoding to be used on `setEncoding` of response data. If set to `null`, the body is returned as a Buffer.

@@ -162,0 +161,0 @@ * `pool` - A hash object containing the agents for these requests. If omitted this request will use the global pool which is set to node's default maxSockets.

var Cookie = require('../vendor/cookie')
, assert = require('assert');
var str = 'sid="s543qactge.wKE61E01Bs%2BKhzmxrwrnug="; path=/; httpOnly; expires=Sat, 04 Dec 2010 23:27:28 GMT';
var str = 'Sid="s543qactge.wKE61E01Bs%2BKhzmxrwrnug="; Path=/; httpOnly; Expires=Sat, 04 Dec 2010 23:27:28 GMT';
var cookie = new Cookie(str);

@@ -17,3 +17,3 @@

// test .name
assert.equal(cookie.name, 'sid');
assert.equal(cookie.name, 'Sid');

@@ -20,0 +20,0 @@ // test .value

@@ -9,3 +9,3 @@ var hmacsign = require('../oauth').hmacsign

var sign
r.headers.authorization.slice('OAuth '.length).replace(/,\ /g, ',').split(',').forEach(function (v) {
r.headers.Authorization.slice('OAuth '.length).replace(/,\ /g, ',').split(',').forEach(function (v) {
if (v.slice(0, 'oauth_signature="'.length) === 'oauth_signature="') sign = v.slice('oauth_signature="'.length, -1)

@@ -12,0 +12,0 @@ })

@@ -23,3 +23,6 @@ var server = require('./server')

hits[label] = true;
res.writeHead(code, {'location':server + '/'+landing})
res.writeHead(code, {
'location':server + '/'+landing,
'set-cookie': 'ham=eggs'
})
res.end()

@@ -31,8 +34,9 @@ })

console.error("Got a non-GET request to the redirect destination URL");
resp.writeHead(400);
resp.end();
res.writeHead(400);
res.end();
return;
}
// Make sure the cookie doesn't get included twice, see #139:
assert.equal(req.headers.cookie, 'foo=bar; quux=baz');
// Make sure cookies are set properly after redirect
assert.equal(req.headers.cookie, 'foo=bar; quux=baz; ham=eggs');
hits[landing] = true;

@@ -48,69 +52,63 @@ res.writeHead(200)

request({uri: server+'/perm', jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.perm, 'Original request is to /perm')
assert.ok(hits.perm_landing, 'Forward to permanent landing URL')
assert.equal(body, 'perm_landing', 'Got permanent landing content')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode !== 200) throw new Error('Status is not 200: '+res.statusCode)
assert.ok(hits.perm, 'Original request is to /perm')
assert.ok(hits.perm_landing, 'Forward to permanent landing URL')
assert.equal(body, 'perm_landing', 'Got permanent landing content')
passed += 1
done()
})
// Temporary bounce
request({uri: server+'/temp', jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
assert.equal(body, 'temp_landing', 'Got temporary landing content')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode !== 200) throw new Error('Status is not 200: '+res.statusCode)
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
assert.equal(body, 'temp_landing', 'Got temporary landing content')
passed += 1
done()
})
// Prevent bouncing.
request({uri:server+'/nope', jar: jar, headers: {cookie: 'foo=bar'}, followRedirect:false}, function (er, res, body) {
try {
assert.ok(hits.nope, 'Original request to /nope')
assert.ok(!hits.nope_landing, 'No chasing the redirect')
assert.equal(res.statusCode, 302, 'Response is the bounce itself')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode !== 302) throw new Error('Status is not 302: '+res.statusCode)
assert.ok(hits.nope, 'Original request to /nope')
assert.ok(!hits.nope_landing, 'No chasing the redirect')
assert.equal(res.statusCode, 302, 'Response is the bounce itself')
passed += 1
done()
})
// Should not follow post redirects by default
request.post(server+'/temp', { jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect when post')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode !== 301) throw new Error('Status is not 301: '+res.statusCode)
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect when post')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
done()
})
// Should follow post redirects when followAllRedirects true
request.post({uri:server+'/temp', followAllRedirects:true, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
assert.equal(body, 'temp_landing', 'Got temporary landing content')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode !== 200) throw new Error('Status is not 200: '+res.statusCode)
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
assert.equal(body, 'temp_landing', 'Got temporary landing content')
passed += 1
done()
})
request.post({uri:server+'/temp', followAllRedirects:false, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode !== 301) throw new Error('Status is not 301: '+res.statusCode)
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
done()
})

@@ -120,34 +118,31 @@

request.del(server+'/temp', { jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect when delete')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode < 301) throw new Error('Status is not a redirect.')
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect when delete')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
done()
})
// Should not follow delete redirects even if followRedirect is set to true
request.del(server+'/temp', { followRedirect: true, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect when delete')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode !== 301) throw new Error('Status is not 301: '+res.statusCode)
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(!hits.temp_landing, 'No chasing the redirect when delete')
assert.equal(res.statusCode, 301, 'Response is the bounce itself')
passed += 1
done()
})
// Should follow delete redirects when followAllRedirects true
request.del(server+'/temp', {followAllRedirects:true, jar: jar, headers: {cookie: 'foo=bar'}}, function (er, res, body) {
try {
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
assert.equal(body, 'temp_landing', 'Got temporary landing content')
passed += 1
} finally {
done()
}
if (er) throw er
if (res.statusCode !== 200) throw new Error('Status is not 200: '+res.statusCode)
assert.ok(hits.temp, 'Original request is to /temp')
assert.ok(hits.temp_landing, 'Forward to temporary landing URL')
assert.equal(body, 'temp_landing', 'Got temporary landing content')
passed += 1
done()
})

@@ -154,0 +149,0 @@

@@ -24,18 +24,23 @@ /*!

// First key is the name
this.name = str.substr(0, str.indexOf('=')).trim();
// Map the key/val pairs
str.split(/ *; */).reduce(function(obj, pair){
var p = pair.indexOf('=');
if(p > 0)
obj[pair.substring(0, p).trim()] = pair.substring(p + 1).trim();
else
obj[pair.trim()] = true;
var key = p > 0 ? pair.substring(0, p).trim() : pair.trim();
var lowerCasedKey = key.toLowerCase();
var value = p > 0 ? pair.substring(p + 1).trim() : true;
if (!obj.name) {
// First key is the name
obj.name = key;
obj.value = value;
}
else if (lowerCasedKey === 'httponly') {
obj.httpOnly = value;
}
else {
obj[lowerCasedKey] = value;
}
return obj;
}, this);
// Assign value
this.value = this[this.name];
// Expires

@@ -42,0 +47,0 @@ this.expires = this.expires

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc