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
This commit is contained in:
shockrah 2021-02-03 13:54:29 -08:00
parent 154086e740
commit 9ceeabea3b

View File

@ -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,6 +30,28 @@ pub async fn parse_json_params(body_raw: &mut Body) -> Result<Value, serde_json:
Ok(values)
}
pub fn parse_query_string<'qs>(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