Permalink
Browse files

Add http#req param followAllRedirects: true to follow non-GET redirec…

…tion.
  • Loading branch information...
1 parent 95a9dda commit b68b48554cce827d1eac4dacd5e7a606e32e8861 @cliffano committed Apr 4, 2013
Showing with 17 additions and 1 deletion.
  1. +1 −0 CHANGELOG.md
  2. +3 −1 lib/http.js
  3. +13 −0 test/http.js
View
@@ -1,5 +1,6 @@
### 0.1.3-pre
* Add http#req wildcard status code handling, e.g. 20x, 3xx
+* Add http#req param followAllRedirects: true to follow non-GET redirection
### 0.1.2
* http#proxy now handles HTTP_PROXY and HTTPS_PROXY along with http_proxy and https_proxy environment variables
View
@@ -3,6 +3,8 @@ var request = require('request');
/**
* Sends a HTTP request to a specified URL with optional proxy, query strings, and handlers.
* Convenient handling of request error and unexpected status code.
+ * GET redirection is handled by default by request module.
+ * Non-GET redirection is handled by params followAllRedirects: true.
*
* @param {String} method: http method
* @param {String} url: URL without query string
@@ -15,7 +17,7 @@ var request = require('request');
function req(method, url, opts, cb) {
opts.handlers = opts.handlers || {};
- var params = { url: url },
+ var params = { url: url, followAllRedirects: true },
envProxy = proxy(url);
if (opts.proxy) {
View
@@ -118,6 +118,19 @@ buster.testCase('http - request', {
assert.equals(result, undefined);
done();
});
+ },
+ 'should follow non-GET redirection': function (done) {
+ this.stub(request, 'post', function (params, cb) {
+ assert.isTrue(params.followAllRedirects);
+ cb(null, { statusCode: 302, body: 'somebody' });
+ });
+ function _redirect(result, cb) {
+ cb(null, result);
+ }
+ http.request('POST', 'http://someurl', { handlers: { 302: _redirect }}, function (err, result) {
+ assert.isNull(err);
+ done();
+ });
}
});

0 comments on commit b68b485

Please sign in to comment.