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

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

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

During development, I need to see what exactly I am sending or receiving using cli (it makes it easier to automate).

Normally I can put my http/1.0 header in a text file (in this case raw-http.txt), send request, and get response from command line using 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

However, in the case of http/2, the header is encoded using hpack.

Suppose my raw-http2.txt looks like:

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

So, I think I have to do something like:

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

how can I do that?

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

Have you considered using something like curl for this? Ultimately you are no longer sending an exact series of bytes over a TCP socket, HTTP/2 is a very different beast. The raw-http2.txt resembles how browsers show headers, but of course the actual on-the-wire format is very different. There's a lot more to it than just compressing the headers.

So you need something that takes a format humans can easily write/understand, and turn it into a HTTP/2 request. Curl is one of those tools but obviously doesn't take exactly your input format.