This commit is contained in:
Douman 2018-07-16 19:41:14 +03:00
parent 6dffedafe0
commit beace9e1dc
2 changed files with 7 additions and 22 deletions

View File

@ -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)))));
FutOk(None)
}
Err(err) => {
println!("Session::from_request error={:?}", &err);
FutErr(err)
}
Err(err) => FutErr(err),
});
Ok(Started::Future(Box::new(fut)))
}
@ -422,18 +419,11 @@ impl CookieSessionInner {
fn load<S>(&self, req: &mut HttpRequest<S>) -> HashMap<String, String> {
if let Ok(cookies) = req.cookies() {
println!("Load cookies");
for cookie in cookies.iter() {
if cookie.name() == self.name {
println!("cookie.name()={} | value={}", cookie.name(), cookie.value());
let mut jar = CookieJar::new();
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 {
CookieSecurity::Signed => jar.signed(&self.key).get(&self.name),
CookieSecurity::Private => {
@ -441,14 +431,9 @@ impl CookieSessionInner {
}
};
if let Some(cookie) = cookie_opt {
println!("Loaded secure cookie");
match serde_json::from_str(cookie.value()) {
Ok(val) => return val,
Err(error) => println!("serde_json Error: {}", error)
if let Ok(val) = serde_json::from_str(cookie.value()) {
return val;
}
//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
/// 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
///

View File

@ -1003,6 +1003,7 @@ fn test_session_storage_middleware() {
const SIMPLE_PAYLOAD: &'static str = "kantan";
const COMPLEX_NAME: &'static str = "test";
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";
let mut srv = test::TestServer::with_factory(move || {
@ -1031,10 +1032,6 @@ fn test_session_storage_middleware() {
}).resource("/expect_cookie", move |r| {
r.f(|req| {
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);
assert!(value.is_ok());