Comment on page
curl supports HTTP/2 for both HTTP:// and HTTPS:// URLs assuming that curl was built with the proper prerequisites. It will even default to using HTTP/2 when given an HTTPS URL since doing so implies no penalty and when curl is used with sites that do not support HTTP/2 the request will instead negotiate HTTP/1.1.
With HTTP:// URLs however, the upgrade to HTTP/2 is done with an
Upgrade:header that may cause an extra round-trip and perhaps even more troublesome, a sizable share of old servers will return a 400 response when seeing such a header.
It should also be noted that some (most?) servers that support HTTP/2 for HTTP:// (which in itself is not all servers) will not acknowledge the
Upgrade:header on POST, for example.
To ask a server to use HTTP/2, just:
curl --http2 http://example.com/
If your curl does not support HTTP/2, that command line will return an error saying so. Running
curl -Vwill 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
A primary feature in the HTTP/2 protocol, is the ability to multiplex several logical streams over the same physical connection. The curl command-line tool can take advantage of this feature when doing parallel transfers.