Skip to content

Commit

Permalink
Add enforced HTTP/3 version
Browse files Browse the repository at this point in the history
  • Loading branch information
h3xOo committed Feb 11, 2025
1 parent 4c41606 commit 2a147f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cpr/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
9 changes: 8 additions & 1 deletion include/cpr/http_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down

0 comments on commit 2a147f2

Please sign in to comment.