A redirection.io redirect engine, run as a Sōzune plugin compiled to WebAssembly — matching rules locally, with no agent.
The plugin embeds redirection.io's own redirectionio
engine (the same crate their agent and integrations use) and matches each request
inside the wasm guest. Rules are carried in the plugin config; a small
companion process refreshes them periodically from redirection.io. There is no
per-request network call and no agent container — nothing has to be running at
request time, and if the refresh source is briefly down the plugin keeps matching
with its last known rules.
redirection.io's usual model runs an agent (a sidecar) that every request queries. This plugin removes it: rules are pulled out-of-band and matched locally. Trade-offs: latency-free and resilient (no agent to keep up), but rules are only as fresh as the last sync, and advanced rule types beyond redirects need the translator extended (see Limitations).
[sync binary, beside Sōzune] [plugin, inside Sōzune]
GET /rules (API token, periodic) reads ruleset from config
→ translate editor → engine rules ─────▶ builds a Router once
→ write rules.json (atomic) per request: match locally
keeps previous file on failure → redirect (301 + Location)
→ or continue to backend
The per-request path touches only the in-memory Router. No agent, no network.
# the wasm guest
cargo build --release --target wasm32-unknown-unknown
# -> target/wasm32-unknown-unknown/release/sozune_redirectionio.wasm
# the sync binary (host-side)
cargo build --release --bin syncThe guest embeds libredirectionio, which is wired for a wasm-bindgen (JS) host.
Sōzune's host is wasmtime (no JS), so three crates are vendored under patches/
with their JS deps removed (see the top of Cargo.toml). The resulting .wasm
imports nothing but the http-wasm host functions — CI asserts this.
Runs beside Sōzune (a small daemon, or a cron one-shot). It pulls the project's rules, translates them to the engine format, and writes the ruleset file the plugin reads.
RIO_API_TOKEN=<api-token> \
RIO_PROJECT_ID=<project-uuid> \
RIO_OUT=/plugins/redirectionio-rules.json \
RIO_INTERVAL=300 \
sync| Env | Description |
|---|---|
RIO_API_TOKEN |
redirection.io API token (Settings > API tokens). Not the agent token. Required. |
RIO_PROJECT_ID |
Project UUID (from the /organization endpoint). Required. |
RIO_OUT |
Path to write the ruleset config. Default rules.json. |
RIO_INTERVAL |
Seconds between syncs. Default 300. 0 = run once and exit (for cron). |
RIO_API_BASE |
API base URL. Default https://api.redirection.io. |
On a failed fetch or translate, the previous ruleset file is left untouched.
The plugin reads its ruleset from config.rules (the shape the sync binary
writes). Point both at the same place, or have the sync binary write into the
plugin config.
# config.yaml
plugins:
redirectionio:
path: /plugins/sozune_redirectionio.wasm
# Keep guest instances between requests so the compiled rules are reused
# instead of rebuilt per request (see "Host requirements").
reuse_instances: 8
config:
rules:
# engine-format rules, as produced by the sync binary:
- { id: "r1", source: { path: "/old" }, rank: 0, target: "/new", status_code: 301 }labels:
- "sozune.enable=true"
- "sozune.http.app.host=app.example.com"
- "sozune.http.app.plugins=redirectionio"Each rules entry is an engine-format redirectionio::api::Rule. You normally
never hand-write these — the sync binary produces them from your project.
Besides the standard http-wasm functions, the plugin imports two non-standard
host extensions from http_handler: get_time_unix_nanos (request timestamp,
for date/time/weekday rule conditions) and get_random (entropy, for rule
sampling). A wasm32-unknown-unknown guest has neither a clock nor an entropy
source, and each request runs in a fresh instance. The host must provide both,
otherwise the plugin fails to instantiate.
The guest caches the Router it builds from its config (keyed by the config, so
routes with different rules stay separate). The cache only pays off when the
host reuses guest instances across requests (Sōzune's reuse_instances
plugin option, http-wasm-host's Plugin::with_instance_reuse); with a fresh
instance per request the config is
re-parsed and the Router rebuilt every time, a cost that grows with the number
of rules (roughly 10 ms per 1000 rules).
- Redirect — a matching rule with a status code sets that status +
Locationand short-circuits; the backend is never reached. - No match / empty ruleset / no config — the request continues untouched.
- Redirect scope. The translator (
GET /ruleseditor format → engine format) covers redirects, optionally gated by methods (or excluded methods), sampling, anddate/datetime/ weekday conditions. A rule using anything else — request headers, IP address, response status codes, time-of-day, markers, variables, or an action other thanredirection— is skipped and logged by the sync binary, never translated without its condition (which would widen it). Extendsrc/translate.rsas you need more; the engine supports them, the translator just has to map them. - Dates are UTC. Editor dates carry no timezone and are read as UTC.
- Staleness. Rules are as fresh as the last successful sync (tune
RIO_INTERVAL). This is the cost of not running an agent. - API token. The sync binary needs an API token, distinct from the agent token. Create one under Settings > API tokens.
- Scheme is assumed https. http-wasm does not expose the scheme; traffic reaching Sōzune over TLS is reported as https for rule evaluation.
patches/{redirectionio,chrono,getrandom} are vendored copies with their wasm32
JS deps removed so the engine loads under wasmtime. They are pinned via
[patch.crates-io]. On a redirectionio version bump these must be
re-applied; the clean long-term fix is an upstream no-js feature.
MIT.