Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will I be able to use CURL to get HTTP/2 headers?

Right now I use curl -I to retrieve headers.

Will sites adopt a different way of serving headers with HPACK in the upcoming adoption of HTTP/2 by browsers that will render my use of the curl command ineffective?

like image 810
Orun Avatar asked Feb 24 '15 18:02

Orun


People also ask

Does curl support HTTP 2?

curl supports http2 over standard TCP via the Upgrade: header. If you do an HTTP request and ask for HTTP 2, curl will ask the server to update the connection to http2 if possible.

How do I know if my curl supports http2?

Running curl -V will show if your version of curl supports it. If you by some chance already know that your server speaks HTTP/2 (for example, within your own controlled environment where you know exactly what runs in your machines) you can shortcut the HTTP/2 "negotiation" with --http2-prior-knowledge .

How do I pass HTTP headers in curl?

To send an HTTP header with a Curl request, you can use the -H command-line option and pass the header name and value in "Key: Value" format. If you do not provide a value for the header, this will remove the standard header that Curl would otherwise send. The number of HTTP headers is unlimited.

Does curl work with HTTP?

curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, GOPHER, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction.


1 Answers

Yes, you can use curl to see and send HTTP headers with HTTP/2 just as you do with HTTP/1.

curl supports HTTP/2 and it is implemented as a sort of translation layer. It means it shows and "pretends" that headers work 1.1 style. It shows headers as text and it sends headers in callbacks like they were done with 1.1. We made it this way to make scripts and applications get a very smooth and basically invisible transition path to HTTP/2 with curl.

Internally that is of course done by decompressing received headers before showing them, and showing them before compressing them when sending them.

like image 157
Daniel Stenberg Avatar answered Sep 22 '22 00:09

Daniel Stenberg