Remix cannot decode endpoint data using gzip

Viewed 27

I am working on a remix project and have gotten into an issue where a loader requesting data from a foreign endpoint encoded with gzip do not seem to be decoded.

The remix loader is fairly simple, with some simplification it looks like this:

export const loader = async () => {
  try {
    const [
      encodedData,
      [... <other responses>]
    ] = await Promise.all([
      gzippedEndpoint(),
      [... <other requests>]
    ]).catch((e) => {
      console.error(e);
    });
    return json([<loader data>]);
  } catch (error) {
    console.log("ERROR:", error);
    return json({});
  }
};

It's the gzippedEndpoint() that fails, where the error stack claims that the returned data is not valid json. I figured compression should not be a problem, but it seems like the fetch requests on the remix server side cannot correctly decode the gzipped data. I also see no option to enable decoding explicitly on remix. When I disable gzip on the foreign endpoint everything works fine for the remix server making the request and parsing the response.

Here is an example of the headers from a returned response (with some obfuscation):

200 GET https://dev.server.com/public/v1/endpoint {
  'cache-control': 'no-store, must-revalidate, no-cache',
  connection: 'close',
  'content-encoding': 'gzip',
  'content-type': 'application/json',
  date: 'Mon, 12 Sep 2022 06:51:41 GMT',
  expires: 'Mon, 12 Sep 2022 06:51:41 GMT',
  pragma: 'no-cache',
  'referrer-policy': 'no-referrer',
  'strict-transport-security': 'max-age=31536000 ; includeSubDomains',
  'transfer-encoding': 'chunked',
}

Is there some remix option or request header that I am missing here?

0 Answers
Related