expression

Compare parsed URL origins

For ordinary HTTPS URLs, the origin is based on scheme, host and effective port, not path or query. An origin equality check alone is not a complete outbound request authorization policy. External crate example; constructs data in memory, does not send requests. Expected stdout (not executed): true false Common mistake: Comparing origins using an arbitrary string prefix.

Formal Syntax & Structure

rust syntaxrust
a.origin() == b.origin()

Working Example

Example Snippetrust
fn main() {    let a = url::Url::parse("https://example.com/a").unwrap();    let b = url::Url::parse("https://example.com:443/b").unwrap();    let c = url::Url::parse("https://example.com:8443/a").unwrap();    println!("{} {}", a.origin() == b.origin(), a.origin() == c.origin());}
Rust Reference