Document per-request HTTP headers for Streamable HTTP clients - #3288
Open
HaoChiBao wants to merge 2 commits into
Open
Document per-request HTTP headers for Streamable HTTP clients#3288HaoChiBao wants to merge 2 commits into
HaoChiBao wants to merge 2 commits into
Conversation
Show how contextvars plus an httpx2 request event hook on a shared AsyncClient cover per-call Authorization and trace headers without new Client API, addressing modelcontextprotocol#1966.
Avoid a partial-covered POST-only branch and match the usual session_manager pragma so fail_under=100 passes.
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
contextvarsand anhttpx2event_hooks["request"]hook on a sharedAsyncClient(docs_src/client_transports/tutorial005.py+ section indocs/client/transports.md).Clientcall reach the request hook as headers over in-process Streamable HTTP.Fixes #1966
AI disclosure
AI-assisted drafting (Cursor). I reviewed the resulting docs/example/tests and verified them locally.
Test plan
uv run --frozen ruff format/ruff check --fixon touched filesuv run --frozen pyrighton touched filesuv run --frozen pytest tests/docs_src/test_client_transports.py -v(7 passed)--8<--snippet under Client transports → Per-request headers