From 65732197b8f1e3abdf8847edcbe24ca70f8a21b5 Mon Sep 17 00:00:00 2001 From: dowwie Date: Wed, 12 Jun 2019 10:11:38 -0400 Subject: [PATCH] modified so as to consider unanticipated state changes --- actix-session/src/lib.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/actix-session/src/lib.rs b/actix-session/src/lib.rs index 30d71552f..aaf0ab02f 100644 --- a/actix-session/src/lib.rs +++ b/actix-session/src/lib.rs @@ -130,25 +130,31 @@ impl Session { /// Set a `value` from the session. pub fn set(&self, key: &str, value: T) -> Result<(), Error> { let mut inner = self.0.borrow_mut(); - inner.status = SessionStatus::Changed; - inner - .state - .insert(key.to_owned(), serde_json::to_string(&value)?); + if inner.status != SessionStatus::Purged { + inner.status = SessionStatus::Changed; + inner + .state + .insert(key.to_owned(), serde_json::to_string(&value)?); + } Ok(()) } /// Remove value from the session. pub fn remove(&self, key: &str) { let mut inner = self.0.borrow_mut(); - inner.status = SessionStatus::Changed; - inner.state.remove(key); + if inner.status != SessionStatus::Purged { + inner.status = SessionStatus::Changed; + inner.state.remove(key); + } } /// Clear the session. pub fn clear(&self) { let mut inner = self.0.borrow_mut(); - inner.status = SessionStatus::Changed; - inner.state.clear() + if inner.status != SessionStatus::Purged { + inner.status = SessionStatus::Changed; + inner.state.clear() + } } /// Removes session, both client and server side. @@ -161,7 +167,9 @@ impl Session { /// Renews the session key, assigning existing session state to new key. pub fn renew(&self) { let mut inner = self.0.borrow_mut(); - inner.status = SessionStatus::Renewed; + if inner.status != SessionStatus::Purged { + inner.status = SessionStatus::Renewed; + } } pub fn set_session(