pyodide: preserve User-Agent header in httpx and httpx2 requests - #7440
Closed
spideydotjs wants to merge 2 commits into
Closed
spideydotjs wants to merge 2 commits into
spideydotjs wants to merge 2 commits into
Conversation
In Python Workers, outbound requests using httpx or httpx2 silently
dropped custom User-Agent headers. Direct calls via fetch(req) preserved
the header as expected.
In the Emscripten fetch transports used by httpx (0.28.1) and httpx2
(via httpx2_jsfetch), HEADERS_TO_IGNORE = ("user-agent",) explicitly
stripped the header to avoid browser console warnings, where User-Agent
is considered a forbidden request header. In workerd and Node.js,
fetch() fully allows setting custom User-Agent headers without restriction.
Register import execution patches for both httpx._transports.emscripten
and httpx2_jsfetch in entropy_import_context_packages.py, clearing
module.HEADERS_TO_IGNORE to an empty tuple upon module execution.
Add regression unit test in test_entropy_patches.py and wire the
unit-test-entropy-patches target in src/pyodide/BUILD.bazel.
Fixes cloudflare#7242
Add a dedicated workflow in .github/workflows/python-tests.yml running on ubuntu-latest. The workflow executes matrix unit testing across Python 3.12 and 3.13, runs the containerized test suite in python:3.12-slim via Docker, and verifies git diff whitespace hygiene. Add /.context/ to .gitignore to exclude local investigation scratchpads.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
|
Sorry, we do not want to fix this by patching the package in workerd. Instead, this needs to be upstreamed to httpx2. |
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.
Fixes #7242
Problem
In Python Workers, outbound requests using httpx or httpx2 silently dropped custom User-Agent headers, whereas direct calls via fetch(req) preserved them.
In the Emscripten fetch transports used by httpx (0.28.1) and httpx2 (via httpx2_jsfetch), HEADERS_TO_IGNORE = ("user-agent",) explicitly stripped the header to avoid browser console warnings, where User-Agent is considered a forbidden request header. In workerd and Node.js, fetch() fully allows setting custom User-Agent headers without restriction.
Solution