4

I have 2 express servers, one working as backend resolving queries to DB and the other working as proxy to redirect requests.

Frontend request every data petition to proxy which, in turn sends a modified request via axios to backend in order to get data results.

The backend server compress response body in gzip format. However, axios by default decompress the response returned by backend and then sends the original size to frontend.

I want axios to keep the response compressed so the one in charge of decompress it is user's navigator.

Is there any option or way to do this?

EDIT: Axios request headers include:

Accept-Encoding: gzip, deflate, br

However, axios response headers are (without 'Content-Encoding: gzip'):

enter image description here

Ray
  • 113
  • 1
  • 15

1 Answers1

5

This is an old question but still the first Google result for "axios keep gzip" or similar.

Axios now supports decompress option in its RequestOptions. Set it to false and it will NOT decompress your response and WILL keep the original Content-Encoding header.

jiri-vyc
  • 86
  • 1
  • 6
  • You meant "on FE" right? Yes, it works only in Node, but this is what OP needed: "I have 2 express servers, one working as backend resolving queries to DB and the other working as proxy to redirect requests." – jiri-vyc Apr 08 '21 at 13:33
  • No, I meant Node, but I deleted my comment because it was incorrect. 'decompress' *does* work in Node, however decompress was just introduced in Axios July last year, and my project was pinned on an earlier version from last year, so it did not work when I tried it. And yes, my comment was not directed to the OP, just elaborating further on your helpful Answer that got my upvote. :) – Chris Beiter Apr 08 '21 at 13:59
  • Oh sorry, just for completeness, it was introduced in 0.20.0 in a full release in Aug 2020 actually to save y'all from looking it up. https://github.com/axios/axios/blob/master/CHANGELOG.md – Chris Beiter Apr 08 '21 at 14:08