From 2a147f2755663555308fd0d182913db94072b2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Wi=C5=9Bniewski?= Date: Tue, 11 Feb 2025 16:10:47 +0100 Subject: [PATCH] Add enforced HTTP/3 version --- cpr/session.cpp | 5 +++++ include/cpr/http_version.h | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cpr/session.cpp b/cpr/session.cpp index 5a42ddc15..6b8c149b4 100644 --- a/cpr/session.cpp +++ b/cpr/session.cpp @@ -618,6 +618,11 @@ void Session::SetHttpVersion(const HttpVersion& version) { curl_easy_setopt(curl_->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3); break; #endif +#if LIBCURL_VERSION_NUM >= 0x075701 // 7.87.1, but corresponds to 7.88.0 tag + case HttpVersionCode::VERSION_3_0_ONLY: + curl_easy_setopt(curl_->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3ONLY); + break; +#endif default: // Should not happen throw std::invalid_argument("Invalid/Unknown HTTP version type."); diff --git a/include/cpr/http_version.h b/include/cpr/http_version.h index 45b502873..3d4d58c6c 100644 --- a/include/cpr/http_version.h +++ b/include/cpr/http_version.h @@ -46,7 +46,14 @@ enum class HttpVersionCode { * Requires prior knowledge that the server supports HTTP 3.0 since there is no gracefully downgrade. * Fallback to HTTP 1.1 if negotiation fails. **/ - VERSION_3_0 + VERSION_3_0, +#endif +#if LIBCURL_VERSION_NUM >= 0x075701 // 7.87.1, but corresponds to 7.88.0 tag + /** + * Enforce HTTP 3.0 requests without fallback. + * Requires prior knowledge that the server supports HTTP 3.0 since there is no gracefully downgrade. + **/ + VERSION_3_0_ONLY #endif };