From aa66f68e30b96ba80e41fc7226cd35b76771cced Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Wed, 18 Nov 2026 12:33:14 +0000 Subject: [PATCH 1/9] Actually use HickoryResolver by default --- src/client.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client.rs b/src/client.rs index cc1e2c3e..d1e047bc 100644 --- a/src/client.rs +++ b/src/client.rs @@ -500,6 +500,8 @@ impl Client { apply_option!(set_if_some, builder, config.zstd, zstd); raise_for_status = config.raise_for_status.unwrap_or(false); + } else { + builder = builder.dns_resolver(HickoryResolver::new(LookupIpStrategy::default())?); } builder From d685d370a8e83f5e742d693dfd9a9f30b40f468f Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Fri, 20 Nov 2026 13:07:02 +0000 Subject: [PATCH 2/9] Use getaddrinfo by default --- src/client.rs | 9 ++------- src/dns.rs | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/client.rs b/src/client.rs index d1e047bc..f3f566c4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -25,7 +25,7 @@ use self::{ use crate::{ cookie::Jar, coroutine::{self, Coroutine}, - dns::{DnsOptions, HickoryResolver, LookupIpStrategy}, + dns::{DnsOptions, HickoryResolver}, emulate::EmulationLike, error::Error, extractor::Extractor, @@ -488,10 +488,7 @@ impl Client { builder = builder.dns_resolver(HickoryResolver::new(opts.lookup_ip_strategy)?); } - } else { - builder = - builder.dns_resolver(HickoryResolver::new(LookupIpStrategy::default())?); - }; + } // Compression options. apply_option!(set_if_some, builder, config.gzip, gzip); @@ -500,8 +497,6 @@ impl Client { apply_option!(set_if_some, builder, config.zstd, zstd); raise_for_status = config.raise_for_status.unwrap_or(false); - } else { - builder = builder.dns_resolver(HickoryResolver::new(LookupIpStrategy::default())?); } builder diff --git a/src/dns.rs b/src/dns.rs index 704357c0..3cb2a94f 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -52,7 +52,7 @@ impl DnsOptions { /// `lookup_ip_strategy` only applies to hickory and has no effect when /// using the system DNS resolver. #[new] - #[pyo3(signature=(system_dns = false, lookup_ip_strategy = LookupIpStrategy::IPV4_AND_IPV6))] + #[pyo3(signature=(system_dns = true, lookup_ip_strategy = LookupIpStrategy::IPV4_AND_IPV6))] pub fn new(system_dns: bool, lookup_ip_strategy: LookupIpStrategy) -> Self { DnsOptions { system_dns, From 422c4d22231211a9e6522f2d44e71947feb09563 Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Fri, 20 Nov 2026 14:05:04 +0000 Subject: [PATCH 3/9] Update tests --- tests/dns_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/dns_test.py b/tests/dns_test.py index b1461f4d..aacbeec0 100644 --- a/tests/dns_test.py +++ b/tests/dns_test.py @@ -60,7 +60,7 @@ def request(): # Exercise actual hostname resolution, including the default resolver. await fetch("localhost", None) await fetch("localhost", DnsOptions(system_dns=True)) - await fetch("localhost", DnsOptions(lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY)) + await fetch("localhost", DnsOptions(system_dns=False, lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY)) # Every strategy must initialize and preserve explicit address overrides. for strategy in ( @@ -70,7 +70,7 @@ def request(): LookupIpStrategy.IPV6_THEN_IPV4, LookupIpStrategy.IPV4_THEN_IPV6, ): - options = DnsOptions(lookup_ip_strategy=strategy) + options = DnsOptions(system_dns=False, lookup_ip_strategy=strategy) options.add_resolve("dns-test.invalid", [IPv4Address("127.0.0.1")]) await fetch("dns-test.invalid", options) @@ -78,7 +78,7 @@ def request(): @pytest.mark.asyncio async def test_dns_resolve_override(dns_http_server): # An override wins over the real address of a resolvable host. - dns_options = DnsOptions(lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY) + dns_options = DnsOptions(system_dns=False, lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY) dns_options.add_resolve("www.google.com", [IPv4Address("127.0.0.1")]) async with wreq.Client(dns_options=dns_options, no_proxy=True) as client: url = f"http://www.google.com:{dns_http_server}/" From 1da30262352faaeb005d1813454d443170ba2a7e Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Fri, 20 Nov 2026 14:11:53 +0000 Subject: [PATCH 4/9] Detect default resolver in tests --- tests/dns_test.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/dns_test.py b/tests/dns_test.py index aacbeec0..f21e459d 100644 --- a/tests/dns_test.py +++ b/tests/dns_test.py @@ -1,4 +1,5 @@ import asyncio +import platform import threading from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from ipaddress import IPv4Address @@ -84,3 +85,31 @@ async def test_dns_resolve_override(dns_http_server): url = f"http://www.google.com:{dns_http_server}/" async with await asyncio.wait_for(client.get(url), 5) as response: assert await response.text() == "DNS resolved" + + +async def invalid_name_resolve_error(client: wreq.Client) -> str: + # A 64-byte label is not a valid DNS name, so every resolver fails without + # sending a query, each with its own error. + async with client: + with pytest.raises(wreq.exceptions.ConnectionError) as exc_info: + await client.get(f"http://{'a' * 64}.invalid/") + return str(exc_info.value) + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "use_dns_options", [False, True], ids=["no_kwargs", "dns_options"] +) +async def test_default_dns_resolver_is_getaddrinfo(use_dns_options: bool): + # Control: hickory rejects the name while parsing it. If this stops holding, + # the assertions below no longer tell the resolvers apart. + hickory_client = wreq.Client(dns_options=DnsOptions(system_dns=False)) + assert "LabelBytesTooLong" in await invalid_name_resolve_error(hickory_client) + + client = wreq.Client(dns_options=DnsOptions()) if use_dns_options else wreq.Client() + error = await invalid_name_resolve_error(client) + assert "LabelBytesTooLong" not in error + if platform.system() != "Windows": + # std's getaddrinfo wrapper prefixes every EAI_* failure with this; + # Windows reports a localized WSA error instead. + assert "failed to lookup address information" in error From d2755be4bab1607b8a1bd1e3be378dce8fd0bd2a Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Fri, 20 Nov 2026 15:48:25 +0000 Subject: [PATCH 5/9] Wrap request in wait_for in dns tests --- tests/dns_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/dns_test.py b/tests/dns_test.py index f21e459d..2bd7326d 100644 --- a/tests/dns_test.py +++ b/tests/dns_test.py @@ -92,7 +92,8 @@ async def invalid_name_resolve_error(client: wreq.Client) -> str: # sending a query, each with its own error. async with client: with pytest.raises(wreq.exceptions.ConnectionError) as exc_info: - await client.get(f"http://{'a' * 64}.invalid/") + async with await asyncio.wait_for(client.get(f"http://{'a' * 64}.invalid/"), 5): + pass return str(exc_info.value) From 01b867c7d95a29ef4c57a9be2c8f3b92aae87f47 Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Fri, 20 Nov 2026 15:48:38 +0000 Subject: [PATCH 6/9] Add release note --- RELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE.md b/RELEASE.md index 8604b96b..dd18c351 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -5,6 +5,7 @@ - Unknown keyword arguments now raise `TypeError` when calling async or blocking client constructors, HTTP or WebSocket request methods and functions, `Http1Options`, `Http2Options`, `TlsOptions`, or `Proxy` factories. These arguments were previously ignored. - Set client-only options such as `connect_timeout` and `proxies` on `Client`; passing them to a request now raises `TypeError`. Use `proxy` to select a proxy for one request. - Async request calls check keyword names before returning a coroutine. Values for supported request keywords are still converted on first `await` or entry with `async with`. +- System DNS is consistently used by default. Previously, the behavior differed between no kwargs and any unrelated kwarg being set. ## [0.11.0](https://github.com/0x676e67/wreq-python/compare/v0.10.2..v0.11.0) - 2026-04-13 From 3dd3fdf167e96233b0a29abb7388baeb90801316 Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Fri, 20 Nov 2026 15:48:48 +0000 Subject: [PATCH 7/9] Update docs and stubs --- docs/source/guide/advanced.md | 6 +++--- python/wreq/dns.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/guide/advanced.md b/docs/source/guide/advanced.md index c1a815c2..62f2f750 100644 --- a/docs/source/guide/advanced.md +++ b/docs/source/guide/advanced.md @@ -129,15 +129,15 @@ enable logging only when you need it. ## DNS and protocol options `dns_options` selects the resolver and can override specific host addresses. -Overrides retain the URL's hostname for HTTP and TLS. This configuration uses -system DNS; omit it to use the default Hickory resolver: +Overrides retain the URL's hostname for HTTP and TLS. Set `system_dns=False` to +use the Hickory resolver instead of system DNS (such as `getaddrinfo` on Linux). ```python from wreq.blocking import Client from wreq.dns import DnsOptions -with Client(dns_options=DnsOptions(system_dns=True)) as client: +with Client(dns_options=DnsOptions(system_dns=False)) as client: with client.get("https://httpbin.io/get") as response: print(response.text()) ``` diff --git a/python/wreq/dns.py b/python/wreq/dns.py index 3690cc58..9843fc64 100644 --- a/python/wreq/dns.py +++ b/python/wreq/dns.py @@ -52,7 +52,7 @@ class DnsOptions: def __init__( self, - system_dns: bool = False, + system_dns: bool = True, lookup_ip_strategy: LookupIpStrategy = LookupIpStrategy.IPV4_AND_IPV6, ) -> None: """Create a new DnsOptions. From 692eb9203bc2e9b174c8bada4fd987ecc5bfae06 Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Fri, 20 Nov 2026 16:01:36 +0000 Subject: [PATCH 8/9] Test formatting + blocking client --- tests/dns_test.py | 48 +++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/dns_test.py b/tests/dns_test.py index 2bd7326d..a8667b42 100644 --- a/tests/dns_test.py +++ b/tests/dns_test.py @@ -1,11 +1,11 @@ import asyncio import platform import threading +from datetime import timedelta from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from ipaddress import IPv4Address import pytest - import wreq from wreq import blocking from wreq.dns import DnsOptions, LookupIpStrategy @@ -47,21 +47,22 @@ async def fetch(host, options): if blocking_api: def request(): - with blocking.Client(**kwargs) as client: - with client.get(url) as response: - return response.text() + with blocking.Client(**kwargs) as client, client.get(url) as response: + return response.text() body = await asyncio.to_thread(request) else: - async with wreq.Client(**kwargs) as client: - async with client.get(url) as response: - body = await response.text() + async with wreq.Client(**kwargs) as client, client.get(url) as response: + body = await response.text() assert body == "DNS resolved" # Exercise actual hostname resolution, including the default resolver. await fetch("localhost", None) await fetch("localhost", DnsOptions(system_dns=True)) - await fetch("localhost", DnsOptions(system_dns=False, lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY)) + await fetch( + "localhost", + DnsOptions(system_dns=False, lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY), + ) # Every strategy must initialize and preserve explicit address overrides. for strategy in ( @@ -79,7 +80,9 @@ def request(): @pytest.mark.asyncio async def test_dns_resolve_override(dns_http_server): # An override wins over the real address of a resolvable host. - dns_options = DnsOptions(system_dns=False, lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY) + dns_options = DnsOptions( + system_dns=False, lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY + ) dns_options.add_resolve("www.google.com", [IPv4Address("127.0.0.1")]) async with wreq.Client(dns_options=dns_options, no_proxy=True) as client: url = f"http://www.google.com:{dns_http_server}/" @@ -87,12 +90,20 @@ async def test_dns_resolve_override(dns_http_server): assert await response.text() == "DNS resolved" -async def invalid_name_resolve_error(client: wreq.Client) -> str: +async def invalid_name_resolve_error(client: wreq.Client | blocking.Client) -> str: # A 64-byte label is not a valid DNS name, so every resolver fails without # sending a query, each with its own error. - async with client: - with pytest.raises(wreq.exceptions.ConnectionError) as exc_info: - async with await asyncio.wait_for(client.get(f"http://{'a' * 64}.invalid/"), 5): + url = f"http://{'a' * 64}.invalid/" + + def request_blocking(blocking_client: blocking.Client) -> None: + with blocking_client, blocking_client.get(url, timeout=timedelta(seconds=5)): + pass + + with pytest.raises(wreq.exceptions.ConnectionError) as exc_info: + if isinstance(client, blocking.Client): + await asyncio.to_thread(request_blocking, client) + else: + async with client, await asyncio.wait_for(client.get(url), 5): pass return str(exc_info.value) @@ -101,13 +112,18 @@ async def invalid_name_resolve_error(client: wreq.Client) -> str: @pytest.mark.parametrize( "use_dns_options", [False, True], ids=["no_kwargs", "dns_options"] ) -async def test_default_dns_resolver_is_getaddrinfo(use_dns_options: bool): +@pytest.mark.parametrize( + "client_type", [wreq.Client, blocking.Client], ids=["async", "blocking"] +) +async def test_default_dns_resolver_is_getaddrinfo( + use_dns_options: bool, client_type: type[wreq.Client | blocking.Client] +): # Control: hickory rejects the name while parsing it. If this stops holding, # the assertions below no longer tell the resolvers apart. - hickory_client = wreq.Client(dns_options=DnsOptions(system_dns=False)) + hickory_client = client_type(dns_options=DnsOptions(system_dns=False)) assert "LabelBytesTooLong" in await invalid_name_resolve_error(hickory_client) - client = wreq.Client(dns_options=DnsOptions()) if use_dns_options else wreq.Client() + client = client_type(dns_options=DnsOptions()) if use_dns_options else client_type() error = await invalid_name_resolve_error(client) assert "LabelBytesTooLong" not in error if platform.system() != "Windows": From 24ec68f6326d27f05e7fde34d7dccd04134914a9 Mon Sep 17 00:00:00 2001 From: Roman Zhikharevich Date: Fri, 20 Nov 2026 16:05:11 +0000 Subject: [PATCH 9/9] Add test for overriden system dns --- tests/dns_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/dns_test.py b/tests/dns_test.py index a8667b42..1f15f285 100644 --- a/tests/dns_test.py +++ b/tests/dns_test.py @@ -64,6 +64,10 @@ def request(): DnsOptions(system_dns=False, lookup_ip_strategy=LookupIpStrategy.IPV4_ONLY), ) + options = DnsOptions(system_dns=True) + options.add_resolve("dns-test.invalid", [IPv4Address("127.0.0.1")]) + await fetch("dns-test.invalid", options) + # Every strategy must initialize and preserve explicit address overrides. for strategy in ( LookupIpStrategy.IPV4_ONLY,