(status)
| 62 | }) |
| 63 | |
| 64 | function strip (status) { |
| 65 | it('should strip content related header fields', async () => { |
| 66 | const app = new Koa() |
| 67 | |
| 68 | app.use(ctx => { |
| 69 | ctx.body = { foo: 'bar' } |
| 70 | ctx.set('Content-Type', 'application/json; charset=utf-8') |
| 71 | ctx.set('Content-Length', '15') |
| 72 | ctx.set('Transfer-Encoding', 'chunked') |
| 73 | ctx.status = status |
| 74 | assert(ctx.response.header['content-type'] == null) |
| 75 | assert(ctx.response.header['content-length'] == null) |
| 76 | assert(ctx.response.header['transfer-encoding'] == null) |
| 77 | }) |
| 78 | |
| 79 | const res = await request(app.callback()) |
| 80 | .get('/') |
| 81 | .expect(status) |
| 82 | |
| 83 | assert.strictEqual(Object.prototype.hasOwnProperty.call(res.headers, 'Content-Type'), false) |
| 84 | assert.strictEqual(Object.prototype.hasOwnProperty.call(res.headers, 'content-length'), false) |
| 85 | assert.strictEqual(Object.prototype.hasOwnProperty.call(res.headers, 'content-encoding'), false) |
| 86 | assert.strictEqual(res.text.length, 0) |
| 87 | }) |
| 88 | |
| 89 | it('should strip content related header fields after status set', async () => { |
| 90 | const app = new Koa() |
| 91 | |
| 92 | app.use(ctx => { |
| 93 | ctx.status = status |
| 94 | ctx.body = { foo: 'bar' } |
| 95 | ctx.set('Content-Type', 'application/json; charset=utf-8') |
| 96 | ctx.set('Content-Length', '15') |
| 97 | ctx.set('Transfer-Encoding', 'chunked') |
| 98 | }) |
| 99 | |
| 100 | const res = await request(app.callback()) |
| 101 | .get('/') |
| 102 | .expect(status) |
| 103 | |
| 104 | assert.strictEqual(Object.prototype.hasOwnProperty.call(res.headers, 'Content-Type'), false) |
| 105 | assert.strictEqual(Object.prototype.hasOwnProperty.call(res.headers, 'content-length'), false) |
| 106 | assert.strictEqual(Object.prototype.hasOwnProperty.call(res.headers, 'content-encoding'), false) |
| 107 | assert.strictEqual(res.text.length, 0) |
| 108 | }) |
| 109 | } |
| 110 | |
| 111 | describe('when 204', () => strip(204)) |
| 112 |
no test coverage detected