Fix res.redirect body when redirect status specified

fixes #2402
fixes #2404
This commit is contained in:
Alex Upadhyay
2014-10-18 01:12:47 +00:00
committed by Douglas Christopher Wilson
parent 6f91416020
commit 6f0302fb78
3 changed files with 33 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
unreleased
==========
* Fix `res.redirect` body when redirect status specified
* deps: accepts@~1.1.2
- Fix error when media type has invalid parameter
- deps: negotiator@0.4.9

View File

@@ -818,11 +818,11 @@ res.redirect = function redirect(url) {
// Support text/{plain,html} by default
this.format({
text: function(){
body = statusCodes[status] + '. Redirecting to ' + encodeURI(url);
body = statusCodes[status] + '. Redirecting to ' + encodeURI(address);
},
html: function(){
var u = escapeHtml(url);
var u = escapeHtml(address);
body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';
},

View File

@@ -106,6 +106,21 @@ describe('res', function(){
done();
})
})
it('should include the redirect type', function(done){
var app = express();
app.use(function(req, res){
res.redirect(301, 'http://google.com');
});
request(app)
.get('/')
.set('Accept', 'text/html')
.expect('Content-Type', /html/)
.expect('Location', 'http://google.com')
.expect(301, '<p>Moved Permanently. Redirecting to <a href="http://google.com">http://google.com</a></p>', done);
})
})
describe('when accepting text', function(){
@@ -143,6 +158,21 @@ describe('res', function(){
done();
})
})
it('should include the redirect type', function(done){
var app = express();
app.use(function(req, res){
res.redirect(301, 'http://google.com');
});
request(app)
.get('/')
.set('Accept', 'text/plain, */*')
.expect('Content-Type', /plain/)
.expect('Location', 'http://google.com')
.expect(301, 'Moved Permanently. Redirecting to http://google.com', done);
})
})
describe('when accepting neither text or html', function(){