From c3f295182fdc99051d575d406fc436a6f721fb31 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 17 Jun 2018 08:54:30 +0600 Subject: [PATCH] use HashMap for HttpRequest::query() --- CHANGES.md | 2 ++ src/httprequest.rs | 16 +++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index be17ef3d..b8ca7d47 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -41,6 +41,8 @@ * port `Extensions` type from http create, we dont need `Send + Sync` +* `HttpRequest::query()` returns `&HashMap` + ### Removed diff --git a/src/httprequest.rs b/src/httprequest.rs index dded35f6..4d6ed87e 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -1,5 +1,6 @@ //! HTTP Request message related code. #![cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ptr))] +use std::collections::HashMap; use std::net::SocketAddr; use std::rc::Rc; use std::{cmp, fmt, io, mem, str}; @@ -47,7 +48,7 @@ pub struct HttpInnerMessage { resource: RouterResource, } -struct Query(Params<'static>); +struct Query(HashMap); struct Cookies(Vec>); #[derive(Debug, Copy, Clone, PartialEq)] @@ -382,18 +383,15 @@ impl HttpRequest { #[doc(hidden)] /// Get a reference to the Params object. /// Params is a container for url query parameters. - pub fn query<'a>(&'a self) -> &'a Params { + pub fn query(&self) -> &HashMap { if self.extensions().get::().is_none() { - let mut params: Params<'a> = Params::new(); + let mut query = HashMap::new(); for (key, val) in form_urlencoded::parse(self.query_string().as_ref()) { - params.add(key, val); + query.insert(key.as_ref().to_string(), val.to_string()); } - let params: Params<'static> = unsafe { mem::transmute(params) }; - self.as_mut().extensions.insert(Query(params)); + self.as_mut().extensions.insert(Query(query)); } - let params: &Params<'a> = - unsafe { mem::transmute(&self.extensions().get::().unwrap().0) }; - params + &self.extensions().get::().unwrap().0 } /// The query string in the URL.