Endpoint Response breaks with "content-type: application/json"
See original GitHub issueDescribe the bug
Using the new api described in #3384, when I create an API endpoint returning a Response, it breaks in Cloudflare Workers if I set content-type: application/json
as a Response header.
I believe the reason is because it applies JSON.stringify to the body of the response. However the body of the response being a ReadableStream, it breaks returning an object { locked: false }
.
Reproduction
I believe the culprit is found here: https://github.com/sveltejs/kit/blob/ee906a3b2b103e4523eb1b6bb13f04d03eb35238/packages/kit/src/runtime/server/endpoint.js#L86
Normally the control is_pojo(body)
shouldn’t allow the code to reach here, however the control doesn’t work correctly in Cloudflare Workers. More specifically it fails here:
https://github.com/sveltejs/kit/blob/ee906a3b2b103e4523eb1b6bb13f04d03eb35238/packages/kit/src/runtime/server/endpoint.js#L119
In Cloudflare body[Symbol.toStringTag]
returns undefined
. Replacing the control with body instanceof ReadableStream
works in Cloudflare Workers.
Logs
No response
System Info
Binaries:
Node: 16.10.0 - ~/.volta/tools/image/node/16.10.0/bin/node
Yarn: 3.1.0 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
npm: 8.3.1 - ~/.volta/tools/image/npm/8.3.1/bin/npm
npmPackages:
@sveltejs/adapter-cloudflare: ^1.0.0-next.8 => 1.0.0-next.8
@sveltejs/kit: ^1.0.0-next.239 => 1.0.0-next.239
svelte: ^3.46.2 => 3.46.2
vite: ^2.7.12 => 2.7.12
Severity
serious, but I can work around it
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
okay. Thanks. I tried to run the test cases. all the test cases were passing
@vicky1999 Not sure how easy it is to reproduce this, since it happens on cloudflare specifically, but as long as the test pass with your changes. I think that’s good enough.