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
According to https://stackoverflow.com/a/64849685 and encodeBody documentation, the only way to return already-gzipped data from worker (without decompressing and compressing again) with Content-Encoding: gzip set (for the browser to decompress it automatically) is to set the encodeBody Response init option to "manual":
// Make a new response with the same body but using manual encoding.resp=newResponse(resp.body,{status: resp.status,headers: resp.headers,encodeBody: "manual"});// Modify headers and return.resp.headers.set("Content-Encoding","gzip");returnresp;
If encodeBody: "manual" is missing, Worker runtime will silently compress the body again, returning gzip-in-gzip data to the browser.
I have failed to find any reasonable way to set this option in worker-rs, because it can only be passed through ResponseInit object, and the current worker code:
has no support for passing anything apart from status, headers and websocket through ResponseInit;
has no support for using custom ResponseInit instances;
constructs the ResponseInit object too late (after the fetch handler has completed processing), so the handler cannot customize it further.
Also, the encodeBody documentation is a bit confusing: it makes it seem like encodeBody is a property on Response, but according to my reading of workerd code, it can be only passed during Response construction through init (ResponseInit.encodeBody property, essentially), and is not exposed on the Response object in any way.
Steps To Reproduce
No response
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
What version of
workers-rs
are you using?0.2.0
What version of
wrangler
are you using?3.53.0
Describe the bug
According to https://stackoverflow.com/a/64849685 and encodeBody documentation, the only way to return already-gzipped data from worker (without decompressing and compressing again) with
Content-Encoding: gzip
set (for the browser to decompress it automatically) is to set theencodeBody
Response init option to"manual"
:If
encodeBody: "manual"
is missing, Worker runtime will silently compress the body again, returning gzip-in-gzip data to the browser.I have failed to find any reasonable way to set this option in
worker-rs
, because it can only be passed throughResponseInit
object, and the current worker code:status
,headers
andwebsocket
throughResponseInit
;ResponseInit
instances;ResponseInit
object too late (after thefetch
handler has completed processing), so the handler cannot customize it further.Also, the encodeBody documentation is a bit confusing: it makes it seem like
encodeBody
is a property onResponse
, but according to my reading of workerd code, it can be only passed duringResponse
construction throughinit
(ResponseInit.encodeBody
property, essentially), and is not exposed on theResponse
object in any way.Steps To Reproduce
No response
The text was updated successfully, but these errors were encountered: