feat: Origin function and tests

This commit is contained in:
2025-09-08 15:05:54 +01:00
parent 62943e11e7
commit 38e2012945
3 changed files with 75 additions and 2 deletions

View File

@@ -97,7 +97,7 @@ pub fn normalise(uri: Uri) -> Uri {
Uri(scheme, userinfo, host, port, path, query, fragment)
}
fn scheme_normalisation(
pub fn scheme_normalisation(
port: Option(Int),
scheme: Option(String),
) -> Option(Int) {

View File

@@ -119,5 +119,16 @@ pub fn parse_query(query: String) -> Result(List(#(String, String)), Nil) {
}
pub fn origin(uri: Uri) -> Result(String, Nil) {
todo
case uri.scheme, uri.host, utils.scheme_normalisation(uri.port, uri.scheme) {
Some("http" as scheme), Some(host), port
| Some("https" as scheme), Some(host), port
-> {
let port =
port
|> option.map(fn(p) { ":" <> int.to_string(p) })
|> option.unwrap("")
Ok(scheme <> "://" <> host <> port)
}
_, _, _ -> Error(Nil)
}
}