Skip to content

Fixing missed arguments for pools when init transports - #2997

Open
NewUserHa wants to merge 10 commits into
encode:masterfrom
NewUserHa:patch-1
Open

NewUserHa wants to merge 10 commits into
encode:masterfrom
NewUserHa:patch-1

Conversation

@NewUserHa

Copy link
Copy Markdown

Summary

class AsyncHTTPTransport(AsyncBaseTransport):
def __init__(
self,
verify: VerifyTypes = True,
cert: typing.Optional[CertTypes] = None,
http1: bool = True,
http2: bool = False,
limits: Limits = DEFAULT_LIMITS,
trust_env: bool = True,
proxy: typing.Optional[Proxy] = None,
uds: typing.Optional[str] = None,
local_address: typing.Optional[str] = None,
retries: int = 0,
socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None,
) -> None:
ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
if proxy is None:
self._pool = httpcore.AsyncConnectionPool(
ssl_context=ssl_context,
max_connections=limits.max_connections,
max_keepalive_connections=limits.max_keepalive_connections,
keepalive_expiry=limits.keepalive_expiry,
http1=http1,
http2=http2,
uds=uds,
local_address=local_address,
retries=retries,
socket_options=socket_options,
)
elif proxy.url.scheme in ("http", "https"):
self._pool = httpcore.AsyncHTTPProxy(
proxy_url=httpcore.URL(
scheme=proxy.url.raw_scheme,
host=proxy.url.raw_host,
port=proxy.url.port,
target=proxy.url.raw_path,
),
proxy_auth=proxy.raw_auth,
proxy_headers=proxy.headers.raw,
ssl_context=ssl_context,
max_connections=limits.max_connections,
max_keepalive_connections=limits.max_keepalive_connections,
keepalive_expiry=limits.keepalive_expiry,
http1=http1,
http2=http2,
socket_options=socket_options,
)
elif proxy.url.scheme == "socks5":
try:
import socksio # noqa
except ImportError: # pragma: no cover
raise ImportError(
"Using SOCKS proxy, but the 'socksio' package is not installed. "
"Make sure to install httpx using `pip install httpx[socks]`."
) from None
self._pool = httpcore.AsyncSOCKSProxy(
proxy_url=httpcore.URL(
scheme=proxy.url.raw_scheme,
host=proxy.url.raw_host,
port=proxy.url.port,
target=proxy.url.raw_path,
),
proxy_auth=proxy.raw_auth,
ssl_context=ssl_context,
max_connections=limits.max_connections,
max_keepalive_connections=limits.max_keepalive_connections,
keepalive_expiry=limits.keepalive_expiry,
http1=http1,
http2=http2,
)
else: # pragma: no cover

eg.

  • in AsyncHTTPTransport, AsyncConnectionPool has the argument of retries passed in, but AsyncHTTPProxy and AsyncSOCKSProxy have not;
  • in HTTPTransport, it has the same issue.

discussion: #2988

This also requires a fix in https://github.com/encode/httpcore

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@NewUserHa

Copy link
Copy Markdown
Author

The PR requires encode/httpcore#857 PR to pass checks

@lovelydinosaur

Copy link
Copy Markdown
Member

The PR requires encode/httpcore#857 PR to pass checks

Can we just start by considering retries here? That's already supported by httpcore>1.0, right?

@NewUserHa

Copy link
Copy Markdown
Author

Ok, done.

Should open a new PR for the rest missed arguments?

@lovelydinosaur

Copy link
Copy Markdown
Member

Okay, first up let's just have a sanity check... do connection retries actually get applied when connecting to proxies?

@NewUserHa

Copy link
Copy Markdown
Author

The SocksProxy?

b2l added a commit to LeComptoirDesPharmacies/openapi-generator that referenced this pull request Nov 25, 2026
- Only build the retry transport for a positive retries count.
- Document httpx's limits instead of working around them: proxies from
  environment variables are ignored with a custom transport, and requests
  sent through a proxy are not retried (encode/httpx#2997). Each attempt
  gets the full connect timeout.
- Tests count real connection attempts instead of transport kwargs, and
  cover retries=0 and negative values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b2l added a commit to LeComptoirDesPharmacies/openapi-generator that referenced this pull request Nov 25, 2026
httpx does not retry through a proxy (encode/httpx#2997), and a custom
transport disables proxies from environment variables. Building the retry
transport with a proxy brought no retry and broke environment proxies.

Only build it for direct connections: no Configuration.proxy and no proxy
from the environment (urllib.request.getproxies, as httpx does). Otherwise
the client is built as before, so this change is not breaking.

Tests pin that behavior for explicit and environment proxies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Development

Successfully merging this pull request may close these issues.

3 participants