1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +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 {
Either::A(
inner.clear_cache(val)
.and_then(move |_| .and_then(move |_|
match inner.remove_cookie(&mut res){ match inner.remove_cookie(&mut res){
Ok(_) => Either::A(ok(res)), Ok(_) => Either::A(ok(res)),
Err(_err) => Either::B(err( Err(_err) => Either::B(err(
error::ErrorInternalServerError(_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 {
Either::A(
self.addr self.addr
.send(Command(resp_array!["DEL", key])) .send(Command(resp_array!["DEL", key]))
.map_err(Error::from) .map_err(Error::from)
.and_then(|res| .and_then(|res| {
match res { match res {
// redis responds with number of deleted records // redis responds with number of deleted records
Ok(RespValue::Integer(x)) if x > 0 => Ok(()), Ok(RespValue::Integer(x)) if x > 0 => Ok(()),
_ => Err(error::ErrorInternalServerError( _ => Err(error::ErrorInternalServerError(
"failed to remove session from cache")) "failed to remove session from cache"))
} }
) })
)
} else {
Either::B(err(error::ErrorInternalServerError(
"missing session key - unexpected")))
}
} }
/// invalidates session cookie /// invalidates session cookie