You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems there is inconsistency between CF and Miniflare. PoC code:
addEventListener('fetch',function(event){event.respondWith(handleRequest(event.request))})asyncfunctionhandleRequest(request){leturl=newURL(request.url)constres=awaitfetch(`http://origin.cloudtest.it${url.pathname}`,{headers: {"if-modified-since": "Wed, 12 Jan 2022 10:43:29 GMT"}})returnnewResponse(res.body,{headers: {
...Object.fromEntries(res.headers),"x-workers-hello": "Hello from Cloudflare Workers"},status: res.status,statusText: res.statusText})}
Throws the following error:
GET /bigfiles/256m 500 Internal Server Error (98.22ms)
[mf:err] GET /bigfiles/256m: TypeError: Response with null body status cannot have body
at new Response (/Users/lukes/labs/cf-workers/sandbox-lukasz-testing/node_modules/undici/lib/fetch/response.js:160:15)
at new Response (/Users/lukes/labs/cf-workers/sandbox-lukasz-testing/node_modules/@miniflare/core/src/standards/http.ts:556:13)
at handleRequest (/Users/lukes/labs/cf-workers/sandbox-lukasz-testing/index.js:22:10)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at EventTarget.[kDispatchFetch] (/Users/lukes/labs/cf-workers/sandbox-lukasz-testing/node_modules/@miniflare/core/src/standards/event.ts:359:13)
at Server.<anonymous> (/Users/lukes/labs/cf-workers/sandbox-lukasz-testing/node_modules/@miniflare/http-server/src/index.ts:167:20)
The origin server returns 304 response with no body (as expected). The reason of the error is that res.body is a ReadableStream which is empty but the object itself is not, therefore the undici library doesn't like it and throws an error (304 responses don't have response body).
I was sitting on the fence if this should be reported here or maybe to the dependency's maintainer. In fact, the object type could be detected to behave properly. WDYT?
The text was updated successfully, but these errors were encountered:
Hey! 👋 Thanks for raising this. This is the right place to report the issue. Executing this code in Chrome/Firefox/undici gives me a ReadableStreambody, whereas Cloudflare gives null:
diff --git a/packages/core/src/standards/http.ts b/packages/core/src/standards/http.ts
index bd59d92..aef6da8 100644
--- a/packages/core/src/standards/http.ts+++ b/packages/core/src/standards/http.ts@@ -551,7 +551,7 @@ export class Response<
// This zero-length body behavior is allowed because it was previously
// the only way to construct a Response with a null body status. It may
// change in the future.
- if (nullBodyStatus.includes(init.status) && body === "") body = null;+ if (nullBodyStatus.includes(init.status)) body = null;
}
super(new BaseResponse(body, init));
}
It seems there is inconsistency between CF and Miniflare. PoC code:
Throws the following error:
The origin server returns 304 response with no body (as expected). The reason of the error is that
res.body
is a ReadableStream which is empty but the object itself is not, therefore theundici
library doesn't like it and throws an error (304 responses don't have response body).I was sitting on the fence if this should be reported here or maybe to the dependency's maintainer. In fact, the object type could be detected to behave properly. WDYT?
The text was updated successfully, but these errors were encountered: