pub struct UaRestrictionPlugin {
allowlist: Vec<Regex>,
denylist: Vec<Regex>,
bypass_missing: bool,
rejected_code: u16,
rejected_msg: String,
}Expand description
Restricts access based on the User-Agent request header.
Exactly one of allowlist / denylist is configured (APISIX oneOf
parity). Each User-Agent value is trimmed and tested against the regexes;
in allowlist mode a request passes when any value matches any rule, in
denylist mode a request is rejected when any value matches any rule.
A missing User-Agent is rejected unless bypass_missing is set.
Fields§
§allowlist: Vec<Regex>Compiled allowlist regexes; non-empty means allowlist mode.
denylist: Vec<Regex>Compiled denylist regexes; non-empty means denylist mode.
bypass_missing: boolPass requests that carry no User-Agent header (default false).
rejected_code: u16HTTP status for rejections (default 403).
rejected_msg: StringBody message for rejections.
Implementations§
Source§impl UaRestrictionPlugin
impl UaRestrictionPlugin
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:
allowlist(array of regex strings): only matching User-Agents pass.denylist(array of regex strings): matching User-Agents are rejected. Exactly one ofallowlist/denylistmust be non-empty (APISIX rejects both-set and neither-set configs); regexes are compiled here, so an invalid pattern is a config error.bypass_missing(bool, defaultfalse): pass requests without a User-Agent header instead of rejecting them.rejected_code(integer 200–599, default403): rejection status.rejected_msg(string, default"Not allowed"): rejection message, returned as{"message": ...}.
type: ua-restriction
config:
denylist: ["curl/.*", "(?i)spider"]
bypass_missing: false
rejected_msg: Not allowedSourcefn reject(&self, ctx: Context) -> Result<PluginOutput, PluginExecutionError>
fn reject(&self, ctx: Context) -> Result<PluginOutput, PluginExecutionError>
Builds the 403-style rejection: JSON body on the response, error routed
through the error port with code UA_RESTRICTED.
Trait Implementations§
Source§impl Plugin for UaRestrictionPlugin
impl Plugin for UaRestrictionPlugin
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 UaRestrictionPlugin
impl RefUnwindSafe for UaRestrictionPlugin
impl Send for UaRestrictionPlugin
impl Sync for UaRestrictionPlugin
impl Unpin for UaRestrictionPlugin
impl UnsafeUnpin for UaRestrictionPlugin
impl UnwindSafe for UaRestrictionPlugin
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