From 1a1c0a98987f4a82531c0b92cfedcbf76c2265dd Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 23 Feb 2025 09:22:40 +0200 Subject: [PATCH] return HashMap for Titan header options, but replace with IndexMap to keep original arguments order --- Cargo.toml | 1 + src/request/titan/header.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fc2fcaf..debaefb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,6 @@ repository = "https://github.com/YGGverse/titanite" [dependencies] anyhow = "1.0.96" +indexmap = "2.7.1" regex = "1.11.1" url = "2.5.4" diff --git a/src/request/titan/header.rs b/src/request/titan/header.rs index 09ab508..ebada1f 100644 --- a/src/request/titan/header.rs +++ b/src/request/titan/header.rs @@ -3,7 +3,7 @@ pub struct Header { pub url: String, pub mime: Option, pub token: Option, - pub options: Option>, + pub options: Option>, } impl Header { @@ -33,11 +33,15 @@ impl Header { options: match Regex::new(r"\?(.*)$")?.captures(header) { Some(c) => match c.get(1) { Some(v) => { - let mut options = Vec::new(); + let mut options = IndexMap::new(); for option in v.as_str().split("&") { let kv: Vec<&str> = option.split('=').collect(); if kv.len() == 2 { - options.push((kv[0].to_string(), kv[1].to_string())) + if let Some(v) = + options.insert(kv[0].to_string(), kv[1].to_string()) + { + bail!("Option key duplicate with value: {v}") + } } else { bail!("Invalid options format") } @@ -97,4 +101,5 @@ fn test() { } use anyhow::{bail, Result}; +use indexmap::IndexMap; use std::str::from_utf8;