request
Advanced tools
Comparing version 2.0.0 to 2.0.1
23
main.js
@@ -107,4 +107,3 @@ // Copyright 2010-2011 Mikeal Rogers | ||
options.followRedirect = (options.followRedirect !== undefined) ? options.followRedirect : true; | ||
options.method = options.method || 'GET'; | ||
options.headers = options.headers || {}; | ||
@@ -221,2 +220,5 @@ | ||
options._started = true; | ||
options.method = options.method || 'GET'; | ||
options.req = options.httpModule.request(options, function (response) { | ||
@@ -273,5 +275,4 @@ options.response = response; | ||
if (dest.setHeader) { | ||
dest.setHeader('content-type', response.headers['content-type']); | ||
if (response.headers['content-length']) { | ||
dest.setHeader('content-length', response.headers['content-length']); | ||
for (i in response.headers) { | ||
dest.setHeader(i, response.headers[i]) | ||
} | ||
@@ -318,3 +319,15 @@ dest.statusCode = response.statusCode; | ||
options.headers['content-type'] = mimetypes.lookup(src.path.slice(src.path.lastIndexOf('.')+1)) | ||
} else { | ||
if (src.headers) { | ||
for (i in src.headers) { | ||
if (!options.headers[i]) { | ||
options.headers[i] = src.headers[i] | ||
} | ||
} | ||
} | ||
if (src.method && !options.method) { | ||
options.method = src.method; | ||
} | ||
} | ||
options.on('pipe', function () { | ||
@@ -321,0 +334,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" : "2.0.0" | ||
, "version" : "2.0.1" | ||
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "repository" : |
@@ -15,3 +15,3 @@ var server = require('./server') | ||
var check = function () { | ||
if (passes === 5) { | ||
if (passes === 7) { | ||
console.log('All tests passed.') | ||
@@ -22,3 +22,3 @@ setTimeout(function () { | ||
} | ||
if (passes > 6) throw new Error('Need to update for more failures') | ||
if (passes > 7) throw new Error('Need to update for more failures') | ||
} | ||
@@ -65,4 +65,3 @@ | ||
resp.writeHead(200, {'content-type':'text/plain-test', 'content-length':4}); | ||
resp.write('asdf'); | ||
resp.end() | ||
resp.end('asdf') | ||
} else if (req.method === "PUT") { | ||
@@ -72,2 +71,3 @@ assert.ok(req.headers['content-type'] === 'text/plain-test'); | ||
var validate = ''; | ||
req.on('data', function (chunk) {validate += chunk}) | ||
@@ -94,6 +94,15 @@ req.on('end', function () { | ||
s.on('/doodle', function (req, resp) { | ||
if (req.headers['x-oneline-proxy']) { | ||
resp.setHeader('x-oneline-proxy', 'yup') | ||
} | ||
resp.writeHead('200', {'content-type':'image/png'}) | ||
fs.createReadStream(path.join(__dirname, 'googledoodle.png')).pipe(resp) | ||
}) | ||
s.on('/onelineproxy', function (req, resp) { | ||
var x = request('http://localhost:3453/doodle') | ||
req.pipe(x) | ||
x.pipe(resp) | ||
}) | ||
fs.createReadStream(__filename).pipe(request.put('http://localhost:3453/pushjs')) | ||
@@ -116,2 +125,3 @@ | ||
assert.deepEqual(fs.readFileSync(path.join(__dirname, 'googledoodle.png')), fs.readFileSync(path.join(__dirname, 'test.png'))) | ||
passes += 1 | ||
check() | ||
@@ -122,2 +132,12 @@ }) | ||
fs.unlinkSync(path.join(__dirname, 'test.png')) | ||
}) | ||
}) | ||
request.get({uri:'http://localhost:3453/onelineproxy', headers:{'x-oneline-proxy':'nope'}}, function (err, resp, body) { | ||
assert.ok(resp.headers['x-oneline-proxy'] === 'yup') | ||
passes += 1 | ||
check() | ||
}) | ||
83377
973