Comparing version 2.32.0 to 2.33.0
13
index.js
@@ -15,8 +15,3 @@ // Copyright 2010-2012 Mikeal Rogers | ||
var optional = require('./lib/optional') | ||
, cookie = optional('tough-cookie') | ||
, Cookie = cookie && cookie.Cookie | ||
, CookieJar = cookie && cookie.CookieJar | ||
, cookieJar = CookieJar && new CookieJar | ||
var cookies = require('./lib/cookies') | ||
, copy = require('./lib/copy') | ||
@@ -152,8 +147,6 @@ , Request = require('./request') | ||
request.jar = function () { | ||
return new CookieJar | ||
return cookies.jar(); | ||
} | ||
request.cookie = function (str) { | ||
if (str && str.uri) str = str.uri | ||
if (typeof str !== 'string') throw new Error("The cookie function only accepts STRING as param") | ||
return new Cookie(str) | ||
return cookies.parse(str); | ||
} |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "2.32.0", | ||
"version": "2.33.0", | ||
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>", | ||
@@ -32,3 +32,3 @@ "repository": { | ||
"optionalDependencies": { | ||
"tough-cookie": "~0.9.15", | ||
"tough-cookie": ">=0.12.0", | ||
"form-data": "~0.1.0", | ||
@@ -35,0 +35,0 @@ "tunnel-agent": "~0.3.0", |
@@ -355,10 +355,9 @@ # Request -- Simplified HTTP client | ||
``` | ||
OR | ||
Note that `setCookie` requires at least three parameters, and the last is required to be a callback. | ||
```javascript | ||
var j = request.jar() | ||
var cookie = request.cookie('your_cookie_here') | ||
j.setCookie(cookie, uri, function (err, cookie){}) | ||
j.setCookie(cookie, uri); | ||
request({url: 'http://www.google.com', jar: j}, function () { | ||
@@ -365,0 +364,0 @@ request('http://images.google.com') |
@@ -14,3 +14,3 @@ var optional = require('./lib/optional') | ||
, hawk = optional('hawk') | ||
, aws = optional('aws-sign') | ||
, aws = optional('aws-sign2') | ||
, httpSignature = optional('http-signature') | ||
@@ -25,5 +25,4 @@ , uuid = require('node-uuid') | ||
, Cookie = optional('tough-cookie') | ||
, CookieJar = Cookie && Cookie.CookieJar | ||
, cookieJar = CookieJar && new CookieJar | ||
, cookies = require('./lib/cookies') | ||
, globalCookieJar = cookies.jar() | ||
@@ -284,3 +283,3 @@ , copy = require('./lib/copy') | ||
if (Object.prototype.hasOwnProperty.call(options.auth, 'password')) options.auth.pass = options.auth.password | ||
self.auth( | ||
@@ -657,14 +656,10 @@ options.auth.user, | ||
var targetCookieJar = (self._jar && self._jar.setCookie)?self._jar:globalCookieJar; | ||
var addCookie = function (cookie) { | ||
if (self._jar){ | ||
var targetCookieJar = self._jar.setCookie?self._jar:cookieJar; | ||
//set the cookie if it's domain in the href's domain. | ||
targetCookieJar.setCookie(cookie, self.uri.href, function(err){ | ||
if (err){ | ||
console.warn('set cookie failed,'+ err) | ||
} | ||
}) | ||
//set the cookie if it's domain in the href's domain. | ||
try { | ||
targetCookieJar.setCookie(cookie, self.uri.href); | ||
} catch (e) { | ||
self.emit('error', e); | ||
} | ||
} | ||
@@ -700,7 +695,7 @@ | ||
var authHeader = response.headers[hasHeader('www-authenticate', response.headers)] | ||
var authVerb = authHeader && authHeader.split(' ')[0] | ||
var authVerb = authHeader && authHeader.split(' ')[0].toLowerCase() | ||
debug('reauth', authVerb) | ||
switch (authVerb) { | ||
case 'Basic': | ||
case 'basic': | ||
self.auth(self._user, self._pass, true) | ||
@@ -710,3 +705,3 @@ redirectTo = self.uri | ||
case 'Digest': | ||
case 'digest': | ||
// TODO: More complete implementation of RFC 2617. | ||
@@ -1191,14 +1186,8 @@ // - check challenge.algorithm | ||
} else { | ||
var targetCookieJar = (jar && jar.getCookieString)?jar:cookieJar; | ||
var targetCookieJar = (jar && jar.getCookieString)?jar:globalCookieJar; | ||
var urihref = this.uri.href | ||
//fetch cookie in the Specified host | ||
targetCookieJar.getCookieString(urihref, function(err, hrefCookie){ | ||
if (err){ | ||
console.warn('get cookieString failed,' +err) | ||
} else { | ||
cookies = hrefCookie | ||
} | ||
}) | ||
if (targetCookieJar) { | ||
cookies = targetCookieJar.getCookieString(urihref); | ||
} | ||
} | ||
@@ -1205,0 +1194,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
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
68738
13
1307
366