Skip to content

Commit

Permalink
Fixed: GET / HEAD on redirects. Closes #86
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Apr 13, 2012
1 parent 1cfa5bd commit ad97d5c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,11 @@ Request.prototype.preventBuffer = function(){
Request.prototype.redirect = function(res){
var url = res.headers.location;
delete this.req;
this.emit('redirect', res);
this.method = 'HEAD' == this.method
? this.method
: 'GET';
this.url = url;
this.emit('redirect', res);
this.end(this.callback);
return this;
};
Expand Down
24 changes: 24 additions & 0 deletions test/node/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ app.get('/movies/all/0', function(req, res){
res.send('first movie page');
});

app.post('/movie', function(req, res){
res.redirect('/movies/all/0');
});

app.listen(3003);

describe('request', function(){
Expand Down Expand Up @@ -66,4 +70,24 @@ describe('request', function(){
});
})
})

describe('on POST', function(){
it('should redirect as GET', function(done){
var redirects = [];

request
.post('http://localhost:3003/movie')
.redirects(2)
.on('redirect', function(res){
redirects.push(res.headers.location);
})
.end(function(res){
var arr = [];
arr.push('http://localhost:3003/movies/all/0');
redirects.should.eql(arr);
res.text.should.equal('first movie page');
done();
});
})
})
})

0 comments on commit ad97d5c

Please sign in to comment.