Skip to content
Browse files

[fix] now it redirects to the absolute url

  • Loading branch information...
1 parent 9f8bda5 commit 7ca3a2422d0133deca2752a869219d5da589b441 @yawnt yawnt committed Jul 15, 2012
Showing with 11 additions and 5 deletions.
  1. +10 −4 lib/response-stream.js
  2. +1 −1 test/simple-test.js
View
14 lib/response-stream.js
@@ -161,12 +161,18 @@ ResponseStream.prototype.write = function (data) {
};
ResponseStream.prototype.redirect = function(path, status) {
- path = path.indexOf('://') ?
- path :
- (this.req.encrypted ? 'https://' : 'http://') + this.req.headers.host + this.req.url;
+ var url = '';
+ if(~path.indexOf('://')) {
+ url = path;
+ } else {
+ url += this.req.encrypted ? 'https://' : 'http://';
+ url += this.req.headers.host;
+ url += (path[0] === '/') ? path : '/' + path;
+ }
+
this.res.writeHead(status || 302, {
- 'Location': path
+ 'Location': url
});
this.res.end();
};
View
2 test/simple-test.js
@@ -70,7 +70,7 @@ vows.describe('union/simple').addBatch({
},
"it should redirect to `/foo`": function(err, res, body) {
assert.equal(res.statusCode, 301);
- assert.equal(res.headers.location, "/foo");
+ assert.equal(res.headers.location, "http://localhost:9090/foo");
}
}
}

0 comments on commit 7ca3a24

Please sign in to comment.
Something went wrong with that request. Please try again.