Permalink
Browse files

Merge pull request #40 from ma2rten/master

Proper redirects and ip on host header
  • Loading branch information...
2 parents ea1b22f + 18bc9fa commit 1a9bab5c28dbb40a71babae7f75f4e1015083dd1 @chriso chriso committed Aug 6, 2011
Showing with 33 additions and 20 deletions.
  1. +33 −20 lib/node.io/request.js
@@ -233,25 +233,6 @@ Job.prototype.doRequest = function (method, resource, body, headers, callback, p
//Parse the URL into parts
url = urlparse(resource, false),
- //Determine the port
- port = url.port;
- if (!port) {
- switch (url.protocol) {
- case 'http:':
- port = 80;
- break;
- case 'https:':
- port = 443;
- secure = true;
- break;
- case 'ftp:':
- port = 21;
- break;
- default:
- port = 80;
- }
- }
-
//Get the request path
path = url.pathname || '/';
if (url.search) {
@@ -288,6 +269,27 @@ Job.prototype.doRequest = function (method, resource, body, headers, callback, p
headers['Content-Length'] = body.length;
}
+ //Determine the port and add it to the host header
+ port = url.port;
+ if (!port) {
+ switch (url.protocol) {
+ case 'http:':
+ port = 80;
+ break;
+ case 'https:':
+ port = 443;
+ secure = true;
+ break;
+ case 'ftp:':
+ port = 21;
+ break;
+ default:
+ port = 80;
+ }
+ } else {
+ headers.host += ':' + port;
+ }
+
method = method.toUpperCase();
//Debug request headers
@@ -354,7 +356,18 @@ Job.prototype.doRequest = function (method, resource, body, headers, callback, p
if (redirect.host) {
headers.host = redirect.host;
}
- self.doRequest(method, location, body, headers, callback, parse, ++redirects);
+ if (code === 302 || code === 303) {
+ // morph this post request into a get request
+ for (header in headers) {
+ h = header.toLowerCase();
+ if (h === 'content-length' || h === 'content-type') {
+ delete headers[header];
+ }
+ }
+ self.doRequest('GET', location, null, headers, callback, parse, ++redirects);
+ } else {
+ self.doRequest(method, location, body, headers, callback, parse, ++redirects);
+ }
}
return;
}

0 comments on commit 1a9bab5

Please sign in to comment.