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?
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?
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)
Since curl 7.88.1, if you build curl to support HTTP/3, the above one-liner can be extended to also check for HTTP/3 support like this:
$ curl -sI --http3 https://curl.se -o/dev/null -w '%{http_version}\n'
3
Run
curl --version
and look for HTTP2 on the Features list
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.
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.
Accepted answer doesn't work for h2c in the example I'm looking at. Instead use:
curl --http2 -sI https://curl.se -o/dev/null -w '%{http_version}\n'