fix(http): parse every +json media type as JSON (GitHub #36)
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 30s
CI / runtimes (edge) (pull_request) Successful in 21s
CI / runtimes (deno) (pull_request) Successful in 33s

Exact matching left `application/json-patch+json` arriving as text,
where the old substring check had parsed it, and still left the other
`+json` types (`application/problem+json`, `application/vnd.api+json`)
as text, as they always were. `+json` is the structured-syntax suffix
for JSON (RFC 6839), so any media type ending in it is parsed as JSON.
`application/jsonx` and parameters that only mention JSON still are not.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-24 16:04:45 -05:00
1 parent 1dfebaa07a
commit aef9640b50
3 files changed
+9 -4

No files matched your search

+3
View File
@@ -394,6 +394,9 @@ describe('request hardening', () => {
expect(await post('Text/Plain; x=application/json', '{"a":1}')).toEqual({ got: '{"a":1}' });
expect(await post('Application/JSON; charset=utf-8', '{"a":1}')).toEqual({ got: { a: 1 } });
expect(await post('application/vnd.api+json', '{"a":1}')).toEqual({ got: { a: 1 } });
expect(await post('application/json-patch+json', '[]')).toEqual({ got: [] });
expect(await post('application/jsonx', '{"a":1}')).toEqual({ got: '{"a":1}' });
expect(await post('APPLICATION/X-WWW-FORM-URLENCODED', 'a=1')).toEqual({ got: { a: '1' } });
expect(await post('text/plain; x=application/x-www-form-urlencoded', 'a=1')).toEqual({ got: 'a=1' });
server.close();