gliri
Values
pub fn are_equivalent(iri1: iri.Iri, iri2: iri.Iri) -> Bool
Determines whether 2 Iris are equivalent, i.e. denote the same endpoint
This will perform normalisation if the Iris are not exactly the same
Examples
let iri = parse("Https://host.com:443?q=1#fragment")
let iri2 = parse("https://HOST.com/?q=1#fragment")
are_equivalent(iri, iri2)
// -> True
pub fn merge(
base: iri.Iri,
relative: iri.Iri,
) -> Result(iri.Iri, Nil)
Resolves a URI with respect to the given base URI.
The base URI must be an absolute URI or this function will return an error. The algorithm for merging uris is as described in RFC 3986.
pub fn normalise(iri: iri.Iri) -> iri.Iri
Normalises the Iri
This follows the normalisation process in RFC3987
- Case normalisation (scheme/host -> lowercase, percent-encoding -> uppercase)
- Character normalisation
- Percent-encoding normalisation (removal of non-necessary encoding)
- Path segement normalisation (processing of /, .. and .)
- Scheme based normalisation (removal of default ports for http/https/ftp/ws/wss, setting empty path to / for valid http(s) uri)
Examples
let iri = Iri(
scheme: Some("Https"),
userinfo: None,
host: Some("host.com"),
port: Some(443),
path: "",
query: Some("q=1"),
fragment: Some("fragment")
)
normalise(iri)
// -> "https://host.com/?q=1#fragment"
pub fn origin(iri: iri.Iri) -> Result(String, Nil)
Returns the origin of the passed URI.
Returns the origin of a uri based on RFC 6454
If the IRI scheme is not http and https.
Error will be returned.
Examples
let assert Ok(iri) = parse("https://blah.com/test?this#that")
origin(uri)
// -> Ok("https://blah.com")
pub fn parse(iri: String) -> Result(iri.Iri, Nil)
Parses a string to the RFC3987 standard.
Error is returned if it fails parsing.
Examples
parse("https://me@host.com:9999/path?q=1#fragment")
// -> Ok(
// Iri(
// scheme: Some("https"),
// userinfo: Some("me"),
// host: Some("host.com"),
// port: Some(9999),
// path: "/path",
// query: Some("q=1"),
// fragment: Some("fragment")
// )
// )
pub fn to_string(iri: iri.Iri) -> String
Encodes a Uri value as a URI string.
Examples
let uri = Uri(
scheme: Some("https"),
userinfo: Some("me"),
host: Some("host.com"),
port: Some(9999),
path: "/path",
query: Some("q=1"),
fragment: Some("fragment")
)
to_string(uri)
// -> "https://me@host.com:9999/path?q=1#fragment"