这是因为你这里的内容,是由 ngx_http_static_module 这个模块负责产生的,这个模块只会调用一次 ngx_http_output_filter, 即所有内容一次发完。还有这个模块不会去调用 ngx_http_clear_content_length,而 chunked 过滤模块只在 r->content_length_n == -1 时,才会决定是否使用 chunked 模式传输,所以 chunked 模式没法工作的(毕竟需要一个长度为 0 的 chunk 块,标识内容结束)
On Wednesday, June 14, 2017 at 5:35:51 PM UTC+8, wuw...@gmail.com wrote:
嗨,大家好。请教一个问题,我想在下载文件的时候,
使用chunk的方式。但是,设置了chunked_transfer_encoding on字段,返回的报文头里面依旧没有trunked 。
conf 配置如下:
location ~ /([-_a-zA-Z0-9/]+)/([-_a-zA-Z0-9/]+) {
chunked_transfer_encoding on;
sendfile on;
sendfile_max_chunk 256k;
default_type application/zip;
root /product;
}
发送请求以及返回报文如下:
---request begin---
GET /product HTTP/1.1
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: 172.xxx.xxx.xxx:52xx
Connection: Keep-Alive
---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 200 OK
Date: Wed, 14 Jun 2017 09:31:53 GMT
Content-Type: application/zip
Content-Length: 41550137
Last-Modified: Wed, 10 May 2017 09:01:41 GMT
Connection: keep-alive
ETag: "5912d6f5-27a0139"
Accept-Ranges: bytes
---response end---
返回报文中 依旧返回的是Content-Length,按理说 返回报文的header 应该是Transfer-Encoding: chunked;
为什么设置了chunked_transfer_encoding on 字段,还是不生效呢?