Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying directives like charset in the response Content-Type breaks JSON response parsing in v0.0.5 #20

Open
jchen42703 opened this issue May 14, 2024 · 0 comments · May be fixed by #21

Comments

@jchen42703
Copy link

jchen42703 commented May 14, 2024

Description

If you have a response that sets directives in the Content-Type header, this breaks the response parsing in version v0.0.5. For example, if you specify charset ("application/json; charset=UTF-8"), then this leads to the response.json() call being skipped:

const JSON_CONTENT_TYPES = ['application/json', 'application/ld+json']
....
const contentType = response.headers.get('content-type');
    if (contentType && JSON_CONTENT_TYPES.includes(contentType)) {
        return await response.json();
    }
    else if (contentType && contentType.indexOf('text') === -1) {
        return await response.blob();
    }
    const text = await response.text();

This results in response bodies that are Blob instead of an object.

Solution

Instead of JSON_CONTENT_TYPES.includes, it should check if contentType contains any of the elements in JSON_CONTENT_TYPES

Similar, but not exact logic is in the regular fetcher.ts.

The temporary solution is to just not return Content-Type directives (but that's not necessarily the ideal solution).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant