Skip to content

Commit 31ac2cc

Browse files
committed
fix(fetch): match Content-Type header case-insensitively
1 parent 6b0021e commit 31ac2cc

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎playwright/_impl/_fetch.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ def is_json_content_type(headers: network.HeadersArray = None) -> bool:
620620
if not headers:
621621
return False
622622
for header in headers:
623-
if header["name"] == "Content-Type":
623+
if header["name"].lower() == "content-type":
624624
return header["value"].startswith("application/json")
625625
return False
626626

‎tests/async/test_fetch_global.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ async def test_should_not_double_stringify_body_when_content_type_is_application
377377
await request.dispose()
378378

379379

380+
async def test_should_json_stringify_string_body_when_content_type_is_application_json(
381+
playwright: Playwright, server: Server
382+
) -> None:
383+
request = await playwright.request.new_context()
384+
[req, _] = await asyncio.gather(
385+
server.wait_for_request("/empty.html"),
386+
request.post(
387+
server.EMPTY_PAGE,
388+
headers={"content-type": "application/json"},
389+
data="foo",
390+
),
391+
)
392+
assert req.post_body == b'"foo"'
393+
await request.dispose()
394+
395+
380396
async def test_should_accept_already_serialized_data_as_bytes_when_content_type_is_application_json(
381397
playwright: Playwright, server: Server
382398
) -> None:

0 commit comments

Comments
 (0)