pub struct BaseUrlContext { /* private fields */ }Expand description
Context for tracking base URLs during parsing
This struct maintains the current base URL context and provides methods for URL resolution within a parsing context.
Implementations§
Source§impl BaseUrlContext
impl BaseUrlContext
Sourcepub fn with_base(base: impl Into<String>) -> Self
pub fn with_base(base: impl Into<String>) -> Self
Creates a new context with an initial base URL
Sourcepub fn update_base(&mut self, xml_base: &str)
pub fn update_base(&mut self, xml_base: &str)
Updates the base URL with a new xml:base value
The new base is resolved against the current base if it’s relative.
Sourcepub fn resolve_safe(&self, href: &str) -> String
pub fn resolve_safe(&self, href: &str) -> String
Resolves a URL against the current base with SSRF protection
This method performs URL resolution and validates the result to prevent Server-Side Request Forgery (SSRF) attacks via malicious xml:base attributes.
§Security
If the resolved URL fails SSRF safety checks (localhost, private IPs,
dangerous schemes), the original href is returned unchanged instead
of the resolved URL.
§Arguments
href- The URL to resolve (may be relative or absolute)
§Returns
The resolved URL if safe, otherwise the original href
§Examples
use feedparser_rs::util::base_url::BaseUrlContext;
// Safe URL resolution
let ctx = BaseUrlContext::with_base("http://example.com/");
assert_eq!(ctx.resolve_safe("page.html"), "http://example.com/page.html");
// SSRF blocked - returns original href
let dangerous_ctx = BaseUrlContext::with_base("http://localhost/");
assert_eq!(dangerous_ctx.resolve_safe("admin"), "admin");Sourcepub fn child_with_base(&self, xml_base: &str) -> Self
pub fn child_with_base(&self, xml_base: &str) -> Self
Creates a child context with an additional xml:base
Trait Implementations§
Source§impl Clone for BaseUrlContext
impl Clone for BaseUrlContext
Source§fn clone(&self) -> BaseUrlContext
fn clone(&self) -> BaseUrlContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more