# haproxy-brotli
A Rust-based brotli module for [HAProxy] 3.2+ Community Edition using the [Lua Filter API].
It implemented as a native Lua module written in Rust using [mlua] and [haproxy-api] crates.
[HAProxy]: https://www.haproxy.org
[Lua Filter API]: https://www.arpalert.org/src/haproxy-lua-api/3.2/index.html
[mlua]: https://github.com/mlua-rs/mlua
[haproxy-api]: https://github.com/khvzak/haproxy-api-rs
## Usage and Configuration
Please check the [module](module) and [tests](tests) directories for working examples.
### HAProxy Configuration
```
global
master-worker
lua-load-per-thread brotli.lua
...
listen http-in
bind *:8080
filter lua.brotli offload type:text/,application/json
```
Create a file named `brotli.lua` with the following content:
```lua
local brotli = require("haproxy_brotli_module")
brotli.register()
```
Only `GET`/`POST` requests with the `Accept-Encoding: br` header will be compressed.
### Configuration Options
The `filter lua.brotli` directive supports the following options:
- `offload`: Remove the `Accept-Encoding` header to prevent backend servers from compressing responses.
- `type:` A comma-separated list of MIME type prefixes to compress. Default is empty (all types).
- `quality:N` Compression quality level (0-11). Default is 5.
- `window:N` The sliding window size (in bits) to use for compression (10-24). Default is 22.
## License
This project is licensed under the [MIT license](LICENSE)