implement specification-compatible Url parser

This commit is contained in:
yggverse 2025-02-23 09:42:34 +02:00
parent 1a1c0a9898
commit 3aaacdd656

View file

@ -1,6 +1,6 @@
pub struct Header { pub struct Header {
pub size: usize, pub size: usize,
pub url: String, pub url: Url,
pub mime: Option<String>, pub mime: Option<String>,
pub token: Option<String>, pub token: Option<String>,
pub options: Option<IndexMap<String, String>>, pub options: Option<IndexMap<String, String>>,
@ -52,9 +52,11 @@ impl Header {
}, },
None => None, None => None,
}, },
// * Titan URL is not compatible with [STD66](https://datatracker.ietf.org/doc/html/rfc3986)
// parse partially; see protocol specification for details
url: match Regex::new(r"^([^;\?]+)")?.captures(header) { url: match Regex::new(r"^([^;\?]+)")?.captures(header) {
Some(c) => match c.get(1) { Some(c) => match c.get(1) {
Some(v) => v.as_str().to_string(), Some(v) => Url::parse(v.as_str())?,
None => bail!("URL required"), None => bail!("URL required"),
}, },
None => bail!("URL required"), None => bail!("URL required"),
@ -103,3 +105,4 @@ fn test() {
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use indexmap::IndexMap; use indexmap::IndexMap;
use std::str::from_utf8; use std::str::from_utf8;
use url::Url;