request
Advanced tools
Comparing version 1.9.8 to 1.9.9
31
main.js
@@ -22,2 +22,3 @@ // Copyright 2010-2011 Mikeal Rogers | ||
, qs = require('querystring') | ||
, mimetypes = require('./mimetypes') | ||
; | ||
@@ -54,2 +55,8 @@ | ||
var isReadStream = function (rs) { | ||
if (rs.readable && rs.path && rs.mode) { | ||
return true; | ||
} | ||
} | ||
var isUrl = /^https?:/; | ||
@@ -202,7 +209,9 @@ | ||
if (options.maxSockets) { | ||
options.agent = options.getAgent(options.host, options.port); | ||
// Don't use our pooling if node has the refactored client | ||
options.agent = options.httpModule.globalAgent || options.getAgent(options.host, options.port); | ||
options.agent.maxSockets = options.maxSockets; | ||
} | ||
if (options.pool.maxSockets) { | ||
options.agent = options.getAgent(options.host, options.port); | ||
// Don't use our pooling if node has the refactored client | ||
options.agent = options.httpModule.globalAgent || options.getAgent(options.host, options.port); | ||
options.agent.maxSockets = options.pool.maxSockets; | ||
@@ -217,2 +226,3 @@ } | ||
if (setHost) delete options.headers.host; | ||
if (options.timeout && options.timeoutTimer) clearTimeout(options.timeoutTimer); | ||
@@ -261,2 +271,9 @@ if (response.statusCode >= 300 && | ||
} | ||
} | ||
if (dest.setHeader) { | ||
dest.setHeader('content-type', response.headers['content-type']); | ||
if (response.headers['content-length']) { | ||
dest.setHeader('content-length', response.headers['content-length']); | ||
} | ||
dest.statusCode = response.statusCode; | ||
} | ||
@@ -285,2 +302,9 @@ }) | ||
if (options.timeout) { | ||
options.timeoutTimer = setTimeout(function() { | ||
options.req.abort(); | ||
options.emit("error", "ETIMEDOUT"); | ||
}, options.timeout); | ||
} | ||
options.req.on('error', clientErrorHandler); | ||
@@ -292,2 +316,5 @@ } | ||
options.src = src; | ||
if (isReadStream(src)) { | ||
options.headers['content-type'] = mimetypes.lookup(src.path.slice(src.path.lastIndexOf('.')+1)) | ||
} | ||
options.on('pipe', function () { | ||
@@ -294,0 +321,0 @@ console.error("You have already piped to this stream. Pipeing twice is likely to break the request.") |
{ "name" : "request" | ||
, "description" : "Simplified HTTP request client." | ||
, "tags" : ["http", "simple", "util", "utility"] | ||
, "version" : "1.9.8" | ||
, "version" : "1.9.9" | ||
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "repository" : |
@@ -46,2 +46,3 @@ # Request -- Simplified HTTP request method | ||
* `pool.maxSockets` - Integer containing the maximum amount of sockets in the pool. | ||
* `timeout` - Integer containing the number of milliseconds to wait for a request to respond before aborting the request | ||
@@ -48,0 +49,0 @@ 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. |
@@ -5,3 +5,5 @@ var server = require('./server') | ||
, assert = require('assert') | ||
, fs = require('fs') | ||
, request = require('../main.js') | ||
, path = require('path') | ||
; | ||
@@ -13,7 +15,10 @@ | ||
function check () { | ||
if (passes === 3) { | ||
var check = function () { | ||
if (passes === 5) { | ||
console.log('All tests passed.') | ||
process.exit(); | ||
setTimeout(function () { | ||
process.exit(); | ||
}, 500) | ||
} | ||
if (passes > 6) throw new Error('Need to update for more failures') | ||
} | ||
@@ -59,7 +64,7 @@ | ||
if (req.method === "GET") { | ||
resp.writeHead(200, {'content-type':'text/plain', 'content-length':4}); | ||
resp.writeHead(200, {'content-type':'text/plain-test', 'content-length':4}); | ||
resp.write('asdf'); | ||
resp.end() | ||
} else if (req.method === "PUT") { | ||
assert.ok(req.headers['content-type'] === 'text/plain'); | ||
assert.ok(req.headers['content-type'] === 'text/plain-test'); | ||
assert.ok(req.headers['content-length'] == 4) | ||
@@ -77,4 +82,39 @@ var validate = ''; | ||
}) | ||
s.on('/pushjs', function (req, resp) { | ||
if (req.method === "PUT") { | ||
assert.ok(req.headers['content-type'] === 'text/javascript'); | ||
passes += 1; | ||
check(); | ||
} | ||
}) | ||
s.on('/catresp', function (req, resp) { | ||
request.get('http://localhost:3453/cat').pipe(resp) | ||
}) | ||
s.on('/doodle', function (req, resp) { | ||
resp.writeHead('200', {'content-type':'image/png'}) | ||
fs.createReadStream(path.join(__dirname, 'googledoodle.png')).pipe(resp) | ||
}) | ||
fs.createReadStream(__filename).pipe(request.put('http://localhost:3453/pushjs')) | ||
request.get('http://localhost:3453/cat').pipe(request.put('http://localhost:3453/cat')) | ||
request.get('http://localhost:3453/catresp', function (e, resp, body) { | ||
assert.ok(resp.headers['content-type'] === 'text/plain-test'); | ||
assert.ok(resp.headers['content-length'] == 4) | ||
passes += 1 | ||
check(); | ||
}) | ||
var doodleWrite = fs.createWriteStream(path.join(__dirname, 'test.png')) | ||
request.get('http://localhost:3453/doodle').pipe(doodleWrite) | ||
doodleWrite.on('close', function () { | ||
assert.deepEqual(fs.readFileSync(path.join(__dirname, 'googledoodle.png')), fs.readFileSync(path.join(__dirname, 'test.png'))) | ||
check() | ||
}) | ||
process.on('exit', function () { | ||
fs.unlinkSync(path.join(__dirname, 'test.png')) | ||
}) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
82690
14
946
124
1