Comparing version 2.2.9 to 2.9.0
21
main.js
@@ -29,2 +29,6 @@ // Copyright 2010-2011 Mikeal Rogers | ||
; | ||
if (process.logging) { | ||
var log = process.logging('request') | ||
} | ||
@@ -304,5 +308,8 @@ try { | ||
self.httpModule = | ||
{"http:":http, "https:":https}[self.proxy ? self.proxy.protocol : self.uri.protocol] | ||
var protocol = self.proxy ? self.proxy.protocol : self.uri.protocol | ||
, defaultModules = {'http:':http, 'https:':https} | ||
, httpModules = self.httpModules || {} | ||
self.httpModule = httpModules[protocol] || defaultModules[protocol] | ||
if (!self.httpModule) throw new Error("Invalid protocol") | ||
@@ -328,3 +335,3 @@ | ||
self.method = self.method || 'GET' | ||
if (log) log('%method %uri', self) | ||
self.req = self.httpModule.request(self, function (response) { | ||
@@ -382,2 +389,3 @@ self.response = response | ||
} | ||
if (log) log('Redirect to %uri', self) | ||
request(self, self.callback) | ||
@@ -431,2 +439,3 @@ return // Ignore the rest of the response | ||
if (log) log('Response %statusCode', response) | ||
self.emit('response', response) | ||
@@ -452,3 +461,7 @@ | ||
}) | ||
response.body = body.toString() | ||
if (self.encoding === null) { | ||
response.body = body | ||
} else { | ||
response.body = body.toString() | ||
} | ||
} else if (buffer.length) { | ||
@@ -455,0 +468,0 @@ response.body = buffer.join('') |
{ "name" : "request" | ||
, "description" : "Simplified HTTP request client." | ||
, "tags" : ["http", "simple", "util", "utility"] | ||
, "version" : "2.2.9" | ||
, "version" : "2.9.0" | ||
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "repository" : |
@@ -157,3 +157,3 @@ # Request -- Simplified HTTP request method | ||
* `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 response.setEncoding when buffering the response data. | ||
* `encoding` - Encoding to be used on `setEncoding` of response data. If set to `null`, the body is returned as a Buffer. | ||
* `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. | ||
@@ -168,3 +168,3 @@ * `pool.maxSockets` - Integer containing the maximum amount of sockets in the pool. | ||
The callback argument gets 3 arguments. The first is an error when applicable (usually from the http.Client option not the http.ClientRequest object). The second in an http.ClientResponse object. The third is the response body buffer. | ||
The callback argument gets 3 arguments. The first is an error when applicable (usually from the http.Client option not the http.ClientRequest object). The second in an http.ClientResponse object. The third is the response body String or Buffer. | ||
@@ -171,0 +171,0 @@ ## Convenience methods |
@@ -1,2 +0,5 @@ | ||
var http = require('http') | ||
var fs = require('fs') | ||
, http = require('http') | ||
, path = require('path') | ||
, https = require('https') | ||
, events = require('events') | ||
@@ -17,2 +20,17 @@ , stream = require('stream') | ||
exports.createSSLServer = function(port) { | ||
port = port || 16767 | ||
var options = { 'key' : fs.readFileSync(path.join(__dirname, 'ssl', 'test.key')) | ||
, 'cert': fs.readFileSync(path.join(__dirname, 'ssl', 'test.crt')) | ||
} | ||
var s = https.createServer(options, function (req, resp) { | ||
s.emit(req.url, req, resp); | ||
}) | ||
s.port = port | ||
s.url = 'https://localhost:'+port | ||
return s; | ||
} | ||
exports.createPostStream = function (text) { | ||
@@ -19,0 +37,0 @@ var postStream = new stream.Stream(); |
@@ -28,7 +28,12 @@ var server = require('./server') | ||
} | ||
, testGetBuffer : | ||
{ resp : server.createGetResponse(new Buffer("TESTING!")) | ||
, encoding: null | ||
, expectBody: new Buffer("TESTING!") | ||
} | ||
, testGetJSON : | ||
{ resp : server.createGetResponse('{"test":true}', 'application/json') | ||
, json : true | ||
, expectBody: {"test":true} | ||
} | ||
{ resp : server.createGetResponse('{"test":true}', 'application/json') | ||
, json : true | ||
, expectBody: {"test":true} | ||
} | ||
, testPutString : | ||
@@ -35,0 +40,0 @@ { resp : server.createPostValidator("PUTTINGDATA") |
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); | ||
@@ -20,3 +20,3 @@ | ||
// test .value | ||
assert.equal(cookie.value, 's543qactge.wKE61E01Bs%2BKhzmxrwrnug'); | ||
assert.equal(cookie.value, '"s543qactge.wKE61E01Bs%2BKhzmxrwrnug="'); | ||
@@ -23,0 +23,0 @@ // test .expires |
@@ -59,3 +59,3 @@ var hmacsign = require('../oauth').hmacsign | ||
var r = request.post( | ||
var rsign = request.post( | ||
{ url: 'https://api.twitter.com/oauth/request_token' | ||
@@ -72,6 +72,8 @@ , oauth: | ||
console.log(getsignature(r)) | ||
assert.equal(reqsign, getsignature(r)) | ||
setTimeout(function () { | ||
console.log(getsignature(rsign)) | ||
assert.equal(reqsign, getsignature(rsign)) | ||
}) | ||
var r = request.post( | ||
var raccsign = request.post( | ||
{ url: 'https://api.twitter.com/oauth/access_token' | ||
@@ -91,6 +93,8 @@ , oauth: | ||
console.log(getsignature(r)) | ||
assert.equal(accsign, getsignature(r)) | ||
setTimeout(function () { | ||
console.log(getsignature(raccsign)) | ||
assert.equal(accsign, getsignature(raccsign)) | ||
}, 1) | ||
var r = request.post( | ||
var rupsign = request.post( | ||
{ url: 'http://api.twitter.com/1/statuses/update.json' | ||
@@ -109,5 +113,9 @@ , oauth: | ||
}) | ||
setTimeout(function () { | ||
console.log(getsignature(rupsign)) | ||
assert.equal(upsign, getsignature(rupsign)) | ||
}, 1) | ||
console.log(getsignature(r)) | ||
assert.equal(upsign, getsignature(r)) | ||
@@ -166,3 +166,18 @@ var server = require('./server') | ||
}) | ||
s.on('/forward1', function (req, resp) { | ||
resp.writeHead(302, {location:'/forward2'}) | ||
resp.end() | ||
}) | ||
s.on('/forward2', function (req, resp) { | ||
resp.writeHead('200', {'content-type':'image/png'}) | ||
resp.write('d') | ||
resp.end() | ||
}) | ||
counter++ | ||
var validateForward = new ValidationStream('d') | ||
validateForward.on('end', check) | ||
request.get('http://localhost:3453/forward1').pipe(validateForward) | ||
}) |
@@ -25,9 +25,12 @@ /*! | ||
// First key is the name | ||
this.name = str.substr(0, str.indexOf('=')); | ||
this.name = str.substr(0, str.indexOf('=')).trim(); | ||
// Map the key/val pairs | ||
str.split(/ *; */).reduce(function(obj, pair){ | ||
pair = pair.split(/ *= */); | ||
obj[pair[0].toLowerCase()] = pair[1] || true; | ||
return obj; | ||
var p = pair.indexOf('='); | ||
if(p > 0) | ||
obj[pair.substring(0, p).trim()] = pair.substring(p + 1).trim(); | ||
else | ||
obj[pair.trim()] = true; | ||
return obj; | ||
}, this); | ||
@@ -44,3 +47,5 @@ | ||
// Default or trim path | ||
this.path = this.path || '/'; | ||
this.path = this.path | ||
? this.path.trim(): req | ||
? url.parse(req.url).pathname: '/'; | ||
}; | ||
@@ -47,0 +52,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
113980
25
1723
0
3
8