eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.89k stars 1.82k forks source link

Zero length body #3520

Closed sm2017 closed 5 years ago

sm2017 commented 5 years ago

How can I have zero length body? My ctx.status is 202 = Accepted , I don't set ctx.body but egg set it as empty object , for 204 egg has no body , but I want to set status 202 as the task is just accepted and will done later

@see https://greenbytes.de/tech/webdav/rfc7230.html#message.body

atian25 commented 5 years ago

https://github.com/koajs/koa/blob/master/lib/response.js#L140

try:(don't work)

    this.ctx.status = 202;
    this.ctx.body = '';

update:

it seems will use ctx.message as default if you don't provide body, maybe should dig into Koa or Node api.

sm2017 commented 5 years ago

@atian25 see https://github.com/koajs/koa/issues/1314#issuecomment-470594686

What you think?

denghongcai commented 5 years ago

try

this.ctx.status = 202;
this.ctx.body = new Buffer(0);
atian25 commented 5 years ago
    this.ctx.status = 202;
    this.ctx.body = Buffer.from('');