moving http parameterization to its own module

This commit is contained in:
shockrah 2020-06-18 20:10:58 -07:00
parent 0b6b5e51c6
commit 32c8619d93

View File

@ -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<Body>, 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<Body>, meth: &Method,
async fn main_responder(request: Request<Body>) -> Result<Response<Body>, 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