如何使用卷曲推送HTTP / 2推送功能?

时间:2014-12-14 16:38:37

标签: curl push http2

我一直在研究如何使用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

有没有办法在使用HTTP / 2推送功能时使用curl?

1 个答案:

答案 0 :(得分:5)

curl(命令行工具)不支持HTTP / 2 push(还)。

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