pub trait HttpPolicy:
Send
+ Sync
+ 'static {
// Required method
fn check_url(&self, url: &str, method: &str) -> Result<(), PolicyError>;
// Provided method
fn policy_name(&self) -> &'static str { ... }
}Expand description
Policy that decides whether a given URL may be accessed.
Every function in the http module calls HttpPolicy::check_url
before making a request.
§Built-in implementations
| Type | Behaviour |
|---|---|
Unrestricted | No checks (default) |
HttpAllowList | Allow only listed host patterns |
§Custom implementations
use mlua_batteries::policy::{HttpPolicy, PolicyError};
struct BlockInternal;
impl HttpPolicy for BlockInternal {
fn check_url(&self, url: &str, method: &str) -> Result<(), PolicyError> {
if url.contains("169.254.") || url.contains("localhost") {
Err(PolicyError::new(format!("{method} denied: internal URL '{url}'")))
} else {
Ok(())
}
}
}Required Methods§
Provided Methods§
Sourcefn policy_name(&self) -> &'static str
fn policy_name(&self) -> &'static str
Human-readable name for this policy, used in Debug output.
The default implementation returns std::any::type_name of the
concrete type, which works correctly even through trait objects
because the vtable dispatches to the concrete implementation.