Home > Back-end >  libcurl - CURLOPT_HTTP_VERSION (HTTP2 without TLS)
libcurl - CURLOPT_HTTP_VERSION (HTTP2 without TLS)

Time:12-07

libcurl has option CURLOPT_HTTP_VERSION with next parameters:

CURL_HTTP_VERSION_2TLS:

Attempt HTTP 2 over TLS (HTTPS) only.

CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE:

Issue non-TLS HTTP requests using HTTP/2

Doesn 't http 2 work automatically with a TLS Connection ? Can http 2 be with an open non - encrypted connection ?

CodePudding user response:

Yes, HTTP/2 can work without encryption. But most of implementations supports only encrypted requests. As of mentioned parameters they are described in documentation:

CURL_HTTP_VERSION_2TLS

Attempt HTTP 2 over TLS (HTTPS) only. libcurl will fall back to HTTP 1.1 if HTTP 2 cannot be negotiated with the HTTPS server. For clear text HTTP servers, libcurl will use 1.1. (Added in 7.47.0)

CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE

Issue non-TLS HTTP requests using HTTP/2 without HTTP/1.1 Upgrade. It requires prior knowledge that the server supports HTTP/2 straight away. HTTPS requests will still do HTTP/2 the standard way with negotiated protocol version in the TLS handshake. (Added in 7.49.0)

So CURL_HTTP_VERSION_2TLS has fallback to HTTP 1.1 protocol and CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE tries only HTTP/2 (with TLS for HTTPS request and without it for HTTP request).

  •  Tags:  
  • c
  • Related