mirror of https://github.com/fafhrd91/actix-web
Clean-up
This commit is contained in:
parent
6dffedafe0
commit
beace9e1dc
|
@ -255,10 +255,7 @@ impl<S: 'static, T: SessionBackend<S>> Middleware<S> for SessionStorage<T, S> {
|
||||||
.insert(Arc::new(SessionImplCell(RefCell::new(Box::new(sess)))));
|
.insert(Arc::new(SessionImplCell(RefCell::new(Box::new(sess)))));
|
||||||
FutOk(None)
|
FutOk(None)
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => FutErr(err),
|
||||||
println!("Session::from_request error={:?}", &err);
|
|
||||||
FutErr(err)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Ok(Started::Future(Box::new(fut)))
|
Ok(Started::Future(Box::new(fut)))
|
||||||
}
|
}
|
||||||
|
@ -422,18 +419,11 @@ impl CookieSessionInner {
|
||||||
|
|
||||||
fn load<S>(&self, req: &mut HttpRequest<S>) -> HashMap<String, String> {
|
fn load<S>(&self, req: &mut HttpRequest<S>) -> HashMap<String, String> {
|
||||||
if let Ok(cookies) = req.cookies() {
|
if let Ok(cookies) = req.cookies() {
|
||||||
println!("Load cookies");
|
|
||||||
for cookie in cookies.iter() {
|
for cookie in cookies.iter() {
|
||||||
if cookie.name() == self.name {
|
if cookie.name() == self.name {
|
||||||
println!("cookie.name()={} | value={}", cookie.name(), cookie.value());
|
|
||||||
let mut jar = CookieJar::new();
|
let mut jar = CookieJar::new();
|
||||||
jar.add_original(cookie.clone());
|
jar.add_original(cookie.clone());
|
||||||
|
|
||||||
println!("Jar cookies:");
|
|
||||||
for cookie in jar.iter() {
|
|
||||||
println!("cookie.name()={} | value={}", cookie.name(), cookie.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
let cookie_opt = match self.security {
|
let cookie_opt = match self.security {
|
||||||
CookieSecurity::Signed => jar.signed(&self.key).get(&self.name),
|
CookieSecurity::Signed => jar.signed(&self.key).get(&self.name),
|
||||||
CookieSecurity::Private => {
|
CookieSecurity::Private => {
|
||||||
|
@ -441,14 +431,9 @@ impl CookieSessionInner {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Some(cookie) = cookie_opt {
|
if let Some(cookie) = cookie_opt {
|
||||||
println!("Loaded secure cookie");
|
if let Ok(val) = serde_json::from_str(cookie.value()) {
|
||||||
match serde_json::from_str(cookie.value()) {
|
return val;
|
||||||
Ok(val) => return val,
|
|
||||||
Err(error) => println!("serde_json Error: {}", error)
|
|
||||||
}
|
}
|
||||||
//if let Ok(val) = serde_json::from_str(cookie.value()) {
|
|
||||||
// return val;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -479,6 +464,9 @@ impl CookieSessionInner {
|
||||||
/// all session data is lost. The constructors will panic if the key is less
|
/// all session data is lost. The constructors will panic if the key is less
|
||||||
/// than 32 bytes in length.
|
/// than 32 bytes in length.
|
||||||
///
|
///
|
||||||
|
/// The backend relies on `cookie` crate to create and read cookies.
|
||||||
|
/// By default all cookies are percent encoded, but certain symbols may
|
||||||
|
/// cause troubles when reading cookie, if they are not properly percent encoded.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
|
|
@ -1003,6 +1003,7 @@ fn test_session_storage_middleware() {
|
||||||
const SIMPLE_PAYLOAD: &'static str = "kantan";
|
const SIMPLE_PAYLOAD: &'static str = "kantan";
|
||||||
const COMPLEX_NAME: &'static str = "test";
|
const COMPLEX_NAME: &'static str = "test";
|
||||||
const COMPLEX_PAYLOAD: &'static str = "url=https://test.com&generate_204";
|
const COMPLEX_PAYLOAD: &'static str = "url=https://test.com&generate_204";
|
||||||
|
//TODO: investigate how to handle below input
|
||||||
//const COMPLEX_PAYLOAD: &'static str = "FJc%26continue_url%3Dhttp%253A%252F%252Fconnectivitycheck.gstatic.com%252Fgenerate_204";
|
//const COMPLEX_PAYLOAD: &'static str = "FJc%26continue_url%3Dhttp%253A%252F%252Fconnectivitycheck.gstatic.com%252Fgenerate_204";
|
||||||
|
|
||||||
let mut srv = test::TestServer::with_factory(move || {
|
let mut srv = test::TestServer::with_factory(move || {
|
||||||
|
@ -1031,10 +1032,6 @@ fn test_session_storage_middleware() {
|
||||||
}).resource("/expect_cookie", move |r| {
|
}).resource("/expect_cookie", move |r| {
|
||||||
r.f(|req| {
|
r.f(|req| {
|
||||||
let cookies = req.cookies().expect("To get cookies");
|
let cookies = req.cookies().expect("To get cookies");
|
||||||
println!("Cookies:");
|
|
||||||
for cookie in cookies.iter() {
|
|
||||||
println!("{}={}", cookie.name(), cookie.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = req.session().get::<String>(SIMPLE_NAME);
|
let value = req.session().get::<String>(SIMPLE_NAME);
|
||||||
assert!(value.is_ok());
|
assert!(value.is_ok());
|
||||||
|
|
Loading…
Reference in New Issue