From 92f46ba2af9451a05e197b1d4297488195e00143 Mon Sep 17 00:00:00 2001 From: Jay Caines-Gooby Date: Sun, 19 May 2019 20:47:02 +0100 Subject: [PATCH] Fallback to http1.1 if http2 isn't supported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #4. Even though the curl command may show that the `--http2` option is available, the version of libcurl that's been linked against might not support it. Thanks for the tipoff @moeffju 🎉 --- ttfb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ttfb b/ttfb index 3a4cb1f..4c67910 100755 --- a/ttfb +++ b/ttfb @@ -65,6 +65,10 @@ for dependency in curl bc column; do which $dependency > /dev/null || (echo "You need to have '$dependency' installed and in your \$PATH" >&2 && exit 1) done +# check curl can use http2 +HTTP_VERSION="--http2" +curl -so /dev/null --http2 https://example.com || HTTP_VERSION="--http1.1" + # Cribbed from https://stackoverflow.com/a/41762669/391826 median() { arr=($(printf '%s\n' "${@}" | sort -n)) @@ -131,7 +135,7 @@ options=() options+=(-o /dev/null) options+=(-s) options+=(-L) -options+=(--http2) +options+=($HTTP_VERSION) options+=(-H 'Cache-Control: no-cache') options+=(-w 'echo DNS lookup: %{time_namelookup} TLS handshake: %{time_appconnect} TTFB including connection: %{time_starttransfer} TTFB: $(echo %{time_starttransfer} - %{time_appconnect} | bc) Total time: %{time_total} \n') if [ $DEBUG -eq 1 ]; then