提供部分 HTTP 响应

Serving Partial HTTP Response

我想使用字节范围请求使文件下载可恢复。

问题是我现有的下载操作正在响应 POST 方法,我想保持这种状态。

但从我早期的测试看来,当用户尝试恢复时,Chrome 将中断的 POST 文件下载请求转换为 GET 请求,因此恢复下载失败.

  1. 我是不是漏掉了什么?
  2. 这是否与只允许恢复 GET 请求的 HTTP 规范有关?
  3. 或者只是 Chrome(可能还有其他浏览器)的设计缺陷导致它忘记了原来使用的 HTTP 方法?

更新:

这里是 request/response 数据:

初始POST请求:

POST http://localhost:35547/Download?Guid=396b4697-e275-4396-818c-548bf8c0a281 HTTP/1.1
Host: localhost:35547
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Origin: http://localhost:35547
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Referer: http://localhost:35547/File/396b4697-e275-4396-818c-548bf8c0a281
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Cookie: __RequestVerificationToken=LuPgM05MHrsuyskgfhsrHVUs; ASP.NET_SessionId=gfiulghfuygisghkf; .ASPXAUTH=FGDJHGDHSDFB15AFDE6371CGJHDFGFBHD; fileDownload=true

初始响应(对上述请求):

HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: application/zip
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 5.2
Content-Disposition: attachment; filename="FILE-396b4697e2754396818c548bf8c0a281.zip"
X-AspNet-Version: 4.0.30319
Set-Cookie: fileDownload=true; path=/
X-Powered-By: ASP.NET
Date: Wed, 09 Nov 2016 11:13:50 GMT
Content-Length: 1885473

PK.......... ZIP file data .............................................

中断后浏览器在恢复时的请求(注意使用的GET方法):

GET http://localhost:35547/Download?Guid=396b4697-e275-4396-818c-548bf8c0a281 HTTP/1.1
Host: localhost:35547
Connection: keep-alive
Referer: http://localhost:35547/File/396b4697-e275-4396-818c-548bf8c0a281
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8
Cookie: __RequestVerificationToken=.............

(一些来自安全相关 cookie 的数据已被缩短和更改)

Am I missing something ?

这取决于您如何分析 google chrome 的行为。理想的方法是使用任何代理或使用数据包嗅探器(例如 Wireshark)来查看 chrome 在后续请求中使用的请求方法。

Is this something related to the HTTP specs that only allow GET requests to be resumed?

截至目前,HTTP协议规范中没有提及只能恢复GET请求。

Or is it simply a design flaw in Chrome (and maybe other browsers as well) that makes it forget the original HTTP method used?

是的,这是googlechrome的缺陷。确保在包含所有更新补丁的最新版本 Google chrome 上检查它。也可以在其他浏览器上查看。

有关 HTTP 协议的更多信息,请参阅 https://www.ietf.org/rfc/rfc2616.txt。 请参考以下请求,以提供部分响应:https://en.wikipedia.org/wiki/Byte_serving

编辑 有关 HTTP 信息的更多更新信息,请参阅:- https://www.rfc-editor.org/rfc/rfc7230