fix(server): match Content-Type case-insensitively in StreamableHTTP#2916
Open
ly-wang19 wants to merge 1 commit into
Open
Conversation
Media types are case-insensitive (RFC 9110, section 8.3.1), and StreamableHTTPServerTransport._check_accept_headers already lowercases the Accept media types before comparing. _check_content_type did not, so a spec-valid request with a mixed/upper-case Content-Type (e.g. "Application/JSON") was rejected with 415 Unsupported Media Type. Lowercase the parsed Content-Type media type before comparing to CONTENT_TYPE_JSON, consistent with _check_accept_headers. Adds a unit test for case-insensitive matching (the _check_content_type path was previously no-cover).
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
StreamableHTTPServerTransport._check_content_typecompared the request'sContent-Typemedia type case-sensitively, so a spec-valid request with a mixed/upper-case type (e.g.Content-Type: Application/JSON) was rejected with415 Unsupported Media Type.Media types are case-insensitive (RFC 9110, §8.3.1), and the sibling
_check_accept_headersalready lowercases Accept media types before comparing —_check_content_typejust didn't.Fix
Lowercase the parsed
Content-Typemedia type before comparing toCONTENT_TYPE_JSON, consistent with_check_accept_headers.Test
Added
test_check_content_type_is_case_insensitive(the_check_content_typerejection path was previously marked# pragma: no cover). It assertsapplication/json,Application/JSON,APPLICATION/JSON, and; charset=utf-8variants are accepted, andtext/plainis still rejected.Verified red→green: the new test fails on
main(mixed-case rejected) and passes with the fix.uv run pytest tests/shared/test_streamable_http.py→ 70 passed;ruff check/ruff format --checkclean on both files.