Skip to content

Handle blank proxy environment variables as unset - #85

Merged
josevalim merged 3 commits into
phoenixframework:mainfrom
ARAYN7011:blank-proxy-env
Nov 27, 2026
Merged

josevalim merged 3 commits into
phoenixframework:mainfrom
ARAYN7011:blank-proxy-env

Conversation

@ARAYN7011

Copy link
Copy Markdown
Contributor

Fixes #80

HTTP_PROXY="" (or HTTPS_PROXY="") was treated as a configured proxy, so fetch_package!/2 crashed trying to build {host, port} from an empty URI. proxy_for_scheme/1 now ignores blank values (and falls back to the lowercase variable), as suggested in the issue. proxy_auth/1 uses the same function, so it is fixed too.

Test plan:

  • New test/npm_registry_test.exs (3 tests: configured proxy, blank treated as unset, lowercase fallback); mix format --check-formatted clean. The existing tests download esbuild from the network, so I only ran the new file.

AI assistance disclosure: this change was written with Claude (Claude Code) and reviewed/tested by me.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: ARAYN7011 <88572149+ARAYN7011@users.noreply.github.com>
@josevalim

Copy link
Copy Markdown
Member

Thank you, we already have similar code in phoenixframework/tailwind, maybe we can port that version instead to ease maintenance?

Signed-off-by: ARAYN7011 <88572149+ARAYN7011@users.noreply.github.com>
@ARAYN7011

Copy link
Copy Markdown
Contributor Author

Thanks @josevalim. Ported the tailwind version (get_and_sanitize_env_var/1, which trims and treats blank as unset) in 6768beb, so the two repos now match. The tests are kept and I added a whitespace-trim case; mix format is clean and the new tests pass.

assert Esbuild.NpmRegistry.proxy_for_scheme("http") == nil
assert Esbuild.NpmRegistry.proxy_for_scheme("https") == nil
end

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.

Let's use a tag for tests:

@tag envs: %{"HTTP_PROXY" => ""}

This way setup knows exactly which tags to set and which ones to reset, instead of traversing the whole environment. It should be faster, simpler, and fewer LOCs!

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

Copy link
Copy Markdown
Contributor Author

Done in ec37942: the tests now use @tag envs: %{...}, and setup clears the proxy variables, applies the tagged ones and restores everything in on_exit. Format is clean; the 4 tests pass (run standalone, since fetching deps is not possible here).

@josevalim
josevalim merged commit 42842da into phoenixframework:main Nov 27, 2026
2 checks passed
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.

Handle blank proxy environment variables

2 participants