From 57eb6a10df323ead9f28d61d0b21c991bb8e1d37 Mon Sep 17 00:00:00 2001 From: dead_horse Date: Fri, 28 Nov 2014 01:01:15 +0800 Subject: [PATCH] set content-type for redirect when accpect plain --- lib/response.js | 1 + test/response/redirect.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) 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) {