Solution using curl
command as the existing curl solution did not work well for me. curl
provides a switch --http2-prior-knowledge
which ensures a direct HTTP/2 request is sent without attempting a HTTP/1.1 upgrade request. Below examples can help understand the behavior in different cases:
Curl to Google which supports HTTP/2 - automatically HTTP/2 is chosen.
curl -Iks https://www.google.com/robots.txt
HTTP/2 200
accept-ranges: bytes
vary: Accept-Encoding
content-type: text/plain
content-length: 7199
cross-origin-resource-policy: cross-origin
date: Fri, 21 May 2021 13:39:02 GMT
expires: Fri, 21 May 2021 13:39:02 GMT
cache-control: private, max-age=0
Curl to my server which does not supports HTTP/2 - response states HTTP/1.1
curl -Iks https://myserver/reset
HTTP/1.1 502 Bad Gateway
connection: close
content-length: 0
Curl to my server with --http2
switch. Response still states HTTP/1.1
curl -Iks --http2 https://myserver/reset
HTTP/1.1 502 Bad Gateway
connection: close
content-length: 0
Curl to my server with --http2-prior-knowledge
. Note that no response is obtained.
curl -Iks --http2-prior-knowledge https://myserver/reset
If the above is executed with v
switch (verbose), the output would include the below line.
* http2 error: Remote peer returned unexpected data while we expected SETTINGS frame. Perhaps, peer does not support HTTP/2 properly.
Note:
- Switch
k
is for insecure
- my server uses a self signed certificate. Not needed otherwise.
- Switch
I
is to send a HEAD
request and avoid noise in output.
- Above is captured with curl 7.58.0 on Ubuntu 18.04
http2://
would not make any sense, because it's still the samehttp
protocol, just another version. Having onehttp://
uri makes fallback possible, so if possible version 2 is used, otherwise fallback to v1. – Rosannrosannahttp2://
if its available? And prependhttps://
if its not. I mean using this theory there would be no reason to prependhttps://
right? Not trying to be a smart guy, I am just curious. – Laager