add uri normalization

This commit is contained in:
Fabian Freund
2026-03-09 19:24:45 +01:00
parent 4b01155584
commit 1b1ee65fb3
4 changed files with 32 additions and 26 deletions
+10
View File
@@ -29,4 +29,14 @@ extension UriX on Uri {
bool get isHttp => isScheme('http');
bool get isHttps => isScheme('https');
bool get isHttpOrHttps => isHttp || isHttps;
/// Removes a bare root path (`/`) when there is no query or fragment, so
/// that `https://example.com/` and `https://example.com` are treated as
/// equivalent.
Uri get normalized {
if (path == '/' && !hasQuery && !hasFragment) {
return replace(path: '');
}
return this;
}
}