From 31ac2ccf7393cd703bf2565429f92c17bd47504f Mon Sep 17 00:00:00 2001 From: kwy404 Date: Thu, 24 Sep 2026 03:51:11 -0300 Subject: [PATCH] fix(fetch): match Content-Type header case-insensitively --- playwright/_impl/_fetch.py | 2 +- tests/async/test_fetch_global.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/playwright/_impl/_fetch.py b/playwright/_impl/_fetch.py index 6181f22b2..767d4cdef 100644 --- a/playwright/_impl/_fetch.py +++ b/playwright/_impl/_fetch.py @@ -620,7 +620,7 @@ def is_json_content_type(headers: network.HeadersArray = None) -> bool: if not headers: return False for header in headers: - if header["name"] == "Content-Type": + if header["name"].lower() == "content-type": return header["value"].startswith("application/json") return False diff --git a/tests/async/test_fetch_global.py b/tests/async/test_fetch_global.py index 10f82583c..3bb428b38 100644 --- a/tests/async/test_fetch_global.py +++ b/tests/async/test_fetch_global.py @@ -377,6 +377,22 @@ async def test_should_not_double_stringify_body_when_content_type_is_application await request.dispose() +async def test_should_json_stringify_string_body_when_content_type_is_application_json( + playwright: Playwright, server: Server +) -> None: + request = await playwright.request.new_context() + [req, _] = await asyncio.gather( + server.wait_for_request("/empty.html"), + request.post( + server.EMPTY_PAGE, + headers={"content-type": "application/json"}, + data="foo", + ), + ) + assert req.post_body == b'"foo"' + await request.dispose() + + async def test_should_accept_already_serialized_data_as_bytes_when_content_type_is_application_json( playwright: Playwright, server: Server ) -> None: