Fixing HTTP/2 curl: (1) Unsupported protocol on MacOS X

Fig.01: Fixing curl: (1) Unsupported protocol on Mac OS X

Fixing curl: (1) Unsupported protocol on Mac OS X

If you run the default version of curl command with --http2 flag, you will get an error that read as follows:
$ curl -I --http2 https://www.nixcraft.com
Sample outputs:

curl: (1) Unsupported protocol

Solution

To fix this problem install an updated version of curl as follows with Nghttp2: HTTP/2 C Library. Open the Terminal app and type the following command:
$ brew install curl --with-nghttp2
Sample outputs:

==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
No changes to formulae.
 
==> Using the sandbox
==> Downloading https://curl.haxx.se/download/curl-7.50.3.tar.bz2
######################################################################## 100.0%
==> ./configure --disable-silent-rules --prefix=/usr/local/Cellar/curl/7.50.3 --with-ssl=/usr/local/opt/openssl --with-ca-bundle=/usr/local/etc/openssl/cert.pem --without-li
==> make install
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
 
macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
 
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
 
    LDFLAGS:  -L/usr/local/opt/curl/lib
    CPPFLAGS: -I/usr/local/opt/curl/include
    PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig
 
==> Summary
?  /usr/local/Cellar/curl/7.50.3: 367 files, 2.6M, built in 2 minutes 6 seconds

Please note the path /usr/local/Cellar/curl/7.50.3

Test it

Type the following command:
$ /usr/local/Cellar/curl/7.50.3/bin/curl -I --http2 https://www.nixcraft.com/
Sample outputs:

HTTP/2 200 
server: nginx
date: Tue, 01 Nov 2016 21:54:13 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
link: ; rel="https://api.w.org/"
link: ; rel=shortlink
strict-transport-security: max-age=15768000
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1

Create a short link in your $HOME as follows:
$ mkdir $HOME/bin/
$ cd $HOME/bin/
$ ln -s /usr/local/Cellar/curl/7.50.3/bin/curl

And use it as follows:
$ ~/bin/curl -I --http2 https://bash.cyberciti.biz/

Examples and usage: How to use curl command with http/2 on MacOS X