Skip to content

Commit

Permalink
Fixing redirect issue, thanks @linus
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Feb 14, 2011
1 parent ee2108d commit 5f838b3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Request.prototype.request = function () {

options.httpModule =
{"http:":http, "https:":https}[options.proxy ? options.proxy.protocol : options.uri.protocol]

if (!options.httpModule) throw new Error("Invalid protocol");

if (options.pool === false) {
Expand All @@ -175,7 +176,7 @@ Request.prototype.request = function () {
options.req = options.httpModule.request(options, function (response) {
options.response = response;
if (setHost) delete options.headers.host;

if (response.statusCode >= 300 &&
response.statusCode < 400 &&
options.followRedirect &&
Expand All @@ -191,6 +192,7 @@ Request.prototype.request = function () {
}
options.uri = response.headers.location;
delete options.req;
delete options.agent;
if (options.headers) {
delete options.headers.host;
}
Expand Down Expand Up @@ -218,9 +220,12 @@ Request.prototype.request = function () {
}
if (options.callback) {
var buffer = '';
response
.on("data", function (chunk) { buffer += chunk; })
.on("end", function () { options.callback(null, response, buffer); })
response.on("data", function (chunk) {
buffer += chunk;
})
response.on("end", function () {
options.callback(null, response, buffer);
})
;
}
}
Expand Down

0 comments on commit 5f838b3

Please sign in to comment.