pub struct SessionMiddleware { /* private fields */ }Expand description
Session middleware
§Examples
use std::sync::Arc;
use std::time::Duration;
use reinhardt_middleware::session::{SessionMiddleware, SessionConfig};
use reinhardt_http::{Handler, Middleware, Request, Response};
use hyper::{StatusCode, Method, Version, HeaderMap};
use bytes::Bytes;
struct TestHandler;
#[async_trait::async_trait]
impl Handler for TestHandler {
async fn handle(&self, _request: Request) -> reinhardt_core::exception::Result<Response> {
Ok(Response::new(StatusCode::OK).with_body(Bytes::from("OK")))
}
}
let config = SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600));
let middleware = SessionMiddleware::new(config);
let handler = Arc::new(TestHandler);
let request = Request::builder()
.method(Method::GET)
.uri("/api/data")
.version(Version::HTTP_11)
.headers(HeaderMap::new())
.body(Bytes::new())
.build()
.unwrap();
let response = middleware.process(request, handler).await.unwrap();
assert_eq!(response.status, StatusCode::OK);Implementations§
Source§impl SessionMiddleware
impl SessionMiddleware
Sourcepub fn new(config: SessionConfig) -> Self
pub fn new(config: SessionConfig) -> Self
Create a new session middleware
§Examples
use std::time::Duration;
use reinhardt_middleware::session::{SessionMiddleware, SessionConfig};
let config = SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600));
let middleware = SessionMiddleware::new(config);Sourcepub fn from_settings(settings: &Settings) -> Self
pub fn from_settings(settings: &Settings) -> Self
Create a SessionMiddleware from application Settings
§Examples
use reinhardt_conf::Settings;
use reinhardt_middleware::session::SessionMiddleware;
#[allow(deprecated)]
let settings = Settings::default();
#[allow(deprecated)]
let middleware = SessionMiddleware::from_settings(&settings);Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create with default configuration
Sourcepub fn from_arc(config: SessionConfig, store: Arc<SessionStore>) -> Self
pub fn from_arc(config: SessionConfig, store: Arc<SessionStore>) -> Self
Create from an existing Arc-wrapped session store
This is provided for cases where you already have an Arc<SessionStore>.
In most cases, you should use new() instead, which creates the store internally.
Sourcepub fn store(&self) -> &SessionStore
pub fn store(&self) -> &SessionStore
Get a reference to the session store
§Examples
use std::time::Duration;
use reinhardt_middleware::session::{SessionMiddleware, SessionConfig};
let middleware = SessionMiddleware::new(
SessionConfig::new("sessionid".to_string(), Duration::from_secs(3600))
);
// Access the store
let store = middleware.store();
assert_eq!(store.len(), 0);Sourcepub fn store_arc(&self) -> Arc<SessionStore>
pub fn store_arc(&self) -> Arc<SessionStore>
Get a cloned Arc of the store (for cases where you need ownership)
In most cases, you should use store() instead to get a reference.
Trait Implementations§
Source§impl Default for SessionMiddleware
impl Default for SessionMiddleware
Source§impl Middleware for SessionMiddleware
impl Middleware for SessionMiddleware
Auto Trait Implementations§
impl Freeze for SessionMiddleware
impl RefUnwindSafe for SessionMiddleware
impl Send for SessionMiddleware
impl Sync for SessionMiddleware
impl Unpin for SessionMiddleware
impl UnsafeUnpin for SessionMiddleware
impl UnwindSafe for SessionMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().