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 const fn with_resolve(self, resolve: bool) -> Self
pub const fn with_resolve(self, resolve: bool) -> Self
Sets whether relative URL resolution is enabled (builder pattern)
When false, Self::resolve never joins href against base — it
always returns href unchanged. Self::resolve_safe is different:
it still validates whatever resolve returns (dangerous schemes,
SSRF/private-IP checks) even when this is false, so it does not
simply return href unchanged — see its docs for why. Mirrors
ParseOptions::resolve_relative_uris.
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(&self, href: &str) -> String
pub fn resolve(&self, href: &str) -> String
Resolves a URL against the current base
Returns href unchanged when relative URL resolution is disabled
(see Self::with_resolve).
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.
§Security
These safety checks run unconditionally, even when relative URL
resolution is disabled via Self::with_resolve. with_resolve(false)
only disables joining href against base; it never skips scheme/SSRF
validation, so a feed-supplied href that is itself an absolute
dangerous or private-network URL is still blocked (#438).
§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");
// Safety checks still run when relative resolution is disabled
let no_resolve_ctx = BaseUrlContext::new().with_resolve(false);
assert_eq!(
no_resolve_ctx.resolve_safe("http://169.254.169.254/latest/meta-data/"),
""
);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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more