-
SummaryI am using the PrivateCookieJar extractor from Is there a way to update cookies within a From the docs:
Example of what I am trying to achieve: #[async_trait]
impl<S> FromRequestParts<S> for Session
where
S: Send + Sync,
Key: FromRef<S>,
{
type Rejection = ();
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let cookie_jar = PrivateCookieJar::<Key>::from_request_parts(parts, state)
.await
.unwrap();
let cookie = cookie_jar.get("session").unwrap();
// Look for session and extend its expiration time
let session = Session::find_and_extend(cookie.value()).await.unwrap();
// Pass new expiration time to cookie
let updated_jar = cookie_jar.add(Cookie::build(cookie).expires(session.expires));
// How to propagate the updated cookie jar?
Ok(session)
}
} axum version0.7.9 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
AFAIK the short answer is: no the longer answer is: you can use a middleware roughly like https://github.com/rust-lang/crates.io/blob/bb0b971b2fe1474849f109bffd93b2fbfb2862c0/crates/crates_io_session/src/lib.rs#L44-L72 |
Beta Was this translation helpful? Give feedback.
AFAIK the short answer is: no
the longer answer is: you can use a middleware roughly like https://github.com/rust-lang/crates.io/blob/bb0b971b2fe1474849f109bffd93b2fbfb2862c0/crates/crates_io_session/src/lib.rs#L44-L72