From 3aaacdd656fee030b1bc793b46740dcef00333ea Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 23 Feb 2025 09:42:34 +0200 Subject: [PATCH] implement specification-compatible Url parser --- src/request/titan/header.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/request/titan/header.rs b/src/request/titan/header.rs index ebada1f..d95b7c5 100644 --- a/src/request/titan/header.rs +++ b/src/request/titan/header.rs @@ -1,6 +1,6 @@ pub struct Header { pub size: usize, - pub url: String, + pub url: Url, pub mime: Option, pub token: Option, pub options: Option>, @@ -52,9 +52,11 @@ impl Header { }, 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) { 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"), @@ -103,3 +105,4 @@ fn test() { use anyhow::{bail, Result}; use indexmap::IndexMap; use std::str::from_utf8; +use url::Url;