rust_web_server/body/form_urlencoded/
mod.rs

1use std::collections::HashMap;
2use crate::symbol::SYMBOL;
3use crate::url::URL;
4
5pub struct FormUrlEncoded;
6
7impl FormUrlEncoded {
8    pub fn parse(data: Vec<u8>) -> Result<HashMap<String, String>, String> {
9        let boxed_string = String::from_utf8(data);
10        if boxed_string.is_err() {
11            let message = boxed_string.err().unwrap().to_string();
12            return Err(message)
13        }
14        let string = boxed_string.unwrap();
15        let string = string.replace(|x : char | x.is_ascii_control(), SYMBOL.empty_string).trim().to_string();
16
17
18        Ok(URL::parse_query(&string))
19    }
20
21    pub fn generate(map: HashMap<String, String>) -> String {
22        URL::build_query(map)
23    }
24}