From 1457a3df0f69b61af51d4d6867c735335a1a7b73 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Tue, 20 Aug 2013 21:24:18 -0700 Subject: [PATCH] add striping of Content-* fields when 204 / 304. Closes #21 --- lib/context.js | 6 ++++++ test/context.js | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/context.js b/lib/context.js index deb142c..faece14 100644 --- a/lib/context.js +++ b/lib/context.js @@ -71,6 +71,12 @@ module.exports = { val = n; } + if (204 == val || 304 == val) { + this.res.removeHeader('Content-Type'); + this.res.removeHeader('Content-Length'); + this.res.removeHeader('Transfer-Encoding'); + } + this.res.statusCode = val; }, diff --git a/test/context.js b/test/context.js index 6788e87..cf3cc54 100644 --- a/test/context.js +++ b/test/context.js @@ -1,5 +1,6 @@ var _context = require('../lib/context'); +var request = require('supertest'); var assert = require('assert'); var koa = require('..'); var fs = require('fs'); @@ -172,6 +173,29 @@ describe('ctx.status=', function(){ }) }) }) + + describe('when 204', function(){ + it('should strip content related header fields', function(done){ + var app = koa(); + + app.use(function(next){ + return function *(){ + this.set('Content-Type', 'application/json'); + this.set('Content-Length', '15'); + this.set('Transfer-Encoding', 'chunked'); + this.status = 204; + assert(null == this.responseHeader['content-type']); + assert(null == this.responseHeader['content-length']); + assert(null == this.responseHeader['transfer-encoding']); + } + }); + + request(app.listen()) + .get('/') + .expect(204) + .end(done); + }) + }) }) describe('ctx.stale', function(){