Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kong + Gzip doesn't work #1200

Closed
ErwannRobin opened this issue May 11, 2016 · 12 comments
Closed

Kong + Gzip doesn't work #1200

ErwannRobin opened this issue May 11, 2016 · 12 comments

Comments

@ErwannRobin
Copy link

Probably a newbie question here, but I am struggling with it for 2 days and can't find the answer...

So: I can't manage to make Kong accept the "Accept-Encoding: gzip" header.
Whenever I make a request with the "Accept-Encoding: gzip" header, I have a correct 200 OK status, but my answer is empty ...
And gzip on the openresty nginx server seems already activated as it already answer "Accept-Encoding: gzip" in the response header...

The problem is that this header is automatically set by browsers, so I can't demo my API if I setup a Kong proxy.
So how to make Kong accept (or ignore) this header ?

@ErwannRobin
Copy link
Author

Ok, I manage to make it work by deactivating the "response-transformer" plugin.
Any idea what is the link between those 2 things ?

@ahmadnassri ahmadnassri added the BC label May 13, 2016
@ErwannRobin
Copy link
Author

What does "BC" means ?

@ahmadnassri
Copy link
Contributor

@diwann just labels we use to track issues infernally...

we are actively looking at the gzipping questions for Kong.

@shashiranjan84
Copy link
Contributor

@thefosk @Tieske can this be closed or we waiting for 0.9.0 release?

@subnetmarco
Copy link
Member

subnetmarco commented Aug 25, 2016

This is caused when the plugin tries to access the body of the request/response, and it's unable to read it because it's gzipped.

@diwann what plugin configuration did you have for the Response Transformation plugin?

@ErwannRobin
Copy link
Author

I have the following settings:

curl 'https://kong.XXXX/plugins' -X PUT -H 'Content-Type: application/json' --data '{"api_id":"XXXXX-7edf-41dd-9115-16f0e324c882","name":"response-transformer","config":{"remove":{"json":"links"}}}'

However, I haven't checked yet if it's still the case with Konk 0.9

@ErwannRobin
Copy link
Author

Yes, I just checked, and it's still the case with 0.9.0 (and "next")

@thibaultcha thibaultcha removed the BC label Sep 1, 2016
@ErwannRobin
Copy link
Author

ErwannRobin commented Nov 2, 2016

ok, I finally found a solution: in order to access to the json structure, the response-transformer plugin need to access the body of the response from the backend.
But this body is compressed as soon as the client accept gzip encoding.
So the trick is to make Kong and the backend to communicate in plain text, and to handle the gzip compression on Nginx side.
For that, you need to hide the "Accept-Encoding" header when the query come in, which you can do in the nginx configuration file, under the "location /" section, with:

proxy_set_header Accept-Encoding ""; 

Then, you need to activate the gzip compression on nginx side, under the "server" section, with:

gzip on;
gzip_types text/plain application/json;

🎉

@Tieske
Copy link
Member

Tieske commented Nov 2, 2016

@diwann thx for reporting back with the solution you found!

@subnetmarco
Copy link
Member

This is great - @diwann if you submit a PR I will be happy to tweak and merge it.

@mloskot
Copy link

mloskot commented Feb 26, 2021

A variation to @diwann 's suggestion for the nginx side from #1200 (comment) is to use the request-transformer plugin on the Kong side and replace the Accept-Encoding header to force Accept-Encoding:identity. By the way, the outbound compression is still not available as per #409

@vivekt333
Copy link

ok, I finally found a solution: in order to access to the json structure, the response-transformer plugin need to access the body of the response from the backend. But this body is compressed as soon as the client accept gzip encoding. So the trick is to make Kong and the backend to communicate in plain text, and to handle the gzip compression on Nginx side. For that, you need to hide the "Accept-Encoding" header when the query come in, which you can do in the nginx configuration file, under the "location /" section, with:

proxy_set_header Accept-Encoding ""; 

Then, you need to activate the gzip compression on nginx side, under the "server" section, with:

gzip on;
gzip_types text/plain application/json;

🎉

I have the nginx-kong.conf file with 3 server blocks kong, kong_gui, kong_admin
i have to add proxy_set_header Accept-Encoding ""; in server_name kong location / block ?

when i restart the kong it overrides those directive, i see the kong.conf have a nginx inject block but i didn't find a way to inject in location / block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants