mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-31 02:52:53 +01:00
modified so as to consider unanticipated state changes
This commit is contained in:
parent
959eef05ae
commit
65732197b8
@ -130,26 +130,32 @@ impl Session {
|
|||||||
/// Set a `value` from the session.
|
/// Set a `value` from the session.
|
||||||
pub fn set<T: Serialize>(&self, key: &str, value: T) -> Result<(), Error> {
|
pub fn set<T: Serialize>(&self, key: &str, value: T) -> Result<(), Error> {
|
||||||
let mut inner = self.0.borrow_mut();
|
let mut inner = self.0.borrow_mut();
|
||||||
|
if inner.status != SessionStatus::Purged {
|
||||||
inner.status = SessionStatus::Changed;
|
inner.status = SessionStatus::Changed;
|
||||||
inner
|
inner
|
||||||
.state
|
.state
|
||||||
.insert(key.to_owned(), serde_json::to_string(&value)?);
|
.insert(key.to_owned(), serde_json::to_string(&value)?);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove value from the session.
|
/// Remove value from the session.
|
||||||
pub fn remove(&self, key: &str) {
|
pub fn remove(&self, key: &str) {
|
||||||
let mut inner = self.0.borrow_mut();
|
let mut inner = self.0.borrow_mut();
|
||||||
|
if inner.status != SessionStatus::Purged {
|
||||||
inner.status = SessionStatus::Changed;
|
inner.status = SessionStatus::Changed;
|
||||||
inner.state.remove(key);
|
inner.state.remove(key);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Clear the session.
|
/// Clear the session.
|
||||||
pub fn clear(&self) {
|
pub fn clear(&self) {
|
||||||
let mut inner = self.0.borrow_mut();
|
let mut inner = self.0.borrow_mut();
|
||||||
|
if inner.status != SessionStatus::Purged {
|
||||||
inner.status = SessionStatus::Changed;
|
inner.status = SessionStatus::Changed;
|
||||||
inner.state.clear()
|
inner.state.clear()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes session, both client and server side.
|
/// Removes session, both client and server side.
|
||||||
pub fn purge(&self) {
|
pub fn purge(&self) {
|
||||||
@ -161,8 +167,10 @@ impl Session {
|
|||||||
/// Renews the session key, assigning existing session state to new key.
|
/// Renews the session key, assigning existing session state to new key.
|
||||||
pub fn renew(&self) {
|
pub fn renew(&self) {
|
||||||
let mut inner = self.0.borrow_mut();
|
let mut inner = self.0.borrow_mut();
|
||||||
|
if inner.status != SessionStatus::Purged {
|
||||||
inner.status = SessionStatus::Renewed;
|
inner.status = SessionStatus::Renewed;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_session(
|
pub fn set_session(
|
||||||
data: impl Iterator<Item = (String, String)>,
|
data: impl Iterator<Item = (String, String)>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user