Skip to content

Add DohUrl option for DNS-over-HTTPS support - #1322

Open
ChrisJr404 wants to merge 1 commit into
libcpr:masterfrom
ChrisJr404:feat/doh-url
Open

ChrisJr404 wants to merge 1 commit into
libcpr:masterfrom
ChrisJr404:feat/doh-url

Conversation

@ChrisJr404

Copy link
Copy Markdown

Summary

Adds a DohUrl option that exposes libcurl's CURLOPT_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

  • New include/cpr/doh_url.h defines DohUrl, following the existing single string option pattern (same shape as Interface, built on StringHolder).
  • Registered the header in include/cpr/cpr.h.
  • Session::SetDohUrl(const DohUrl&) wraps curl_easy_setopt(..., CURLOPT_DOH_URL, ...), with a matching SetOption overload so it works through the variadic option mechanism. An empty DohUrl clears the option (passes nullptr), matching how SetInterface handles the empty case.
  • CURLOPT_DOH_URL has been available since libcurl 7.62, which is below the versions cpr already requires, so no version guard is needed.

Tests

Added DohUrlTests in test/session_tests.cpp covering SetDohUrl, 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 as LocalPort are tested.

Verification

Built on Linux with -DCPR_BUILD_TESTS=ON and ran the full suite via ctest: 100% passed (32/32). Changed files were run through the project's clang-format.

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 COM8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for libcurl’s DNS-over-HTTPS (DoH) feature?

2 participants