Skip to main content

Module request_validation

Module request_validation 

Source
Expand description

The request-validation node — validates request headers and/or body against JSON Schemas before the request reaches the upstream, rejecting non-conforming requests with a configurable status code.

Port of APISIX’s request-validation plugin. Schemas are compiled once at config load (invalid schemas fail policy compilation, not requests). Bodies are validated as JSON by default; application/x-www-form-urlencoded bodies are decoded into a flat object first, mirroring the Lua plugin’s ngx.decode_args shape (duplicate keys become arrays, keys without = become true).

Structs§

RequestValidationPlugin
Validates context.request headers and body against compiled JSON Schemas. On failure the request is rejected through the error port with error code VALIDATION_FAILED and a JSON response using rejected_code.

Functions§

compile_schema 🔒
Compiles an optional schema key into a validator, failing fast with the key name on malformed schemas.
decode_urlencoded 🔒
Decodes an application/x-www-form-urlencoded body into a flat JSON object, mirroring ngx.decode_args: a=1&a=2 becomes {"a": ["1","2"]}, a bare flag (no =) becomes {"flag": true}, values are percent-decoded and + maps to space.
hex_val 🔒
urldecode 🔒
Percent-decodes a urlencoded component (+ becomes space; malformed escapes pass through literally).