6

我一直在寻找使用 HTTP/2 推送功能的方法,以减少发出的 GET 请求的数量和特定客户端-服务器实现中的平均感知延迟。现有的客户端严重依赖使用 curl 来发出 GET 请求,我需要能够重用当前的实现。最新版本的 curl 提供对 HTTP/2 的支持,依赖于底层的 nghttp2 模块。使用现有的 nghttp2 服务器:

nghttpd -d /var/www/html/ 3000 local.key local.crt

nghttp 和 curl 都可以用来获取示例文本文件的内容:

nghttp https://localhost:3000/text.txt
This is some sample text.

curl https://localhost:3000/text.txt -k --http2
This is some sample text.

然而,使用 nghttp2 的推送功能,另一个文本文件被推送:

nghttpd -d /var/www/html/ -p/text.txt=/text2.txt 3000 local.key local.crt

curl 似乎无法处理推送的资源:

nghttp https://localhost:3000/bbb/text.txt
This is some sample text.
This is some sample text as well.

curl https://localhost:3000/text.txt -k --http2 -v
...
* nghttp2_session_mem_recv() returns 268
* before_frame_send() was called
* on_frame_send() was called
* on_stream_close() was called, error_code = 1
* before_frame_send() was called
* on_frame_send() was called
* on_stream_close() was called, error_code = 1
* Connection #0 to host localhost left intact

实际上,在服务器端,两个打开的流接收到两个重置:

[id=1] [331.593] recv RST_STREAM frame <length=4, flags=0x00, stream_id=1>
      (error_code=PROTOCOL_ERROR(0x01))
[id=1] [331.594] recv RST_STREAM frame <length=4, flags=0x00, stream_id=2>
      (error_code=PROTOCOL_ERROR(0x01))
[id=1] [331.594] closed

有没有办法将 curl 与 HTTP/2 推送功能一起使用?

4

1 回答 1

5

curl(命令行工具)不支持 HTTP/2 推送(目前)。

您只能在使用 libcurl 而不是命令行工具执行 HTTP/2 时使用它。

于 2014-12-15T09:31:03.743 回答