MSIE/Edge 对 <object> 数据 URL 使用 HTTP HEAD,然后将 204 响应视为错误?

MSIE/Edge uses HTTP HEAD for <object> data URLs, then treats 204 response as error?

背景:

我的 PHP 代码通过发送 HTTP 状态 404 响应或 204 响应来处理典型的 HTTP HEAD 请求。这对我来说似乎是正确的,因为 RFC7231 将 HTTP 状态 204 指定为:

6.3.5. 204 No Content

The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. Metadata in the response header fields refer to the target resource and its selected representation after the requested action was applied...

The 204 response allows a server to indicate that the action has been successfully applied to the target resource, while implying that the user agent does not need to traverse away from its current "document view" (if any)...

A 204 response is terminated by the first empty line after the header fields because it cannot contain a message body...

https://www.rfc-editor.org/rfc/rfc7231#section-6.3.5

由于用户代理仅请求 headers 而不是文件本身,因此 204 似乎合适。

惊喜 #1:

元素的 data 属性具有 URL 时,MSIE/Edge 最初发出 HTTP HEAD 请求,以便通过响应 headers 确定 content-type。虽然另一个 MS 怪癖,但它是有道理的,因为它允许浏览器在接收内容之前 pre-load 所需的处理程序。当它收到对 HEAD 请求的合适响应时,它将对文件本身发出 HTTP GET 请求。

现在,如果不是因为......

,这不会是一个大问题

惊喜 #2:

当 MSIE/Edge 收到对其 HEAD 请求的 204 响应时,它会将其视为错误并中止加载文件。

不用说,发现(过程和发现本身)非常令人沮丧。

我是否误解了 204 响应的目的或用法?我知道 industry-usage 经常与规格不同,但这似乎......是错误的。

我是 Edge 团队的一名工程师,看到了您提到的问题。目前,我鼓励您使用 200 OK 响应,即使您只是发送 headers(这很常见)。

我同意两个请求是不正常的,204 应该不会阻止后续的 GET 请求。

我已经为我们的团队提交了一个错误,以便更彻底地评估这个问题。

https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8499759/

当您使用 HEAD returning 204 时,您是在告诉用户代理,如果它要执行 GET,那么它也会得到 204,因此没有要检索的内容。从用户代理的角度来看,执行 GET 是没有意义的,因为 HEAD 检索了所有可用的信息。

如果执行 GET 请求 return 是 200,那么 HEAD 也应该 return 是 200。