sjnam / luajit-brotli Goto Github PK
View Code? Open in Web Editor NEWGoogle brotli ffi binding
Google brotli ffi binding
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.