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