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?
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.
i actually looked at most of those tools, however, I need to keep the http2 request in a text file. I just created an issue in httpie as well github.com/httpie/httpie/issues/999#issue-754854604 querying this feature.
Yes but it might be simpler to take your custom format in a text file, and transform it to a curl command-line string than to hope if someone has written something perfectly matches your custom format.
sorry, I do not understand. can you please give an example.
I mean, write a script that takes your file as an input, and runs curl with the correct arguments.