Skip to content

Response (and Request) with array body should auto-serialize to JSON #583

@tripodsan

Description

@tripodsan

Description

When creating a Response or Request with a plain JS object body, it is automatically serialized to JSON and the Content-Type header is set to application/json. However, this does not work for arrays, which are also valid JSON values.

Expected behavior

const res = new Response([1, 2, 3]);
// Content-Type: application/json
// body: [1,2,3]

Actual behavior

Arrays fall through to guessContentType, which does not recognize them as JSON, so no Content-Type is set and the body is not serialized.

Fix

The isPlainObject check in response.js (and request.js) should be extended to also handle arrays (Array.isArray(body)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions