Expand description
The custom function seams: the reference pipeline’s ninth and seventeenth checks.
This is the Rust family’s port of the two checks the reference pipeline runs host-supplied functions through:
guard_core/core/checks/implementations/custom_validators.py: a route’scustom_validatorslist, run in order, first truthy response wins.guard_core/core/checks/implementations/custom_request.py: the globalcustom_request_checkfunction.
The reference seams are async callables over the request; the Rust
family’s are sync boxed functions over a CustomRequestContext (the
request facts the reference’s checks can see). Both checks share the
same shapes:
custom_validators (route-scoped, in order, first truthy wins):
validator returns None: continue
validator returns a response: Failed (block with the validator's
own response, the reference returns
it as-is, never create_error_response)
validator returns a truthy
non-response: Failed with no block (the reference
logs and emits but does not block)
custom_request (global):
check returns None: Allowed
check returns a response: Blocked with it (the reference
applies the response modifier;
passive mode logs only)Names are explicit on the seam (the reference reads __name__,
falling back to "anonymous" for unnamed callables): a Rust closure
carries no name, so hosts name them at registration.
§Example
use std::sync::Arc;
use guard_core_engine::custom_checks::{
decide_custom_request, CustomRequestContext, CustomRequestFn, CustomRequestVerdict,
CustomResponse,
};
let check: CustomRequestFn = Arc::new(|_ctx: &CustomRequestContext<'_>| {
Some(CustomResponse { status: Some(418), body: None })
});
let ctx = CustomRequestContext { method: "GET", path: "/", client_ip: None, body: None };
let verdict = decide_custom_request(&check, "block_maintenance", &ctx);
assert_eq!(
verdict,
CustomRequestVerdict::Blocked { status: Some(418), function: "block_maintenance".to_owned() }
);Structs§
- Custom
Request Context - The request facts a custom function sees (the pieces of
GuardRequestthe reference’s checks read; everything else stays with the host). - Custom
Response - A response a custom function hands back.
Enums§
- Custom
Request Verdict - What
decide_custom_requestdecided. - Custom
Validators Verdict - What
decide_custom_validatorsdecided. - Validator
Answer - What a route validator returned: the reference’s truthy response (blocks with its own shape) versus a truthy non-response value (logs and emits, never blocks).
Constants§
- CUSTOM_
REQUEST_ CHECK_ NAME - The
custom_requestcheck’s stable name (check_name). - CUSTOM_
VALIDATORS_ CHECK_ NAME - The
custom_validatorscheck’s stable name (check_name).
Functions§
- anonymous_
name - The
"anonymous"name the reference falls back to for unnamed callables. - decide_
custom_ request - The
custom_requestcheck body: the function runs once; a returned response blocks with it. - decide_
custom_ validators - The
custom_validatorscheck body: run in order, first truthy answer wins (the reference stops at the first truthy response, never running the rest).
Type Aliases§
- Custom
Request Fn - The host-supplied
custom_request_checkfunction. - Custom
Validator Fn - The host-supplied route validator function.