19 releases

0.0.19 Mar 24, 2024
0.0.17 Sep 23, 2023
0.0.16 Mar 19, 2023
0.0.12 Nov 23, 2022
0.0.1 Nov 28, 2021

#4 in #reverse-proxy

Download history 51/week @ 2024-02-25 4/week @ 2024-03-03 19/week @ 2024-03-10 217/week @ 2024-03-17 270/week @ 2024-03-24 1827/week @ 2024-03-31 3/week @ 2024-04-07 210/week @ 2024-04-14

2,346 downloads per month

BSD-3-Clause

160KB
2.5K SLoC

crates.io tests docs.rs

Documentation

In your Cargo.toml:

[dependencies]
varnish = "0.0.16"

varnish-rs

Varnish bindings, notably to build vmods, such as:

  • vmod-reqwest: issue HTTP calls from VCL, use dynamic, HTTPS backends (support HTTP2)
  • vmod-rers: support for dynamic regex, including respone body manipulation
  • vmod-fileserver: serve files directly from disk, without the need for an HTTP backend

Don't hesitate to open github issues if something is unclear or impractical. You can also join us on discord.

Requirements

Rust

varnish-rs works on stable Rust and should be fine with more recent versions too. If it doesn't, please open an issue.

Varnish

varnish-rs relies on varnish-sys (in this same repository) to generate bindings from the libvarnish headers which you will need to install, depending on you linux distribution, the related package can be named varnish-devel, varnish-dev or maybe libvarnish-dev.

Right now, the only Varnish versions supported are 7.*.

Python3

At the moment, we use an embedded python script to generate the boilerplate that exposes the rust vmod code to Varnish. Make sure that python3 is in your path, or that the PYTHON environment variable is pointing at a compatible interpreter.

Building

git clone https://github.com/gquintard/varnish-rs.git
cd varnish-rs
cargo build

If your varnish headers are installed where pkg-config can find them, it's all there is to it. If not, you can set the VARNISH_INCLUDE_PATHS environment variable to a colon-separated list of paths to search:

VARNISH_INCLUDE_PATHS=/my/custom/libpath:/my/other/custom/libpath cargo build

Versions

The varnish-rs and varnish-sys versions will work in tandem: to build version X of varnish, you need version X of varnish-rs and of varnish-sys, in turn varnish-sys will depend on a specific Varnish C library version:

varnish-rs/varnish-sys (rust) libvarnish (C)
0.0.18 -> 0.0.19 7.5
0.0.17 7.4
0.0.15 -> 0.0.16 7.3
0.0.12 -> 0.0.14 7.2
0.0.9 -> 0.0.11 7.1
0.0.* 7.0

You can check which Varnish version is required using the libvarnish metadata field of varnish-sys:

cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "varnish-sys") | .metadata.libvarnishapi.version '

Dependencies

~0.5–2.8MB
~59K SLoC