如何从命令行以人类可读格式查看 http/2 header(hpack 编码)?

How to view http/2 header (hpack encoded) in human readable format from command line?

在开发过程中,我需要使用 cli 查看我正在发送或接收的内容(它使自动化更容易)。

通常我可以将 http/1.0 header 放入文本文件(在本例中为 raw-http.txt),发送请求,并使用 [=16 从命令行获取响应=].

% echo '"'; cat raw-http.txt; echo '"'
"
GET / HTTP/1.0
Host: www.google.com

"
% cat raw-http.txt | openssl s_client -quiet -connect www.google.com:443 2>/dev/null

然而,在 http/2 的情况下,header 是使用 hpack 编码的。

假设我的 raw-http2.txt 看起来像:

:method:GET
:path:/
:scheme:https
:authority:www.google.com
user-agent:curl/7.58.0
accept:*/*

所以,我想我必须做类似的事情:

% cat raw-http.txt | encode-request | openssl s_client -quiet -connect www.google.com:443 2>/dev/null

我该怎么做?

您是否考虑过为此使用 curl 之类的工具?最终您不再通过 TCP 套接字发送一系列精确的字节,HTTP/2 是一个非常不同的野兽。 raw-http2.txt 类似于浏览器显示 headers 的方式,但当然实际的 on-the-wire 格式非常不同。它不仅仅是压缩 headers.

因此,您需要采用人类可以轻松 write/understand 的格式,并将其转换为 HTTP/2 请求。 Curl 是其中一种工具,但显然不能完全采用您的输入格式。