You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running this snippet and sending a request will return a 204 response code despite the status code being explicitly set to 200, it does return a 200 if you reverse the two lines:
This contradicts the documentation and I believe it is caused by not checking for _explicitStatus on this line.
I'm happy to fix the issue by adding the check there, I just want to confirm this is un-intended behavior or if its a mistake in the documentation. As far as I can tell the HTTP spec doesn't specifically mandate that a body be included on a 200 response, only that a 204 MUST NOT include a message-body.
The text was updated successfully, but these errors were encountered:
Yes, there are some cases one wants to reply with "no body" for other status codes as well, that's why I submitted #1447 which is already on latest version (2.12.0)
To obtain the result you want use as this
// This must be always set first before status, since null | undefined // body automatically sets the status to 204ctx.body=null;// Now we override the 204 status with the desired onectx.status=200;
notice the server won't respond with "null" value, it will be no response like it does for 204
I can't say I agree with the behavior, if a response code is set explicitly, then a body is set after it shouldn't change the response code. Thats a strange side effect that I don't think many people will expect.
If I set a status code, I would expect that status code to be what is returned assuming it is valid for the body given.
If the response code and body are invalid together I would expect an error to be thrown.
At the very least this side effect needs documented correctly. Again, offering to do it just looking for some confirmation or consensus.
Koa version 2.12.0
Running this snippet and sending a request will return a 204 response code despite the status code being explicitly set to 200, it does return a 200 if you reverse the two lines:
This contradicts the documentation and I believe it is caused by not checking for
_explicitStatus
on this line.I'm happy to fix the issue by adding the check there, I just want to confirm this is un-intended behavior or if its a mistake in the documentation. As far as I can tell the HTTP spec doesn't specifically mandate that a body be included on a 200 response, only that a 204 MUST NOT include a message-body.
The text was updated successfully, but these errors were encountered: