From 4fe55b1268cf02b2b6433c05d51227cc23b58a89 Mon Sep 17 00:00:00 2001
From: Darius Auding <Darius.auding@gmx.de>
Date: Tue, 6 Jun 2023 22:29:36 +0200
Subject: [PATCH] Some rather small changes

---
 core/http/src/handling/request.rs | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/core/http/src/handling/request.rs b/core/http/src/handling/request.rs
index 6fa46de..09f5db6 100644
--- a/core/http/src/handling/request.rs
+++ b/core/http/src/handling/request.rs
@@ -71,7 +71,6 @@ impl Request<'_> {
             _ => false,
         }
     }
-    // pub fn get_post_form_key<T: FromRequest>(&self, data: Data) -> T {}
     pub fn get_get_form_keys<'a>(
         &'a self,
         keys: &'a [&str],
@@ -115,7 +114,7 @@ impl Request<'_> {
         &self,
         keys: &[&str],
         data: &Data,
-    ) -> Result<Vec<String>, ParseFormError> {
+    ) -> Result<HashMap<&str, Result<&str, ParseFormError>>, ParseFormError> {
         let mut post_type = self
             .headers
             .iter()
@@ -131,6 +130,7 @@ impl Request<'_> {
         let post_type: Vec<&str> = post_type.trim().split(';').collect();
         let mime_type = post_type[0].parse::<Mime>().unwrap();
 
+        let mut result = HashMap::new();
         match mime_type {
             Mime::ApplicationXWwwFormUrlencoded => {
                 let data = String::from_utf8(data.buffer.clone()).unwrap();
@@ -139,15 +139,15 @@ impl Request<'_> {
                     .map(|kvp| kvp.split_once("=").unwrap())
                     .collect::<HashMap<&str, &str>>();
 
-                let mut result: Vec<String> = Vec::with_capacity(keys.len());
                 for key in keys {
-                    if let Some(val) = kvps.get(key) {
-                        result.push(val.to_string());
+                    let entry = if let Some(val) = kvps.get(key) {
+                        Ok(*val)
                     } else {
-                        return Err(ParseFormError {
+                        Err(ParseFormError {
                             error: ParseErrors::NoData,
-                        });
-                    }
+                        })
+                    };
+                    result.insert(*key, entry);
                 }
                 Ok(result)
             }
@@ -158,7 +158,7 @@ impl Request<'_> {
                     .unwrap()
                     .strip_prefix("boundary=")
                     .unwrap();
-                let mut boundary = "--".as_bytes().to_vec();
+                let mut boundary = b"--".to_vec();
                 boundary.extend_from_slice(from_req.trim_matches('"').as_bytes());
                 let mut end_boundary = boundary.clone();
                 end_boundary.extend_from_slice(b"--");
-- 
GitLab