Skip to content

fix(apiRequestContext): detect JSON content type with parameters - #43391

Closed
Pushpak Siva Sai (Pushpak731) wants to merge 1 commit into
microsoft:mainfrom
Pushpak731:fix-43388-json-content-type-parameters
Closed

Pushpak Siva Sai (Pushpak731) wants to merge 1 commit into
microsoft:mainfrom
Pushpak731:fix-43388-json-content-type-parameters

Conversation

@Pushpak731

Copy link
Copy Markdown

APIRequestContext decided whether to JSON-serialize string data by comparing the Content-Type header against application/json exactly (isJsonContentType in packages/playwright-core/src/client/fetch.ts). A content type with parameters — the very common application/json; charset=utf-8 — did not match, so the string was sent raw instead of JSON-serialized.

The comparison now uses the media type only, ignoring parameters and case, per RFC 9110 (media types are case-insensitive; parameters do not change the essential type).

Tests in tests/library/global-fetch.spec.ts:

  • string body with application/json; charset=utf-8 is JSON-serialized (hello → "hello"),
  • an already-serialized string with that content type is not double-stringified,
  • string body with Application/JSON; charset=utf-8 (uppercase media type) is JSON-serialized.

Verified locally (--project=chromium-*): the full global-fetch.spec.ts file passes (80 tests) with the change; reverting the one-line comparison fails the new parameter and uppercase tests, confirming they exercise the reported path.

Fixes #43388

isJsonContentType compared the Content-Type value against
'application/json' exactly, so 'application/json; charset=utf-8'
took the raw-string path instead of JSON-serializing string data.
Compare the media type only, ignoring parameters and case per
RFC 9110.

Fixes microsoft#43388
Copilot AI balanced review requested due to automatic review settings October 14, 2026 19:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: APIRequestContext ignores charset parameter when detecting JSON content type

2 participants