domain
ModuleThe domain and path checks every purge and certificate call starts with.
Contents
use utopia_cdn::domain::validate;Rust
pub fn validate(domain: &str) -> Result<Cow<'_, str>, Error>A domain in its canonical form: lower-cased (borrowed when it already is), and a hostname without a scheme, port, path or trailing slash.
DNS labels are case-insensitive (RFC 4343), so case is folded rather than rejected. Use the returned value: it is what providers and equality checks expect.
Fails with Error::InvalidArgument for anything else.
Rust
use utopia_cdn::domain;
assert_eq!(domain::validate("APP.Example.CoM")?, "app.example.com");
assert!(domain::validate("https://app.example.com").is_err());use utopia_cdn::domain::validate_paths;Rust
pub fn validate_paths<S: AsRef<str>>(paths: &[S]) -> Result<(), Error>Checks that every cache path begins with /.
Fails with Error::InvalidArgument otherwise.
Rust
use utopia_cdn::domain;
assert!(domain::validate_paths(&["/index.html", "/assets/app.js"]).is_ok());
assert!(domain::validate_paths(&["index.html"]).is_err());