pub struct RequestValidationPlugin {
header_schema: Option<Validator>,
body_schema: Option<Validator>,
rejected_code: u16,
rejected_msg: Option<String>,
}Expand description
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.
Headers are validated as a single-value object (first value per header, names lowercased), matching the shape APISIX passes to its schema check. After a successful JSON-body validation the body is re-serialized from the parsed document, so the JSON that was validated is exactly the JSON the upstream receives (guards against JSON-interoperability smuggling).
Fields§
§header_schema: Option<Validator>§body_schema: Option<Validator>§rejected_code: u16§rejected_msg: Option<String>Implementations§
Source§impl RequestValidationPlugin
impl RequestValidationPlugin
Sourcepub fn from_config(config: &HashMap<String, Value>) -> Result<Self, String>
pub fn from_config(config: &HashMap<String, Value>) -> Result<Self, String>
Builds the plugin from node config.
Accepted keys:
header_schema(object): JSON Schema applied to the request headers, seen as{name: first_value}with lowercase names.body_schema(object): JSON Schema applied to the parsed request body (JSON, or urlencoded decoded to a flat object).rejected_code(integer 200–599, default400): response status for rejected requests.rejected_msg(string): fixed message returned instead of the validator’s error description.
At least one of header_schema / body_schema is required; both are
compiled here so malformed schemas fail at config load.
type: request-validation
config:
rejected_code: 422
body_schema:
type: object
required: [name]
properties:
name: { type: string, minLength: 1 }Sourcefn reject(&self, ctx: Context, detail: String) -> PluginExecutionError
fn reject(&self, ctx: Context, detail: String) -> PluginExecutionError
Writes the rejection onto the response and returns the error that
routes the context through the node’s error port.
Trait Implementations§
Source§impl Plugin for RequestValidationPlugin
impl Plugin for RequestValidationPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for RequestValidationPlugin
impl !RefUnwindSafe for RequestValidationPlugin
impl Send for RequestValidationPlugin
impl Sync for RequestValidationPlugin
impl Unpin for RequestValidationPlugin
impl UnsafeUnpin for RequestValidationPlugin
impl !UnwindSafe for RequestValidationPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more