mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-30 18:34:36 +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`
|
* port `Extensions` type from http create, we dont need `Send + Sync`
|
||||||
|
|
||||||
|
* `HttpRequest::query()` returns `&HashMap<String, String>`
|
||||||
|
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//! HTTP Request message related code.
|
//! HTTP Request message related code.
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ptr))]
|
#![cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ptr))]
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{cmp, fmt, io, mem, str};
|
use std::{cmp, fmt, io, mem, str};
|
||||||
@ -47,7 +48,7 @@ pub struct HttpInnerMessage {
|
|||||||
resource: RouterResource,
|
resource: RouterResource,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Query(Params<'static>);
|
struct Query(HashMap<String, String>);
|
||||||
struct Cookies(Vec<Cookie<'static>>);
|
struct Cookies(Vec<Cookie<'static>>);
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
@ -382,18 +383,15 @@ impl<S> HttpRequest<S> {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Get a reference to the Params object.
|
/// Get a reference to the Params object.
|
||||||
/// Params is a container for url query parameters.
|
/// 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() {
|
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()) {
|
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(query));
|
||||||
self.as_mut().extensions.insert(Query(params));
|
|
||||||
}
|
}
|
||||||
let params: &Params<'a> =
|
&self.extensions().get::<Query>().unwrap().0
|
||||||
unsafe { mem::transmute(&self.extensions().get::<Query>().unwrap().0) };
|
|
||||||
params
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The query string in the URL.
|
/// The query string in the URL.
|
||||||
|
Loading…
Reference in New Issue
Block a user