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

πŸ› Bug Report β€” URLSearchParams body sets incorrect fetch content-type #3066

Open
nickbabcock opened this issue Nov 6, 2024 · 1 comment Β· May be fixed by #3151
Open

πŸ› Bug Report β€” URLSearchParams body sets incorrect fetch content-type #3066

nickbabcock opened this issue Nov 6, 2024 · 1 comment Β· May be fixed by #3151
Labels
bug Something isn't working

Comments

@nickbabcock
Copy link

nickbabcock commented Nov 6, 2024

export default {
    async fetch(request, env, ctx) {
        const r = new Request('https://example.com/', {
            method: 'POST',
            body: new URLSearchParams({ hello: 'world' })
        });
        return new Response(r.headers.get('content-type'))
    },
};

Expected (ref):

application/x-www-form-urlencoded;charset=UTF-8

Actual:

text/plain;charset=UTF-8

This behavior differs from browsers and node.js

Replicated in cloudflare workers playground and in a production workers deployment.

@jasnell jasnell added the bug Something isn't working label Nov 6, 2024
@balusch
Copy link
Contributor

balusch commented Nov 21, 2024

It seems that api::url::URLSearchParams instead of api::URLSearchParams should be used in Body::Initializer:

jsg::Ref<Blob>, jsg::Ref<URLSearchParams>, jsg::Ref<FormData>>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants