Brotli compression support?

Hi there! We have been using Tyk for the last 2 years without any issue, but 2 weeks ago our body response templates started to fail with this kind of error
msg="Error unmarshalling JSON" api_id=2 error="invalid character '\u0083' looking for beginning of value" path="generic/aggregated_dashboard/24742/aggregated_shipping_quantity"
After some research, we realised that Cloudfare (used in our infrastructure) has enabled short ago the Brotli compression, and that seems to cause some problem. We have changed the configuration of our app to replace the Accept-Endoding header with one without br (brotli) support, and all is working fine now.
We are wondering if this is a known issue, or something anyone has noticed previously.

Thanks for raising @Juan_Bernabeu Just making sure I understand what might be happening here. Possibly 2 flows:

Client → CF → Gateway → Server
Client → Gateway → CF → Server

If client includes ‘br’ in the Accept-Encoding request header, but the Gateway doesn’t understand that encoding, then CF or Server is returning response zipped with brotli, which Gateway doesn’t understand.

Because the Gateway is doing a body transform, it is trying to decode the body to transform the body, but cant unzip it.

My initial thoughts is that the gateway should remove ‘br’ from the Accept-Encoding header to play nice with the content negotiation process. That way, the gateway would ensure that it receives a body in an encoding which it understands.

Hi Ahmet! The flow should more like:
Client → CF → Gateway → CF → Server

Even if the client doesn’t request br, I’m still getting a br encoded response from the server. The strange thing in this case is that the gateway sometimes understands the response and sometimes not. Not in a random way, if a given call fails, it alway fails.

And indeed, so far the solution has been to remove the Accept-Encoding coming from the client and replace with one in which the br is not included. This seems to work so far.

But just wondering if this is an expected behaviour from Tyk gateway

Hi @Juan_Bernabeu,

Yes, at the moment, the Gateway doesn’t support br encoding.
There’s an existing enhancement request/ticket for it (TT-8892), and I’ve updated it to include your concern.

Best regards

1 Like