request
Advanced tools
Comparing version 2.2.5 to 2.2.6
75
main.js
@@ -154,3 +154,9 @@ // Copyright 2010-2011 Mikeal Rogers | ||
} | ||
if (cookies) {self.headers.Cookie = cookies} | ||
if (cookies) { | ||
var cookieString = cookies.map(function (c) { | ||
return c.name + "=" + c.value; | ||
}).join("; "); | ||
self.headers.Cookie = cookieString; | ||
} | ||
@@ -202,4 +208,4 @@ if (!self.uri.pathname) {self.uri.pathname = '/'} | ||
var oa = {} | ||
for (i in form) oa[i] = form[i] | ||
for (i in self.oauth) oa['oauth_'+i] = self.oauth[i] | ||
for (var i in form) oa[i] = form[i] | ||
for (var i in self.oauth) oa['oauth_'+i] = self.oauth[i] | ||
if (!oa.oauth_version) oa.oauth_version = '1.0' | ||
@@ -220,3 +226,3 @@ if (!oa.oauth_timestamp) oa.oauth_timestamp = Math.floor( (new Date()).getTime() / 1000 ).toString() | ||
// oa.oauth_signature = signature | ||
for (i in form) { | ||
for (var i in form) { | ||
if ( i.slice(0, 'oauth_') in self.oauth) { | ||
@@ -259,3 +265,3 @@ // skip | ||
} else if (self.multipart) { | ||
self.body = '' | ||
self.body = []; | ||
self.headers['content-type'] = 'multipart/related;boundary="frontier"' | ||
@@ -268,17 +274,30 @@ if (!self.multipart.forEach) throw new Error('Argument error, options.multipart.') | ||
delete part.body | ||
self.body += '--frontier\r\n' | ||
var preamble = '--frontier\r\n' | ||
Object.keys(part).forEach(function(key){ | ||
self.body += key + ': ' + part[key] + '\r\n' | ||
preamble += key + ': ' + part[key] + '\r\n' | ||
}) | ||
self.body += '\r\n' + body + '\r\n' | ||
preamble += '\r\n'; | ||
self.body.push(new Buffer(preamble)); | ||
self.body.push(new Buffer(body)); | ||
self.body.push(new Buffer('\r\n')); | ||
}) | ||
self.body += '--frontier--' | ||
self.body.push(new Buffer('--frontier--')); | ||
} | ||
if (self.body) { | ||
var length = 0; | ||
if (!Buffer.isBuffer(self.body)) { | ||
self.body = new Buffer(self.body) | ||
if (Array.isArray(self.body)) { | ||
for (var i = 0; i < self.body.length; i++) { | ||
length += self.body[i].length; | ||
} | ||
} else { | ||
self.body = new Buffer(self.body) | ||
length = self.body.length; | ||
} | ||
} else { | ||
length = self.body.length; | ||
} | ||
if (self.body.length) { | ||
self.headers['content-length'] = self.body.length | ||
if (length) { | ||
self.headers['content-length'] = length; | ||
} else { | ||
@@ -327,2 +346,15 @@ throw new Error('Argument error, options.body.') | ||
if (self.timeout && self.timeoutTimer) clearTimeout(self.timeoutTimer) | ||
if (response.headers['set-cookie'] && (!self._disableCookies)) { | ||
response.headers['set-cookie'].forEach(function(cookie) { | ||
if (self.jar) { | ||
// custom defined jar | ||
self.jar.add(new Cookie(cookie)); | ||
} | ||
else { | ||
// add to the global cookie jar if user don't define his own | ||
cookieJar.add(new Cookie(cookie)); | ||
} | ||
}); | ||
} | ||
@@ -431,13 +463,2 @@ if (response.statusCode >= 300 && | ||
} | ||
if (response.statusCode == 200 && response.headers['set-cookie'] && (!self._disableCookies)) { | ||
response.headers['set-cookie'].forEach(function(cookie) { | ||
if (self.jar) { | ||
// custom defined jar | ||
self.jar.add(new Cookie(cookie)); | ||
} else { | ||
// add to the global cookie jar if user don't define his own | ||
cookieJar.add(new Cookie(cookie)); | ||
} | ||
}); | ||
} | ||
@@ -488,3 +509,9 @@ self.callback(null, response, response.body) | ||
if (self.body) { | ||
self.write(self.body) | ||
if (Array.isArray(self.body)) { | ||
self.body.forEach(function(part) { | ||
self.write(part); | ||
}); | ||
} else { | ||
self.write(self.body) | ||
} | ||
self.end() | ||
@@ -491,0 +518,0 @@ } else if (self.requestBodyStream) { |
@@ -16,3 +16,3 @@ var crypto = require('crypto') | ||
// big WTF here with the escape + encoding but it's what twitter wants | ||
return encodeURIComponent(qs.escape(i)) + "%3D" + encodeURIComponent(qs.escape(params[i])) | ||
return encodeURIComponent(escape(i)) + "%3D" + encodeURIComponent(escape(params[i])) | ||
}).join("%26") | ||
@@ -19,0 +19,0 @@ var key = consumer_secret + '&' |
{ "name" : "request" | ||
, "description" : "Simplified HTTP request client." | ||
, "tags" : ["http", "simple", "util", "utility"] | ||
, "version" : "2.2.5" | ||
, "version" : "2.2.6" | ||
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "repository" : |
@@ -240,3 +240,3 @@ # Request -- Simplified HTTP request method | ||
{ method: 'PUT' | ||
, uri: 'http://mikeal.couchone.com/testjs/' + rand | ||
, uri: 'http://mikeal.iriscouch.com/testjs/' + rand | ||
, multipart: | ||
@@ -251,3 +251,3 @@ [ { 'content-type': 'application/json' | ||
if(response.statusCode == 201){ | ||
console.log('document saved as: http://mikeal.couchone.com/testjs/'+ rand) | ||
console.log('document saved as: http://mikeal.iriscouch.com/testjs/'+ rand) | ||
} else { | ||
@@ -254,0 +254,0 @@ console.log('error: '+ response.statusCode) |
@@ -30,3 +30,3 @@ /*! | ||
pair = pair.split(/ *= */); | ||
obj[pair[0]] = pair[1] || true; | ||
obj[pair[0].toLowerCase()] = pair[1] || true; | ||
return obj; | ||
@@ -44,5 +44,3 @@ }, this); | ||
// Default or trim path | ||
this.path = this.path | ||
? this.path.trim() | ||
: url.parse(req.url).pathname; | ||
this.path = this.path || '/'; | ||
}; | ||
@@ -49,0 +47,0 @@ |
103587
1434
286