Search code examples
unit-testingcurlhttp2

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?


Solution

  • 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)

    HTTP/3

    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