Improve proxy wrapper: HTTP forwarding, NO_PROXY support, tests#13
Merged
Improve proxy wrapper: HTTP forwarding, NO_PROXY support, tests#13
Conversation
…r handling Inspired by simonw/research go-rod-cli proxy approach, this improves our Python proxy wrapper with several missing capabilities: - Add plain HTTP request forwarding (previously only CONNECT tunnels worked) - Add HTTP_PROXY and NO_PROXY environment variable support - Use dynamic port allocation instead of hardcoded port 18080 - Send proper HTTP error responses (400/502/504) to Chrome instead of silently dropping connections - Replace bare except blocks with typed OSError catches and logging - Extract shared helpers (_build_auth_header, _inject_auth_header, _send_error, _forward_data) - Reduce startup sleep from 500ms to 100ms https://claude.ai/code/session_01G9pCRRAvGKFduD1eosqDA5
The localhost/127.0.0.1/::1 bypass was unreachable when NO_PROXY was empty because of an early return. Move the localhost check before the no_proxy emptiness guard. https://claude.ai/code/session_01G9pCRRAvGKFduD1eosqDA5
The real NO_PROXY env in Claude Code web uses glob syntax like *.googleapis.com and *.svc.cluster.local. Previously only the .domain suffix syntax was handled. Now both forms work: - "*.example.com" matches "sub.example.com" and "example.com" - ".example.com" matches "sub.example.com" and "example.com" Verified with live tests against the real upstream proxy. https://claude.ai/code/session_01G9pCRRAvGKFduD1eosqDA5
- Add 48 unit/integration tests covering: _should_bypass_proxy (NO_PROXY matching), _build_auth_header, _inject_auth_header, _send_error, get_proxy_config, is_claude_code_web_environment, start/stop lifecycle, and end-to-end handle_client with mock upstream proxy - Fix race in stop_proxy_wrapper: accept loop referenced the global _wrapper_server which was set to None before the thread exited, causing AttributeError. Now captures a local reference and joins the thread on shutdown. https://claude.ai/code/session_01G9pCRRAvGKFduD1eosqDA5
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.
Summary
NO_PROXY/HTTP_PROXYenv vars, dynamic port allocation, and proper HTTP error responses (400/502/504) back to Chromelocalhost/127.0.0.1/::1was unreachable whenNO_PROXYwas empty due to an early return*.domainglob pattern support forNO_PROXYmatching — the real Claude Code web environment uses*.googleapis.comstyle patterns, not just.domainsuffix syntaxstop_proxy_wrapperwhere the accept thread referenced a global that was set toNonebefore the thread exited, causingAttributeErrorTest plan
pytest tests/test_proxy_wrapper.py— 48 tests passing