diff --git a/server/src/main.rs b/server/src/main.rs index ca5cf1c..38407e4 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -28,24 +28,8 @@ mod channels; mod members; mod messages; mod badges; +mod http_params; -fn map_qs(query_string_raw: Option<&str>) -> HashMap<&str, &str> { - /* - * Parse a given query string and build a hashmap from it - */ - let mut map: HashMap<&str, &str> = HashMap::new(); - if let Some(qs) = query_string_raw { - let raw_pairs: Vec<&str> = qs.split('&').collect(); - for raw_pair in raw_pairs.iter() { - let sub_segment: Vec<&str> = raw_pair.split('=').collect(); - match sub_segment.len() { - 2 => map.insert(sub_segment[0], sub_segment[1]), - _ => continue - }; - } - } - map -} async fn route_dispatcher(pool: &Pool, resp: &mut Response, meth: &Method, path: &str, params: &HashMap<&str, &str>) { // At some point we should have some way of hiding this obnoxious complexity @@ -71,9 +55,10 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response, meth: &Method, async fn main_responder(request: Request) -> Result, hyper::Error>{ use AuthReason::*; let mut response = Response::new(Body::empty()); - let method = request.method(); - let path = request.uri().path(); - let params = map_qs(request.uri().query()); + let (parts, mut body) = request.into_parts(); + let method = parts.method; + let path = parts.uri.path(); + let params = http_params::parse_params(parts.uri.query(), &mut body).await; let pool = Pool::new(&env::var("DATABASE_URL").unwrap()); // some more information in the response would be great right about here