提交 6cf6a95a 编写于 作者: J jongleberry

fix: Set body to if and @likegun closes #1059 closes #998

上级 94c2ac4f
......@@ -13,6 +13,7 @@
## Fixes
- fix: Do not response Content-Length if Transfer-Encoding is defined #1562 @charlyzeng
- fix: Set body to `null` if `ctx.type = json` and `ctx.body = null` #1059 @likegun
2.13.1 / 2021-01-04
==================
......
......@@ -27,6 +27,9 @@ describe('res.length', () => {
it('should return a number', () => {
const res = response()
res.body = null
assert.strictEqual(res.length, undefined)
res.body = 'foo'
res.remove('Content-Length')
assert.strictEqual(res.length, 3)
......@@ -63,4 +66,16 @@ describe('res.length', () => {
})
})
})
describe('and a .type is set to json', () => {
describe('and a .body is set to null', () => {
it('should return a number', () => {
const res = response()
res.type = 'json'
res.body = null
assert.strictEqual(res.length, 4)
})
})
})
})
......@@ -137,7 +137,13 @@ module.exports = {
// no content
if (val == null) {
if (!statuses.empty[this.status]) this.status = 204
if (!statuses.empty[this.status]) {
if (this.type === 'application/json') {
this._body = 'null'
return
}
this.status = 204
}
if (val === null) this._explicitNullBody = true
this.remove('Content-Type')
this.remove('Content-Length')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册