mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
use HashMap for HttpRequest::query()
This commit is contained in:
parent
b6ed778775
commit
c3f295182f
@ -41,6 +41,8 @@
|
||||
|
||||
* port `Extensions` type from http create, we dont need `Send + Sync`
|
||||
|
||||
* `HttpRequest::query()` returns `&HashMap<String, String>`
|
||||
|
||||
|
||||
### Removed
|
||||
|
||||
|
@ -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<String, String>);
|
||||
struct Cookies(Vec<Cookie<'static>>);
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
@ -382,18 +383,15 @@ impl<S> HttpRequest<S> {
|
||||
#[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<String, String> {
|
||||
if self.extensions().get::<Query>().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::<Query>().unwrap().0) };
|
||||
params
|
||||
&self.extensions().get::<Query>().unwrap().0
|
||||
}
|
||||
|
||||
/// The query string in the URL.
|
||||
|
Loading…
Reference in New Issue
Block a user