Curl: one-liner to test http/2 support

bn4t picture bn4t · Jul 11, 2018 · Viewed 19.4k times · Source

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?

Answer

Daniel Stenberg picture Daniel Stenberg · Jul 11, 2018

HTTP/2 supported:

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

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

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

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