在解析无效的 HTTP `Range: ...` header 时,我们 return 会出现什么错误?

What error do we return when parsing an invalid HTTP `Range: ...` header?

我正在开发一个手动解析 Range: ... 字段的项目。出现错误时,它总是 return 一个 416 HTTP 错误(Range Not Satisfiable)。

在我看来,在大多数情况下,比如范围不是 bytes=... 或数字无效,HTTP 错误应该改为 400。

您以前有过这个具体案例的经验吗?我们期望什么 return?

冒着类似意见的答案的风险:RFC 7233 在无法满足范围请求的上下文中讨论了 416,强烈暗示该请求在语法上是正确的。

The 416 (Range Not Satisfiable) status code indicates that none of the ranges in the request's Range header field (Section 3.1) overlap the current extent of the selected resource or that the set of ranges requested has been rejected due to invalid ranges or an excessive request of small or overlapping ranges.

https://www.rfc-editor.org/rfc/rfc7233#page-15

请求语法错误或其他格式错误仍然对应于一般的 400 Bad Request。

The 400 (Bad Request) status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

https://www.rfc-editor.org/rfc/rfc7231#page-58

因此,如果请求未指定有效的 bytes 范围(目前唯一注册的范围类型),我会 return 400。