leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.08k stars 249 forks source link

gzip? #150

Open pygy opened 9 years ago

pygy commented 9 years ago

I want to gzip the output of Lapis. apparently, setting gzip on; in the nginx config file doesn't work as is.

I've had to "self-proxy" the request for gzip to kick in:

    location / {
        gzip on; 
        gzip_min_length 1; 
        proxy_http_version 1.1; 
        proxy_pass http://127.0.0.1:$server_port/lapis; 
    }

    location /lapis {
      set $_url "";
      default_type text/html;
      content_by_lua 'lapis.serve"main"';
    }

The trouble is that I have to prefix my routes, and url_for is now broken. using @include my_app, path: "/lapis", name:"" in an empty app would solve the first issue, but url_for would still be broken. I guess I could gsub the prefix on the fly, but I wanted to be sure there wasn't a cleaner solution.

leafo commented 9 years ago

Seems like the suggested approach is to compress the content within lua using lua-zlib: https://groups.google.com/forum/#!msg/openresty-en/yVNvA6uhjyA/9QlHzPs2zE8J

I'll mark this as a new feature as it's currently not trivial to manipulate the output buffer after it's been completed.