Code Monkey home page Code Monkey logo

luajit-brotli's People

Contributors

alonbg avatar andrepeng323 avatar sjnam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

alonbg echohes

luajit-brotli's Issues

how to check if brotli file exists

Hi there, I was wondering if it's possible to also check if the brotli file exists. e.g. this file ngx.req.set_uri(ngx.var.uri..".br")

I can't seem to find an easy way with lua in nginx to test this.

This would be useful as a way to enable a similar feature set to the static broli nginx brotli module provided by google, including only serving specific file types compressed as brotli, like js,css

It would also allow a graceful fallback if brotli files are not created during a build process.

best,
Aleck

compressStream does not work?

Example with compressStream does not work if data chunk is big enough and is splitted to several calls of 'body_fileter_by_lua_block'

My example is:

server {
                header_filter_by_lua_block {
                local brotlienc = require "brotli.encoder"
                local brotli_ok = false
                local header = ngx.var.http_accept_encoding
                if header then
                   if string.find(header, "br") then
                                brotli_ok = true
                   end
                end
                ngx.ctx.brotli_ok = brotli_ok
                ngx.header["Vary"] = "Accept-Encoding"
                if brotli_ok then
                   ngx.header.content_length = nil
                   ngx.header["Content-Encoding"] = "br"
                   ngx.ctx.encoder = brotlienc:new()
                end
                }
                body_filter_by_lua_block {
                        if not ngx.ctx.brotli_ok then return end
                        local encoder = ngx.ctx.encoder
                        ngx.arg[1] = encoder:compressStream(ngx.arg[1])
                        if encoder:isFinished() then
                           encoder:destroy()
                           ngx.arg[2] = true
                        end
                }

                listen 443 ssl;
                ssl_certificate /etc/openresty/certs/crt.crt;
                ssl_certificate_key /etc/openresty/certs/crt.key;

                location / {
                        root /var/www/html;
                }
        }

If file size is more than several kilobytes, openresty calls 'body_filter_by_lua' several times, but this example returns ngx.arg[2] = true after first call. So, the result is truncated.
Also, I have tried change the code end removed isFinished() checking, but it does not work at all, in this case client receives nothing.

How use compress and compressStream in right way? Where is difference?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.