Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl: one-liner to test http/2 support

I'm currently writing an unit test to check if http/2 is supported.

Is there a curl one-liner which checks if http/2 is supported and outputs a response that is easy to parse?

like image 694
bn4t Avatar asked Jul 11 '18 05:07

bn4t


People also ask

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 can I tell if http 2 is supported?

Google Chrome offers a quick and easy way to check if HTTP/2 is supported on your SSL-enabled site. First, visit your site in Chrome over HTTPS. There you'll see your site listed with protocol h2, confirming your site works over HTTP/2.

How do I use curl command in HTTP request?

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.

Can http2 work without TLS?

No. After extensive discussion, the Working Group did not have consensus to require the use of encryption (e.g., TLS) for the new protocol. However, some implementations have stated that they will only support HTTP/2 when it is used over an encrypted connection, and currently no browser supports HTTP/2 unencrypted.


4 Answers

HTTP/2 supported:

$ curl -sI https://curl.se -o/dev/null -w '%{http_version}\n'
2

HTTP/2 not supported (instead serving 1.1 in this case):

$ curl -sI http://curl.se -o/dev/null -w '%{http_version}\n'
1.1

(curl 7.50.0 or later is required for this command line to work)

like image 96
Daniel Stenberg Avatar answered Oct 04 '22 13:10

Daniel Stenberg


Run

curl --version

and look for HTTP2 on the Features list

like image 24
Benav Avatar answered Oct 04 '22 14:10

Benav


Here you can find a list of Tools for debugging, testing and using HTTP/2.

Probably the easiest one from the command line is:

$ is-http2 www.cloudflare.com

But that requires npm install -g is-http2-cli

For testing using curl you may need to compile it using the nghttp library, in macOS this can be done by using brew you could use:

$ brew install curl --with-nghttp2

And then you could use what @daniel-stenberg suggests in his answer

$ curl -sI https://curl.haxx.se -o/dev/null -w '%{http_version}\n'

In where you will get a 2 if http2 is supported.

like image 31
nbari Avatar answered Oct 04 '22 15:10

nbari


I used

curl -kvso /dev/null --http2 https://app.domain.com:443

which returned

...
> GET / HTTP/2
...
< HTTP/2 302
...

this is not checking if HTTP2 is supported, but check if HTTP2 actually works.

like image 21
Ľubomír Mlích Avatar answered Oct 04 '22 15:10

Ľubomír Mlích