This commit is contained in:
Darin 2018-07-31 16:07:15 +00:00 committed by GitHub
commit 7c293ef1af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -182,6 +182,14 @@ impl Session {
} }
} }
/// Renew the session (new key)
pub fn renew(&self) {
match self.0 {
SessionInner::Session(ref sess) => sess.as_ref().0.borrow_mut().renew(),
SessionInner::None => (),
}
}
/// Clear the session. /// Clear the session.
pub fn clear(&self) { pub fn clear(&self) {
match self.0 { match self.0 {
@ -278,10 +286,12 @@ pub trait SessionImpl: 'static {
fn remove(&mut self, key: &str); fn remove(&mut self, key: &str);
fn renew(&mut self);
fn clear(&mut self); fn clear(&mut self);
/// Write session to storage backend. /// Write session to storage backend.
fn write(&self, resp: HttpResponse) -> Result<Response>; fn write(&mut self, resp: HttpResponse) -> Result<Response>;
} }
/// Session's storage backend trait definition. /// Session's storage backend trait definition.
@ -338,7 +348,9 @@ impl SessionImpl for CookieSession {
self.state.clear() self.state.clear()
} }
fn write(&self, mut resp: HttpResponse) -> Result<Response> { fn renew(&mut self) {} // not relevant for cookie-based sessions
fn write(&mut self, mut resp: HttpResponse) -> Result<Response> {
if self.changed { if self.changed {
let _ = self.inner.set_cookie(&mut resp, &self.state); let _ = self.inner.set_cookie(&mut resp, &self.state);
} }