Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-03-15 02:55:13 +0400
committerisaacs <i@izs.me>2012-03-15 02:55:13 +0400
commitfcf85f7b376edd742b42bba582cfc3cb7cb0d68a (patch)
treeffbea47407fbb6b124b9cac8af74a426f9176495 /node_modules/request
parentab8738876d90a53250cf92ec31bbd49af333987b (diff)
Update request from git
Diffstat (limited to 'node_modules/request')
-rw-r--r--node_modules/request/main.js121
-rw-r--r--node_modules/request/package.json8
-rw-r--r--node_modules/request/vendor/cookie/index.js25
3 files changed, 120 insertions, 34 deletions
diff --git a/node_modules/request/main.js b/node_modules/request/main.js
index f65120274..5a6bd9eb0 100644
--- a/node_modules/request/main.js
+++ b/node_modules/request/main.js
@@ -137,12 +137,12 @@ Request.prototype.init = function (options) {
// do the HTTP CONNECT dance using koichik/node-tunnel
if (http.globalAgent && self.uri.protocol === "https:") {
- self.tunnel = true
var tunnelFn = self.proxy.protocol === "http:"
? tunnel.httpsOverHttp : tunnel.httpsOverHttps
var tunnelOptions = { proxy: { host: self.proxy.hostname
- , port: +self.proxy.port }
+ , port: +self.proxy.port
+ , proxyAuth: self.proxy.auth }
, ca: this.ca }
self.agent = tunnelFn(tunnelOptions)
@@ -170,7 +170,7 @@ Request.prototype.init = function (options) {
self.setHost = true
}
- self.jar(options.jar)
+ self.jar(self._jar || options.jar)
if (!self.uri.pathname) {self.uri.pathname = '/'}
if (!self.uri.port) {
@@ -348,6 +348,70 @@ Request.prototype.init = function (options) {
})
}
+// Must call this when following a redirect from https to http or vice versa
+// Attempts to keep everything as identical as possible, but update the
+// httpModule, Tunneling agent, and/or Forever Agent in use.
+Request.prototype._updateProtocol = function () {
+ var self = this
+ var protocol = self.uri.protocol
+
+ if (protocol === 'https:') {
+ // previously was doing http, now doing https
+ // if it's https, then we might need to tunnel now.
+ if (self.proxy) {
+ self.tunnel = true
+ var tunnelFn = self.proxy.protocol === 'http:'
+ ? tunnel.httpsOverHttp : tunnel.httpsOverHttps
+ var tunnelOptions = { proxy: { host: self.proxy.hostname
+ , post: +self.proxy.port
+ , proxyAuth: self.proxy.auth }
+ , ca: self.ca }
+ self.agent = tunnelFn(tunnelOptions)
+ return
+ }
+
+ self.httpModule = https
+ switch (self.agentClass) {
+ case ForeverAgent:
+ self.agentClass = ForeverAgent.SSL
+ break
+ case http.Agent:
+ self.agentClass = https.Agent
+ break
+ default:
+ // nothing we can do. Just hope for the best.
+ return
+ }
+
+ // if there's an agent, we need to get a new one.
+ if (self.agent) self.agent = self.getAgent()
+
+ } else {
+ if (log) log('previously https, now http')
+ // previously was doing https, now doing http
+ // stop any tunneling.
+ if (self.tunnel) self.tunnel = false
+ self.httpModule = http
+ switch (self.agentClass) {
+ case ForeverAgent.SSL:
+ self.agentClass = ForeverAgent
+ break
+ case https.Agent:
+ self.agentClass = http.Agent
+ break
+ default:
+ // nothing we can do. just hope for the best
+ return
+ }
+
+ // if there's an agent, then get a new one.
+ if (self.agent) {
+ self.agent = null
+ self.agent = self.getAgent()
+ }
+ }
+}
+
Request.prototype.getAgent = function () {
var Agent = this.agentClass
var options = {}
@@ -373,7 +437,11 @@ Request.prototype.getAgent = function () {
poolKey += this.host + ':' + this.port
}
- if (options.ca) {
+ // ca option is only relevant if proxy or destination are https
+ var proxy = this.proxy
+ if (typeof proxy === 'string') proxy = url.parse(proxy)
+ var caRelevant = (proxy && proxy.protocol === 'https:') || this.uri.protocol === 'https:'
+ if (options.ca && caRelevant) {
if (poolKey) poolKey += ':'
poolKey += options.ca
}
@@ -383,6 +451,9 @@ Request.prototype.getAgent = function () {
return this.httpModule.globalAgent
}
+ // we're using a stored agent. Make sure it's protocol-specific
+ poolKey = this.uri.protocol + poolKey
+
// already generated an agent for this setting
if (this.pool[poolKey]) return this.pool[poolKey]
@@ -439,7 +510,15 @@ Request.prototype.start = function () {
if (!isUrl.test(response.headers.location)) {
response.headers.location = url.resolve(self.uri.href, response.headers.location)
}
- self.uri = response.headers.location
+
+ var uriPrev = self.uri
+ self.uri = url.parse(response.headers.location)
+
+ // handle the case where we change protocol from https to http or vice versa
+ if (self.uri.protocol !== uriPrev.protocol) {
+ self._updateProtocol()
+ }
+
self.redirects.push(
{ statusCode : response.statusCode
, redirectUri: response.headers.location
@@ -449,6 +528,7 @@ Request.prototype.start = function () {
delete self.req
delete self.agent
delete self._started
+ delete self.body
if (self.headers) {
delete self.headers.host
}
@@ -598,17 +678,17 @@ Request.prototype.setHeaders = function (headers) {
return this
}
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
}
Request.prototype.form = function (form) {
@@ -787,6 +867,7 @@ function initParams(uri, options, callback) {
}
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;
if (typeof options === 'object') {
options.uri = uri;
@@ -841,12 +922,12 @@ request.get = request
request.post = function (uri, options, callback) {
var params = initParams(uri, options, callback);
params.options.method = 'POST';
- return request(params.uri, params.options, params.callback)
+ return request(params.uri || null, params.options, params.callback)
}
request.put = function (uri, options, callback) {
var params = initParams(uri, options, callback);
params.options.method = 'PUT'
- return request(params.uri, params.options, params.callback)
+ return request(params.uri || null, params.options, params.callback)
}
request.head = function (uri, options, callback) {
var params = initParams(uri, options, callback);
@@ -857,12 +938,12 @@ request.head = function (uri, options, callback) {
params.options.multipart) {
throw new Error("HTTP HEAD requests MUST NOT include a request body.")
}
- return request(params.uri, params.options, params.callback)
+ return request(params.uri || null, params.options, params.callback)
}
request.del = function (uri, options, callback) {
var params = initParams(uri, options, callback);
params.options.method = 'DELETE'
- return request(params.uri, params.options, params.callback)
+ return request(params.uri || null, params.options, params.callback)
}
request.jar = function () {
return new CookieJar
diff --git a/node_modules/request/package.json b/node_modules/request/package.json
index 4a62c5a46..0e6ddc5d8 100644
--- a/node_modules/request/package.json
+++ b/node_modules/request/package.json
@@ -35,11 +35,11 @@
"devDependencies": {},
"optionalDependencies": {},
"_engineSupported": true,
- "_npmVersion": "1.1.2",
- "_nodeVersion": "v0.7.6-pre",
+ "_npmVersion": "1.1.8",
+ "_nodeVersion": "v0.6.12",
"_defaultsLoaded": true,
"dist": {
- "shasum": "d1f4855a90a9e69bf6cd2a68503e253cc4a27a71"
+ "shasum": "6f07c2ba3acfbe0cfe941f43647102740f05ff73"
},
- "_from": "request@~2.9"
+ "_from": "../request"
}
diff --git a/node_modules/request/vendor/cookie/index.js b/node_modules/request/vendor/cookie/index.js
index 1eb2eaa22..ff44b3e62 100644
--- a/node_modules/request/vendor/cookie/index.js
+++ b/node_modules/request/vendor/cookie/index.js
@@ -21,22 +21,27 @@ var url = require('url');
var Cookie = exports = module.exports = function Cookie(str, req) {
this.str = str;
- // 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
this.expires = this.expires
? new Date(this.expires)