From 9ceeabea3b595530cb13f264af59584d92688b23 Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 3 Feb 2021 13:54:29 -0800 Subject: [PATCH] Moving query parameters to the query string This should allow js developers to write their own apps now as js doesn't allow for bodies in GET requests From now the body is used for raw payloads --- json-api/src/http.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 +}