| 1 | #ifndef CPR_HTTP_VERSION_H |
| 2 | #define CPR_HTTP_VERSION_H |
| 3 | |
| 4 | #include <curl/curlver.h> |
| 5 | |
| 6 | namespace cpr { |
| 7 | enum class HttpVersionCode { |
| 8 | /** |
| 9 | * Let libcurl decide which version is the best. |
| 10 | **/ |
| 11 | VERSION_NONE, |
| 12 | /** |
| 13 | * Enforce HTTP 1.0 requests. |
| 14 | **/ |
| 15 | VERSION_1_0, |
| 16 | /** |
| 17 | * Enforce HTTP 1.1 requests. |
| 18 | **/ |
| 19 | VERSION_1_1, |
| 20 | #if LIBCURL_VERSION_NUM >= 0x072100 // 7.33.0 |
| 21 | /** |
| 22 | * Attempt HTTP 2.0 requests. |
| 23 | * Fallback to HTTP 1.1 if negotiation fails. |
| 24 | **/ |
| 25 | VERSION_2_0, |
| 26 | #endif |
| 27 | #if LIBCURL_VERSION_NUM >= 0x072F00 // 7.47.0 |
| 28 | /** |
| 29 | * Attempt HTTP 2.0 for HTTPS requests only. |
| 30 | * Fallback to HTTP 1.1 if negotiation fails. |
| 31 | * HTTP 1.1 will be used for HTTP connections. |
| 32 | **/ |
| 33 | VERSION_2_0_TLS, |
| 34 | #endif |
| 35 | #if LIBCURL_VERSION_NUM >= 0x073100 // 7.49.0 |
| 36 | /** |
| 37 | * Start HTTP 2.0 for HTTP requests. |
| 38 | * Requires prior knowledge that the server supports HTTP 2.0. |
| 39 | * For HTTPS requests we will negotiate the protocol version in the TLS handshake. |
| 40 | **/ |
| 41 | VERSION_2_0_PRIOR_KNOWLEDGE, |
| 42 | #endif |
| 43 | #if LIBCURL_VERSION_NUM >= 0x074200 // 7.66.0 |
| 44 | /** |
| 45 | * Attempt HTTP 3.0 requests. |
| 46 | * Requires prior knowledge that the server supports HTTP 3.0 since there is no gracefully downgrade. |
| 47 | * Fallback to HTTP 1.1 if negotiation fails. |
| 48 | **/ |
| 49 | VERSION_3_0 |
| 50 | #endif |
| 51 | }; |
| 52 | |
| 53 | class HttpVersion { |
| 54 | public: |
| 55 | /** |
| 56 | * The HTTP version that should be used by libcurl when initiating a HTTP(S) connection. |
| 57 | * Default: HttpVersionCode::VERSION_NONE |
| 58 | **/ |
| 59 | HttpVersionCode code = HttpVersionCode::VERSION_NONE; |
| 60 | |
| 61 | HttpVersion() = default; |
| 62 | explicit HttpVersion(HttpVersionCode _code) : code(_code) {} |
| 63 | }; |
| 64 | |
| 65 | } // namespace cpr |
| 66 | |
| 67 | #endif |
| 68 | |