-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPTIONS returns "200 OK" even though there is no body #156
Comments
According to https://tools.ietf.org/html/rfc7231#section-6.3.1 200 status code is perfectly valid for an OPTIONS request. As far as I know 204 is usually used when there is some kind of content involved (in the request for example), but the response does not have any. I don't see any improvement in semantics by returning 204 (and in the end this is a semantical question IMO), but I am not against it either. This could be a breaking change though. |
According to that same link, returning
The server isn't returning any data for the It's also more explicit in the following section:
Returning I opened this issue because I'm writing some test cases for a server and I'm validating every data returned by According to the RFC, a server may generate a payload body of zero length for a |
Although that's what the spec suggests, I wouldn't be too strict on that one. That's an option you can choose. It recommends to use 204 when there is no content, but it's not a strict rule. I would say relying on the status code to determine whether there is content is not really a good choice. My particular issue with using multiple success status codes is that clients might not be ready to handle them all, this doing this change is definitely breaking. I would rather use 200 always instead of changing from 204 to 200 if necessary. (That of course does not apply to error status codes as a client MUST handle every non-success status and have some kind of fallback logic for unknown statuses) |
Odd. RFC7230-section3.3.3 would seem to disagree with your assertion, concerning using 204.
Although I'm certain someone hardcoded Would kinda wonder about a portion of the logic in "router.go" though; wouldn't there always be an |
I think I wasn't totally clear. I agree that 204 should mean there is actually no content. On the other hand, 200 with an empty body should be fine too. Maybe not for an OPTIONS request, but I think clients/servers with this level of RFC conformity is rare. Ultimately my main argument is backwards compatibility which is no longer valid if we are talking about a new major version. |
Changing the status code is now possible via a global OPTIONS handler. See Automatic OPTIONS responses and CORS. I will leave this issue open, since |
…hmidt#156) Signed-off-by: Aaron Schlesinger <[email protected]>
Isn't "204 No Content" a more appropriate return status for OPTIONS requests, as they don't return anything in their bodies?
AFAIU, "200 OK" should be used when the request is successful and there is some data to return, and "204 No Content" when the request is successful but there isn't data to return. "200 OK" is used currently because in https://github.com/julienschmidt/httprouter/blob/master/router.go#L382, no status is set.
When I send an OPTIONS request to my server, I get:
IMO, even the Content-Type is misleading because there's no content at all.
I applied the following patch to my local code:
And it seemed to do the trick. If you agree with this, I can send a PR.
The text was updated successfully, but these errors were encountered: