Skip to content

Commit

Permalink
Fixing relative uri's for forwards.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Jan 21, 2011
1 parent 85e3d97 commit f796da7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var toBase64 = function(str) {
};

function request (options, callback) {
console.log(options.uri)
if (!options.uri) {
throw new Error("options.uri is a required argument")
} else {
Expand All @@ -20,7 +21,7 @@ function request (options, callback) {
options._redirectsFollowed = options._redirectsFollowed ? options._redirectsFollowed : 0;
options.maxRedirects = options.maxRedirects ? options.maxRedirects : 10;

options.followRedirect = (options.followRedirect !== undefined) ? options.followRedirect : true;
options.followRedirect = (options.followRedirect === undefined) ? true : options.followRedirect;
options.method = options.method ? options.method : 'GET';

options.headers = options.headers ? options.headers : {};
Expand Down Expand Up @@ -90,6 +91,11 @@ function request (options, callback) {

if (response.statusCode > 299 && response.statusCode < 400 && options.followRedirect && response.headers.location && (options._redirectsFollowed < options.maxRedirects) ) {
options._redirectsFollowed += 1
if (response.headers.location.slice(0, 'http:'.length) !== 'http:' &&
response.headers.location.slice(0, 'https:'.length) !== 'https:'
) {
response.headers.location = url.resolve(options.uri.href, response.headers.location);
}
options.uri = response.headers.location;
delete options.client;
if (options.headers) {
Expand Down

0 comments on commit f796da7

Please sign in to comment.