1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

resolved bug related to updating session cookie

This commit is contained in:
dowwie 2019-06-18 13:47:14 -04:00
parent fa531fb03d
commit 1086180267

View File

@ -151,23 +151,33 @@ where
Either::B(Either::A(inner.update(res, state, value))), Either::B(Either::A(inner.update(res, state, value))),
(SessionStatus::Purged, Some(_)) => { (SessionStatus::Purged, Some(_)) => {
Either::B(Either::B( Either::B(Either::B(
inner.clear_cache(value) if let Some(val) = value {
.and_then(move |_| Either::A(
match inner.remove_cookie(&mut res){ inner.clear_cache(val)
Ok(_) => Either::A(ok(res)), .and_then(move |_|
Err(_err) => Either::B(err( match inner.remove_cookie(&mut res){
error::ErrorInternalServerError(_err))) Ok(_) => Either::A(ok(res)),
}) Err(_err) => Either::B(err(
error::ErrorInternalServerError(_err)))
})
)
} else {
Either::B(err(error::ErrorInternalServerError("unexpected")))
}
)) ))
}, },
(SessionStatus::Renewed, Some(state)) => { (SessionStatus::Renewed, Some(state)) => {
if let Some(val) = value {
Either::A( Either::A(
Either::B( Either::B(
inner.clear_cache(value) inner.clear_cache(val)
.and_then(move |_| .and_then(move |_|
inner.update(res, state, None)) inner.update(res, state, None))
) )
) )
} else {
Either::B(Either::A(inner.update(res, state, None)))
}
}, },
(_, None) => unreachable!() (_, None) => unreachable!()
} }
@ -285,7 +295,6 @@ impl Inner {
}; };
let state: HashMap<_, _> = state.collect(); let state: HashMap<_, _> = state.collect();
match serde_json::to_string(&state) { match serde_json::to_string(&state) {
Err(e) => Either::A(err(e.into())), Err(e) => Either::A(err(e.into())),
Ok(body) => Either::B( Ok(body) => Either::B(
@ -310,26 +319,19 @@ impl Inner {
} }
/// removes cache entry /// removes cache entry
fn clear_cache(&self, value: Option<String>) fn clear_cache(&self, key: String)
-> impl Future<Item=(), Error=Error> { -> impl Future<Item=(), Error=Error> {
if let Some(key) = value { self.addr
Either::A( .send(Command(resp_array!["DEL", key]))
self.addr .map_err(Error::from)
.send(Command(resp_array!["DEL", key])) .and_then(|res| {
.map_err(Error::from) match res {
.and_then(|res| // redis responds with number of deleted records
match res { Ok(RespValue::Integer(x)) if x > 0 => Ok(()),
// redis responds with number of deleted records _ => Err(error::ErrorInternalServerError(
Ok(RespValue::Integer(x)) if x > 0 => Ok(()), "failed to remove session from cache"))
_ => Err(error::ErrorInternalServerError( }
"failed to remove session from cache")) })
}
)
)
} else {
Either::B(err(error::ErrorInternalServerError(
"missing session key - unexpected")))
}
} }
/// invalidates session cookie /// invalidates session cookie