diff --git a/lib/response.js b/lib/response.js index 5d064cd..5cfc888 100644 --- a/lib/response.js +++ b/lib/response.js @@ -257,6 +257,7 @@ module.exports = { } // text + this.type = 'text/plain; charset=utf-8'; this.body = 'Redirecting to ' + url + '.'; }, diff --git a/test/response/redirect.js b/test/response/redirect.js index f93489d..ca3d72b 100644 --- a/test/response/redirect.js +++ b/test/response/redirect.js @@ -91,6 +91,19 @@ describe('ctx.redirect(url)', function(){ ctx.body.should.equal('Redirecting to ' + url + '.'); }) }) + + describe('when content-type was present', function(){ + it('should overwrite content-type', function() { + var ctx = context(); + ctx.body = {}; + var url = 'http://google.com'; + ctx.header.accept = 'text/plain'; + ctx.redirect('http://google.com'); + ctx.status.should.equal(302); + ctx.body.should.equal('Redirecting to ' + url + '.'); + ctx.type.should.equal('text/plain'); + }) + }) }) function escape(html) {