2022-03-05 23:22:14 +00:00
|
|
|
use actix_web::{
|
|
|
|
dev::{ServiceRequest, ServiceResponse},
|
2022-03-25 18:25:38 +00:00
|
|
|
guard::GuardContext,
|
2022-03-05 23:22:14 +00:00
|
|
|
HttpMessage, HttpRequest,
|
|
|
|
};
|
|
|
|
|
|
|
|
use crate::Session;
|
|
|
|
|
|
|
|
/// Extract a [`Session`] object from various `actix-web` types (e.g. `HttpRequest`,
|
|
|
|
/// `ServiceRequest`, `ServiceResponse`).
|
|
|
|
pub trait SessionExt {
|
|
|
|
/// Extract a [`Session`] object.
|
|
|
|
fn get_session(&self) -> Session;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SessionExt for HttpRequest {
|
|
|
|
fn get_session(&self) -> Session {
|
2022-09-25 21:08:34 +01:00
|
|
|
Session::get_session(&mut self.extensions_mut())
|
2022-03-05 23:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SessionExt for ServiceRequest {
|
|
|
|
fn get_session(&self) -> Session {
|
2022-09-25 21:08:34 +01:00
|
|
|
Session::get_session(&mut self.extensions_mut())
|
2022-03-05 23:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SessionExt for ServiceResponse {
|
|
|
|
fn get_session(&self) -> Session {
|
|
|
|
self.request().get_session()
|
|
|
|
}
|
|
|
|
}
|
2022-03-25 18:25:38 +00:00
|
|
|
|
|
|
|
impl<'a> SessionExt for GuardContext<'a> {
|
|
|
|
fn get_session(&self) -> Session {
|
2022-09-25 21:08:34 +01:00
|
|
|
Session::get_session(&mut self.req_data_mut())
|
2022-03-25 18:25:38 +00:00
|
|
|
}
|
|
|
|
}
|