以下是我在 nginx 服务器日志中看到的内容(IP 和某些路径已更改,以方便举例):
101.101.101.101 - - [15/Apr/2020:14:46:03 +0000] "GET /item/download-file/ready/5e971e290107e HTTP/2.0" 200 142940 "https://example.com/referer" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36" 101.101.101.101 - - [15/Apr/2020:14:46:04 +0000] "GET /item/download-file/ready/5e971e290107e HTTP/1.1" 200 5 "https://example.com/referer" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
问题在于访问的链接是不可重复使用的资源(只能访问一次),因此客户端会遇到错误。
这些链接是用 JavaScript 代码调用的文件下载,其中涉及 window.location.href = "..."。响应服务器头包括 Content-Disposition: attachment。
在什么情况下,Chrome 会发送两个请求,首先是 HTTP/2.0,然后是几分钟之后的 HTTP/1.1?也许有一个扩展可以引起这种情况?
请注意,我无法在我拥有的任何浏览器中重现此问题。
更新2:
我已确定它不仅发生在 Chrome 中。Edge 44 在日志中也出现了。此外,其他此问题实例的第二个请求并没有切换到 HTTP/1.1。而是使用的是 HTTP/2.0。
更新:
我被要求提供典型请求的响应头:
101.101.101.101 - - [15/Apr/2020:14:46:03 +0000] "GET /item/download-file/ready/5e971e290107e HTTP/2.0" 200 142940 "https://example.com/referer" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36" 101.101.101.101 - - [15/Apr/2020:14:46:04 +0000] "GET /item/download-file/ready/5e971e290107e HTTP/1.1" 200 5 "https://example.com/referer" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
问题在于访问的链接是不可重复使用的资源(只能访问一次),因此客户端会遇到错误。
这些链接是用 JavaScript 代码调用的文件下载,其中涉及 window.location.href = "..."。响应服务器头包括 Content-Disposition: attachment。
在什么情况下,Chrome 会发送两个请求,首先是 HTTP/2.0,然后是几分钟之后的 HTTP/1.1?也许有一个扩展可以引起这种情况?
请注意,我无法在我拥有的任何浏览器中重现此问题。
更新2:
我已确定它不仅发生在 Chrome 中。Edge 44 在日志中也出现了。此外,其他此问题实例的第二个请求并没有切换到 HTTP/1.1。而是使用的是 HTTP/2.0。
更新:
我被要求提供典型请求的响应头:
cache-control: no-store, no-cache, must-revalidate
content-disposition: attachment; filename=sources.zip
content-length: 8597357
content-transfer-encoding: Binary
content-type: application/octet-stream
date: Wed, 15 Apr 2020 17:23:44 GMT
expires: Thu, 19 Nov 1981 08:52:00 GMT
pragma: no-cache
server: nginx/1.16.1
status: 200