I have a Nginx server with location and simple NJS scenario where I need to parse the response of surequest. The response from API has such a header:
"Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store", "Content-Encoding": "gzip", ...
When I am trying to read responseBody it looks like below:
\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0004\u0000��\u0007
\u001cI�%&/m�{J�J��t�\b�
\u0013$ؐ@\u0010������\u001diG#)�*��eVe]f\u0016@�흼��{���{���;�N'
The issue is reproducing only in NJS. It looks like an encoding issue. Is anybody knows how to fix it and parse such a response?
PS: I have tried to check JSON response from another API and got the same encoding issue. Nginx version is 1.19.1 and NJS is 0.4.2
The issue was in gzip encoding. Decoding the response helped me. I have added this directive to location and now it's working correct.
gunzip on;