Warm tip: This article is reproduced from serverfault.com, please click

其他-如何从命令行查看人类可读格式的http / 2标头(hpack编码)?

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

发布于 2020-12-02 01:17:22

在开发过程中,我需要查看使用cli发送或接收的确切信息(它使自动化变得更容易)。

通常,我可以将http / 1.0标头放在一个文本文件中(在这种情况下raw-http.txt),发送请求,并使用从命令行获取响应openssl

% 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的情况下,标头是使用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

我怎样才能做到这一点?

Questioner
blueray
Viewed
11
Evert 2020-12-02 09:49:31

你是否考虑过为此使用诸如curl之类的东西?最终,你不再需要通过TCP套接字发送确切的一系列字节,HTTP / 2是完全不同的野兽。raw-http2.txt酷似如何浏览器会显示标题,当然实际的On-the-wire格式是非常不同的。除了压缩头文件外,还有很多其他功能。

因此,你需要一种人类可以轻松编写/理解的格式,并将其转换为HTTP / 2请求。Curl是这些工具之一,但显然并不能完全采用你的输入格式。