Skip to main content

tower_sessions_core/
extract.rs

1use axum_core::extract::FromRequestParts;
2use http::{request::Parts, StatusCode};
3
4use crate::session::Session;
5
6impl<S> FromRequestParts<S> for Session
7where
8    S: Sync + Send,
9{
10    type Rejection = (http::StatusCode, &'static str);
11
12    async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
13        parts.extensions.get::<Session>().cloned().ok_or((
14            StatusCode::INTERNAL_SERVER_ERROR,
15            "Can't extract session. Is `SessionManagerLayer` enabled?",
16        ))
17    }
18}