I’m using fetch() in an edge function, and I don’t understand why the response doesn’t have a Content-Encoding header even though visiting the request URL directly from a browser shows that it’s compressed using Brotli (and the Content-Encoding header is present).
const upstreamResponse = await fetch('https://example.com', {
headers: {
'Accept-Encoding': 'gzip, br',
},
});
// Always null
console.log(upstreamResponse.headers.get('Content-Encoding'))
// Pass the response as-is to avoid automatic decompression,
// but the response body is always uncompressed
return new Response(upstreamResponse.body, {
status: upstreamResponse.status,
headers: {
...Object.fromEntries(upstreamResponse.headers), // Preserve headers
},
});
I can recompress it before sending it along, but that seems like a waste of computing resources. Anyone know how I can prevent the response from getting automatically uncompressed?
(I’m testing locally via Netlify CLI.)