Repository navigation
Add DohUrl option for DNS-over-HTTPS support - #1322
Open
ChrisJr404 wants to merge 1 commit into
Open
ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
Expose libcurl's CURLOPT_DOH_URL through a new DohUrl option so requests can resolve names using a DNS-over-HTTPS server. DohUrl follows the existing single string option pattern (like Interface). Session gains SetDohUrl along with a matching SetOption overload. An empty DohUrl clears the option. The new header is registered in cpr.h. Added session tests covering SetDohUrl, SetOption and clearing the option. Closes libcpr#1256
COM8
requested changes
Oct 3, 2026
COM8
left a comment
Member
There was a problem hiding this comment.
@ChrisJr404 thanks for contributing!
For the tests could you add some kind of mich DoH server to to ensure the enabled option actually does something in the backend?
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
DohUrloption that exposes libcurl'sCURLOPT_DOH_URL, letting a session resolve hostnames through a DNS-over-HTTPS server.cpr::Session session; session.SetOption(cpr::DohUrl{"https://dns.google/dns-query"});Closes #1256.
Details
include/cpr/doh_url.hdefinesDohUrl, following the existing single string option pattern (same shape asInterface, built onStringHolder).include/cpr/cpr.h.Session::SetDohUrl(const DohUrl&)wrapscurl_easy_setopt(..., CURLOPT_DOH_URL, ...), with a matchingSetOptionoverload so it works through the variadic option mechanism. An emptyDohUrlclears the option (passesnullptr), matching howSetInterfacehandles the empty case.CURLOPT_DOH_URLhas been available since libcurl 7.62, which is below the versions cpr already requires, so no version guard is needed.Tests
Added
DohUrlTestsintest/session_tests.cppcoveringSetDohUrl,SetOption, and clearing the option. The test server does not run a DoH resolver, so the requests target an IP literal; libcurl only consults the DoH server when it has to resolve a name, so the option is applied and accepted without affecting the request. This mirrors how other curl-option wrappers such asLocalPortare tested.Verification
Built on Linux with
-DCPR_BUILD_TESTS=ONand ran the full suite via ctest: 100% passed (32/32). Changed files were run through the project's clang-format.