fix(state): only emit Content-Type charset for media types that define it#8226
Open
soyuka wants to merge 1 commit into
Open
fix(state): only emit Content-Type charset for media types that define it#8226soyuka wants to merge 1 commit into
soyuka wants to merge 1 commit into
Conversation
…e it JSON-based media types (RFC 8259, RFC 6839 `+json` suffix) do not define a `charset` parameter, and including one can break strict clients. Restrict `; charset=utf-8` to `text/*`, `application/xml` and `application/xml-external-parsed-entity`, matching their IANA registrations. Updates functional tests asserting on Content-Type accordingly. Refs api-platform#8218
44ebbee to
32e2b1c
Compare
1 task
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
Per #8218 review feedback, API Platform was unconditionally appending
; charset=utf-8to every responseContent-Type. JSON-based media types (application/jsonand the RFC 6839+jsonstructured syntax suffix family:ld+json,hal+json,vnd.api+json,problem+json,merge-patch+json,vnd.openapi+json…) do not define acharsetparameter in their IANA registrations, and including one can be rejected by strict clients.RFC references
charsetparameter is defined for this registration."+json/+yamlstructured syntax suffixes inherit the base type's parameter rules; neither definescharset.text/*types definecharset.application/xmlandapplication/xml-external-parsed-entitydefinecharset.Change
New
formatContentType()helper inHttpResponseHeadersTraitthat appends; charset=utf-8only fortext/*,application/xml, andapplication/xml-external-parsed-entity. Everything else (JSON family, YAML, binary, etc.) returns the bare media type.Functional tests asserting on
Content-Typefor JSON / YAML responses were updated accordingly.Test plan
tests/Functional/full suite green (1562 tests, 16351 assertions)tests/Symfony/Bundle/Test/ClientTest.phpgreenRefs #8218