1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_HTTP_VERSION
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_ALTSVC (3)
9  - CURLOPT_HTTP09_ALLOWED (3)
10  - CURLOPT_HTTP200ALIASES (3)
11  - CURLOPT_SSLVERSION (3)
12---
13
14# NAME
15
16CURLOPT_HTTP_VERSION - HTTP protocol version to use
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTP_VERSION, long version);
24~~~
25
26# DESCRIPTION
27
28Pass *version* a long, set to one of the values described below. They ask
29libcurl to use the specific HTTP versions.
30
31Note that the HTTP version is just a request. libcurl still prioritizes to
32reuse existing connections so it might then reuse a connection using an HTTP
33version you have not asked for.
34
35## CURL_HTTP_VERSION_NONE
36
37We do not care about what version the library uses. libcurl uses whatever it
38thinks fit.
39
40## CURL_HTTP_VERSION_1_0
41
42Enforce HTTP 1.0 requests.
43
44## CURL_HTTP_VERSION_1_1
45
46Enforce HTTP 1.1 requests.
47
48## CURL_HTTP_VERSION_2_0
49
50Attempt HTTP 2 requests. libcurl falls back to HTTP 1.1 if HTTP 2 cannot be
51negotiated with the server. (Added in 7.33.0)
52
53When libcurl uses HTTP/2 over HTTPS, it does not itself insist on TLS 1.2 or
54higher even though that is required by the specification. A user can add this
55version requirement with CURLOPT_SSLVERSION(3).
56
57The alias *CURL_HTTP_VERSION_2* was added in 7.43.0 to better reflect the
58actual protocol name.
59
60## CURL_HTTP_VERSION_2TLS
61
62Attempt HTTP 2 over TLS (HTTPS) only. libcurl falls back to HTTP 1.1 if HTTP 2
63cannot be negotiated with the HTTPS server. For clear text HTTP servers,
64libcurl uses 1.1. (Added in 7.47.0)
65
66## CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
67
68Issue non-TLS HTTP requests using HTTP/2 without HTTP/1.1 Upgrade. It requires
69prior knowledge that the server supports HTTP/2 straight away. HTTPS requests
70still do HTTP/2 the standard way with negotiated protocol version in the TLS
71handshake. (Added in 7.49.0)
72
73## CURL_HTTP_VERSION_3
74
75(Added in 7.66.0) This option makes libcurl attempt to use HTTP/3 to the host
76given in the URL, with fallback to earlier HTTP versions if needed.
77
78## CURL_HTTP_VERSION_3ONLY
79
80(Added in 7.88.0) Setting this makes libcurl attempt to use HTTP/3 directly to
81server given in the URL and does not downgrade to earlier HTTP version if the
82server does not support HTTP/3.
83
84# DEFAULT
85
86Since curl 7.62.0: CURL_HTTP_VERSION_2TLS
87
88Before that: CURL_HTTP_VERSION_1_1
89
90# PROTOCOLS
91
92HTTP
93
94# EXAMPLE
95
96~~~c
97int main(void)
98{
99  CURL *curl = curl_easy_init();
100  if(curl) {
101    CURLcode ret;
102    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
103    curl_easy_setopt(curl, CURLOPT_HTTP_VERSION,
104                     (long)CURL_HTTP_VERSION_2TLS);
105    ret = curl_easy_perform(curl);
106    if(ret == CURLE_HTTP_RETURNED_ERROR) {
107      /* an HTTP response error problem */
108    }
109  }
110}
111~~~
112
113# AVAILABILITY
114
115Along with HTTP
116
117# RETURN VALUE
118
119Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
120