diff --git a/json-api/src/http.rs b/json-api/src/http.rs index 924db17..5962508 100644 --- a/json-api/src/http.rs +++ b/json-api/src/http.rs @@ -5,6 +5,7 @@ use hyper::Body; use hyper::body::to_bytes; use std::u8; +use std::collections::HashMap; const APP_JSON_HEADER: &'static str = "application/json"; const CONTENT_TYPE: &'static str = "Content-Type"; @@ -29,9 +30,31 @@ pub async fn parse_json_params(body_raw: &mut Body) -> Result(string: &'qs str) + -> HashMap<&str, &str> { + + let mut map: HashMap<&str, &str> = HashMap::new(); + + // get pairs of [key1=value1, key2=value2, ...] + for pair in string.split('&') { + + let kv: Vec<&str> = pair.split('=').collect(); + + match (kv.get(0), kv.get(1)) { + // only if the format is some_key=some_value do we actually care about it + (Some(key), Some(value)) => { + map.insert(key, value); + }, + // ignore all non-pairs + _ => continue + }; + } + return map; +} + #[inline] pub fn extract_uid(values: &Value) -> u64 { // pulling 'id' from user params is safe because the // auth modules guarantees this to be there already values.get("id").unwrap().as_u64().unwrap() -} \ No newline at end of file +}