一开始我以为http流其实就是实现了http chunk。
所以我做了一个测试来学习。
这是一个django视图
def test_stream(request):
return StreamingHttpResponse(func)
func return iterable 这是使用 curl 访问视图的输出
curl -vv -raw http://172.25.44.238:8004/api/v1/admin/restart_all_agent?cluster_id='dd5aef9cbe7311e99585f000ac192cee' -i
Warning: Invalid character is found in given range. A specified range MUST
Warning: have only digits in 'start'-'stop'. The server's response to this
Warning: request is uncertain.
* About to connect() to 172.25.44.238 port 8004 (#0)
* Trying 172.25.44.238...
* Connected to 172.25.44.238 (172.25.44.238) port 8004 (#0)
> GET /api/v1/admin/restart_all_agent?cluster_id=dd5aef9cbe7311e99585f000ac192cee HTTP/1.1
> Range: bytes=aw
> User-Agent: curl/7.29.0
> Host: 172.25.44.238:8004
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8
< X-Frame-Options: SAMEORIGIN
X-Frame-Options: SAMEORIGIN
* no chunk, no close, no size. Assume close to signal end
<
some http response body.
* Closing connection 0
从输出中您可以看到没有分块标题。似乎Http流与块无关。
所以这是问题
- http流是由http chunk实现的吗?
- 如何在 django 中返回分块响应?