fix: sanitize NO_PROXY env vars containing newline characters#3308
Open
paulxg12 wants to merge 1 commit into
Open
fix: sanitize NO_PROXY env vars containing newline characters#3308paulxg12 wants to merge 1 commit into
paulxg12 wants to merge 1 commit into
Conversation
When NO_PROXY contains newlines (common in Docker, .env files, or shell scripts), httpx's get_environment_proxies() splits only by commas, causing the newline to become part of the hostname and triggering InvalidURL on client creation. This adds a sanitization step in both _DefaultHttpxClient and _DefaultAsyncHttpxClient that replaces newlines with commas so each line becomes a separate NO_PROXY entry. Fixes openai#3303
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.
What
Sanitize
NO_PROXY/no_proxyenvironment variables by replacing embedded newlines with commas before httpx reads them.Why
Fixes #3303. When
NO_PROXYcontains newline characters (common in Docker,.envfiles, and shell scripts), httpx splits only by commas. The newline becomes part of the hostname, triggering:How
Add a
_sanitize_proxy_env_vars()helper that normalises newline-separated entries into comma-separated ones. Call it from both_DefaultHttpxClient.__init__and_DefaultAsyncHttpxClient.__init__so that sync and async clients are both covered.Testing
NO_PROXYhas no newlines, which is the common case).Checklist