diff --git a/src/uri/builder.rs b/src/uri/builder.rs index 046a116a..b87b9d5a 100644 --- a/src/uri/builder.rs +++ b/src/uri/builder.rs @@ -257,5 +257,6 @@ mod tests { assert_eq!(uri.scheme(), Some(&Scheme::HTTPS)); assert_eq!(uri.host(), Some("example.com")); assert_eq!(uri.path(), "*"); + assert_eq!(uri.to_string(), "https://example.com"); } } diff --git a/src/uri/mod.rs b/src/uri/mod.rs index 9a551819..0f0b0156 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -1040,7 +1040,11 @@ impl fmt::Display for Uri { f.write_str(authority.as_str())?; } - f.write_str(self.path())?; + // RFC 9112 3.2.4: the absolute-form of an asterisk-form target has an + // empty path. Writing the `*` would make it part of the authority. + if self.authority().is_none() || self.path() != "*" { + f.write_str(self.path())?; + } if let Some(query) = self.query() { f.write_str("?")?;