CURLOPT_HTTP_VERSION.3 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. .\" generated by cd2nroff 0.1 from CURLOPT_HTTP_VERSION.md
  2. .TH CURLOPT_HTTP_VERSION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_HTTP_VERSION \- HTTP protocol version to use
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTP_VERSION, long version);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass \fIversion\fP a long, set to one of the values described below. They ask
  12. libcurl to use the specific HTTP versions.
  13. Note that the HTTP version is just a request. libcurl still prioritizes to
  14. reuse existing connections so it might then reuse a connection using an HTTP
  15. version you have not asked for.
  16. .IP CURL_HTTP_VERSION_NONE
  17. We do not care about what version the library uses. libcurl uses whatever it
  18. thinks fit.
  19. .IP CURL_HTTP_VERSION_1_0
  20. Enforce HTTP 1.0 requests.
  21. .IP CURL_HTTP_VERSION_1_1
  22. Enforce HTTP 1.1 requests.
  23. .IP CURL_HTTP_VERSION_2_0
  24. Attempt HTTP 2 requests. libcurl falls back to HTTP 1.1 if HTTP 2 cannot be
  25. negotiated with the server. (Added in 7.33.0)
  26. When libcurl uses HTTP/2 over HTTPS, it does not itself insist on TLS 1.2 or
  27. higher even though that is required by the specification. A user can add this
  28. version requirement with \fICURLOPT_SSLVERSION(3)\fP.
  29. The alias \fICURL_HTTP_VERSION_2\fP was added in 7.43.0 to better reflect the
  30. actual protocol name.
  31. .IP CURL_HTTP_VERSION_2TLS
  32. Attempt HTTP 2 over TLS (HTTPS) only. libcurl falls back to HTTP 1.1 if HTTP 2
  33. cannot be negotiated with the HTTPS server. For clear text HTTP servers,
  34. libcurl uses 1.1. (Added in 7.47.0)
  35. .IP CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE
  36. Issue non\-TLS HTTP requests using HTTP/2 without HTTP/1.1 Upgrade. It requires
  37. prior knowledge that the server supports HTTP/2 straight away. HTTPS requests
  38. still do HTTP/2 the standard way with negotiated protocol version in the TLS
  39. handshake. (Added in 7.49.0)
  40. .IP CURL_HTTP_VERSION_3
  41. (Added in 7.66.0) This option makes libcurl attempt to use HTTP/3 to the host
  42. given in the URL, with fallback to earlier HTTP versions if needed.
  43. .IP CURL_HTTP_VERSION_3ONLY
  44. (Added in 7.88.0) Setting this makes libcurl attempt to use HTTP/3 directly to
  45. server given in the URL and does not downgrade to earlier HTTP version if the
  46. server does not support HTTP/3.
  47. .SH DEFAULT
  48. Since curl 7.62.0: CURL_HTTP_VERSION_2TLS
  49. Before that: CURL_HTTP_VERSION_1_1
  50. .SH PROTOCOLS
  51. This functionality affects http only
  52. .SH EXAMPLE
  53. .nf
  54. int main(void)
  55. {
  56. CURL *curl = curl_easy_init();
  57. if(curl) {
  58. CURLcode ret;
  59. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  60. curl_easy_setopt(curl, CURLOPT_HTTP_VERSION,
  61. (long)CURL_HTTP_VERSION_2TLS);
  62. ret = curl_easy_perform(curl);
  63. if(ret == CURLE_HTTP_RETURNED_ERROR) {
  64. /* an HTTP response error problem */
  65. }
  66. }
  67. }
  68. .fi
  69. .SH AVAILABILITY
  70. Added in curl 7.9.1
  71. .SH RETURN VALUE
  72. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
  73. .SH SEE ALSO
  74. .BR CURLOPT_ALTSVC (3),
  75. .BR CURLOPT_HTTP09_ALLOWED (3),
  76. .BR CURLOPT_HTTP200ALIASES (3),
  77. .BR CURLOPT_SSLVERSION (3)