Comparing version 0.4.4 to 0.5.0
0.5.0 / 2013-08-11 | ||
================== | ||
* Support max redirects to protect loop redirect | ||
* Auto redirect handle (@ibigbug) | ||
0.4.4 / 2013-08-10 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -74,2 +74,4 @@ /** | ||
* - {String} [passphrase]: A string of passphrase for the private key or pfx. | ||
* - {Boolean} [followRedirect]: Follow HTTP 3xx responses as redirects. defaults to false. | ||
* - {Number} [maxRedirects]: The maximum number of redirects to follow, defaults to 10. | ||
* @param {Function} callback, callback(error, data, res) | ||
@@ -88,2 +90,3 @@ * @return {HttpRequest} req object. | ||
args.timeout = args.timeout || exports.TIMEOUT; | ||
args.maxRedirects = args.maxRedirects || 10; | ||
var parsedUrl = typeof url === 'string' ? urlutil.parse(url) : url; | ||
@@ -254,2 +257,18 @@ | ||
var err = null; | ||
if ((res.statusCode === 302 || res.statusCode === 301) && args.followRedirect) { // handle redirect | ||
args._followRedirectCount = (args._followRedirectCount || 0) + 1; | ||
if (!res.headers.location) { | ||
err = new Error('Got statusCode ' + res.statusCode + ' but cannot resolve next location from headers'); | ||
err.name = 'FollowRedirectError'; | ||
} else if (args._followRedirectCount > args.maxRedirects) { | ||
err = new Error('Exceeded maxRedirects. Probably stuck in a redirect loop ' + url); | ||
err.name = 'MaxRedirectError'; | ||
} else { | ||
var _url = urlutil.resolve(url, res.headers.location); | ||
debug('Request#%d %s: `redirected` from %s to %s', reqId, options.path, url, _url); | ||
return exports.request(_url, args, callback); | ||
} | ||
} | ||
if (args.dataType === 'json') { | ||
@@ -256,0 +275,0 @@ if (size === 0) { |
{ | ||
"name": "urllib", | ||
"version": "0.4.4", | ||
"version": "0.5.0", | ||
"description": "Help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more.", | ||
@@ -5,0 +5,0 @@ "keywords": [ "urllib", "http", "urlopen", "curl", "wget", "request", "https" ], |
@@ -66,2 +66,4 @@ # urllib | ||
- ***passphrase*** String - A string of passphrase for the private key or pfx. | ||
- ***followRedirect*** Boolean - follow HTTP 3xx responses as redirects. defaults to false. | ||
- ***maxRedirects*** Number - The maximum number of redirects to follow, defaults to 10. | ||
- ***callback(err, data, res)*** Function - Optional callback. | ||
@@ -184,3 +186,3 @@ - **err** Error - Would be `null` if no error accured. | ||
* [√] Upload file like form upload | ||
* [ ] Auto redirect handle | ||
* [√] Auto redirect handle | ||
* [√] https & self-signed certificate | ||
@@ -197,10 +199,11 @@ | ||
repo age : 2 years, 3 months | ||
active : 32 days | ||
commits : 89 | ||
active : 33 days | ||
commits : 103 | ||
files : 17 | ||
authors : | ||
75 fengmk2 84.3% | ||
9 XiNGRZ 10.1% | ||
4 Jackson Tian 4.5% | ||
1 aleafs 1.1% | ||
83 fengmk2 80.6% | ||
9 XiNGRZ 8.7% | ||
6 ibigbug 5.8% | ||
4 Jackson Tian 3.9% | ||
1 aleafs 1.0% | ||
``` | ||
@@ -207,0 +210,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
25209
293
232