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

How to handle gziped capture? #12

Closed
robert-martens opened this issue Jan 17, 2011 · 4 comments
Closed

How to handle gziped capture? #12

robert-martens opened this issue Jan 17, 2011 · 4 comments

Comments

@robert-martens
Copy link

This may be more of a question than an issue. I want to feed the body of one capture into another ex:
local res2 = ngx.location.capture("/cap2?"..res1.body)
However res1.body was gziped by the origin server. Any idea how I can prevent the gzip of the body (a special Accept-Encoding header maybe) or unzip it using something like the gzio library on luaforge (http://luaforge.net/projects/gzio/)?

@chaoslawful
Copy link
Contributor

Remove Accept-Encoding header from the request can prevent server responsing with gzip compressed content. If this can't be done, you can also decompress gzip'd content in Lua by using birmworks' lua-zlib module or similar ones (https://github.com/brimworks/lua-zlib).

@agentzh
Copy link
Member

agentzh commented Jan 17, 2011

If you're using the ngx_proxy module for your subrequests, try using the following directive to prevent forwarding your original request's headers:

proxy_pass_request_headers off;

See http://wiki.nginx.org/NginxHttpProxyModule#proxy_pass_request_headers for more details.

Alternatively, you can explicitly remove the Accep-Encoding header in your subrequest location like this:

 more_clear_input_headers Accept-Encoding;

You need the ngx_headers_more module though. See http://wiki.nginx.org/NginxHttpHeadersMoreModule#more_clear_input_headers for more details :)

@robert-martens
Copy link
Author

Thank-you. All three options work.

OPTION ONE

Placed:
more_clear_input_headers Accept-Encoding;
in "location /cap2"

OPTION TWO

Placed:
proxy_pass_request_headers off;
in "location /cap2"

OPTION THREE

Downloaded https://github.com/brimworks/lua-zlib :
make linux
cp zlib.so /usr/lib/lua/5.1/zlib.so

added following to conf:
local zlib = require("zlib")
local stream = zlib.inflate()
local inflated_body = stream(res1.body)
local res2 = ngx.location.capture("/cap2?"..inflated_body)

I like having all three as options (may need gz some time and good to be able to modify the headers). I also like the work that both of you are doing; very cool.

@shann09
Copy link

shann09 commented Mar 30, 2020

zzlib may help

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

No branches or pull requests

4 participants