wasm-plugins only.Expand description
WebAssembly middleware (18.10.0, #40, feature wasm-plugins): a
WasmLayer runs a core WebAssembly module on each request and,
optionally, each response. The module may let the request pass, change
its headers or target, answer it itself, or change the response’s status
and headers.
Isolation. Plugins get no imports at all — no WASI, no clock, no
files, no network: a module that imports anything is refused at load.
They see only what the host hands them. CPU per call is bounded by fuel,
memory by a limit on the instance’s linear memory. A trap, running out
of fuel or memory, or output the host can’t read answers 500 and
counts in rws_wasm_plugin_errors_total; it never takes the server down.
Each request gets a fresh instance, so nothing leaks from one request to
the next.
ABI (version 1). The module exports:
| Export | Signature | |
|---|---|---|
memory | memory | required |
rws_alloc | (len: i32) -> i32 | required: a buffer of len bytes the host writes input into |
rws_on_request | (ptr: i32, len: i32) -> i64 | required |
rws_on_response | (ptr: i32, len: i32) -> i64 | optional |
rws_init | (ptr: i32, len: i32) | optional: called once per instance with the config string |
A hook returns 0 to change nothing, or (ptr << 32) | len of its
output in its memory. The request a hook gets:
GET /path?query HTTP/1.1
203.0.113.7 ← the client address
host: example.com ← every header, "name: value"
user-agent: curl/8.11.1
← blank line; the body isn't passedThe response: its status code on the first line, then its headers and a blank line. Output is one directive per line:
| Directive | In | Does |
|---|---|---|
set <name>: <value> | both | replace the header |
add <name>: <value> | both | add a header |
remove <name> | both | remove the header |
uri <target> | request | change the request target (origin form, /…) |
status <code> | response | change the status |
respond <code> | request | answer now: header lines (name: value) follow, then a blank line and the body |
Anything else is an error (fail closed). Header names and values with CR, LF or NUL are refused.
Structs§
- Response
Action - A response hook’s decision.
- Wasm
Layer - WebAssembly middleware. See the module docs.
Enums§
- Edit
- Plugin
Error - What went wrong in a plugin call (the metric’s
kindlabel). - Request
Action - A request hook’s decision.
Constants§
- DEFAULT_
FUEL - Fuel per call when not configured: roughly tens of milliseconds of CPU.
- DEFAULT_
MEMORY_ MB - Linear memory limit when not configured, in MiB.
- MAX_
OUTPUT - The most output a hook may return.
Functions§
- parse_
request_ output - A request hook’s output, decoded. Public for the fuzz target.
- parse_
response_ output - A response hook’s output, decoded. Public for the fuzz target.