我一直在研究使用HTTP / 2推送功能的方法,以减少发出的GET请求的数量以及特定客户端-服务器实现中的平均感知延迟。现有的客户端在很大程度上依赖于使用curl来发出GET请求,并且我需要能够重用当前的实现。curl的最新版本依靠底层nghttp2模块提供对HTTP / 2的支持。使用现有的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推送功能一起使用?
curl(命令行工具)尚不支持HTTP / 2推送。
仅当使用libcurl而不是命令行工具进行HTTP / 2时,才可以使用它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句