Unobtanium makes heavy use of the url crate and inherits its way of representing parsed URLs.
Also see: The URL Standard
URL Component | Datatype | If absent |
---|---|---|
scheme |
str | empty |
username |
str | empty |
password |
Option<str> | empty |
host |
Option<str> | None |
port |
Option<u16> | None |
path |
str | empty |
query |
Option<str> | None |
fragment |
Option<str> | None |
All values are taken as is, for "special" URLs (mostly http
and https
) the hostnames are punycode encoded, otherwise they are percent encoded.
Origin
Unobtanium does not follow the url crate when it comes to the URL origin implementation. For unobtanium the Origin is the scheme
, host
and port
taken from the URL and put into a struct. For http
, https
, ws
, wss
and ftp
the default port numbers are automatically filled in if no port is mentioned in the URL using the port_or_known_default() getter. If two origins are represented using equal data, they equal each other, this simplifies matching and comparing logic across the whole codebase.
Criteria
URLs and Origins can be matched using the UrlCriterium (since 2.0.0) and OriginCriterium. Their naming and types follow the above table.
In addition to matching single fields the UrlCriterium
offers two extra methods:
equals
(Url):- For an equivalent to a string comparison on the whole URL
same_document_as
(UrlWithoutFragment)- Like
equals
, but ignores the fragment part on both sides of the comparison.