According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2 the only response ever mentioned regarding an HTTP OPTIONS request is a 200. However, there seem to be cases such as when the content-length is 0 that a 204 would be more appropriate. Is it appropriate for an HTTP OPTIONS request to return a 204?
相关问题
- Angular RxJS mergeMap types
- Google Apps Script: testing doPost() with cURL
- How to instantiate Http service in main.ts manuall
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- PHP Empty $_POST
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- Is a unicode user agent legal inside an HTTP heade
- git: retry if http request failed
- Flutter - http.get fails on macos build target: Co
- C# HttpClient.SendAsync always returns 404 but URL
- Response body is null, status is 200
- Returning plain text or other arbitary file in ASP
- jquery how to get the status message returned by a
RFC 2616 says:
which indeed makes it unclear whether the 200 applies to the whole paragraph or only the first sentence. If you wanted to play it safe, you'd let the MUST take precedence (and it wouldn't cost you much).
RFC 7231, which obsoletes RFC 2616, changed the wording to
which makes the last sentence apply in the general sense to 2xx statuses, and the MUST prevails.
So, Content-Length MUST be sent. But a Content-Length cannot be sent with a 204:
RFC 2616 says it like so:
And RFC 7230 clarifies this as well:
That's how I understand it, anyway.
Within the existing language, the only resolution to the apparent contradiction between RFC 7230 §3.3.2
Content-Length
:“A server MUST NOT send a
Content-Length
header field in any response with a status code of 1xx (Informational) or 204 (No Content).”and RFC 7231 §4.3.7
OPTIONS
:“A server MUST generate a
Content-Length
field with a value of "0" if no payload body is to be sent in the response.”is to disallow all 204 responses to
OPTIONS
requests. Because this does not seem to have been the intention, I submitted an erratum report. The latter statement was removed from RFC 7231 in draft-ietf-httpbis-semantics-06, so a 204 response (without aContent-Length
field) is now unambiguously allowed.Yes, it can return 204. Or 400. Or 404. There is no general restriction as to what status codes a method can return.
Also note that it's time to stop looking at RFC 2616. See http://trac.tools.ietf.org/wg/httpbis/trac/wiki.