Workers not decoding gzip request automatically

Getting the .text() of
Z�&�;��2����9s#Ò/y�H�H�����Cp_΃;05��J#c�E�G9�M*�a�zJ%,�[t���)<�>��Ņ��^����GXLgGC㩡�X��a��-ˍz[/aqR���R�<
�:m��1]��c�>�(�z%��bZ���S�
����
�Oǵ�v�ϰL�ϵq����n���������y=
Z�&�;��2����9s#Ò/y�H�H�����Cp_΃;05��J#c�E�G9�M*�a�zJ%,�[t���)<�>��Ņ��^����GXLgGC㩡�X��a��-ˍz[/aqR���R�<
�:m��1]��c�>�(�z%��bZ���S�
����
�Oǵ�v�ϰL�ϵq����n���������y=
from a logpush job pointing to a worker
3 Replies
DanTheGoodman
DanTheGoodman2y ago
working looking like this:
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
console.log(await request.text())
return new Response("Hello World!");
},
};
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
console.log(await request.text())
return new Response("Hello World!");
},
};
echo '{"mydummy": "json"}' | gzip | curl -v -i --data-binary @- -H "Content-Encoding: gzip" -H "content-type: application/json" http://localhost:8787
!��c�VʭL)�ͭT�RP�*��S���b
1:53:22 PM POST /json 200
!��c�VʭL)�ͭT�RP�*��S���b
1:53:22 PM POST /json 200
kian
kian2y ago
Workers don't handle gzip automatically - you will need to leverage stuff like DecompressionStream https://discord.com/channels/595317990191398933/1041788765783474216/1045010540809945148
DanTheGoodman
DanTheGoodman2y ago
Thanks @kiannh Will look at this
const ds = new DecompressionStream("gzip");
const tds = new TextDecoderStream();

const chunks = await c.req.body!.pipeThrough(ds).pipeThrough(tds);

let data = "";
for await (let chunk of chunks) {
data = data + chunk;
}
console.log("got text:", data)
const ds = new DecompressionStream("gzip");
const tds = new TextDecoderStream();

const chunks = await c.req.body!.pipeThrough(ds).pipeThrough(tds);

let data = "";
for await (let chunk of chunks) {
data = data + chunk;
}
console.log("got text:", data)
this is what worked
Want results from more Discord servers?
Add your server