1- use std:: { borrow:: Cow , collections :: HashMap , fmt, future:: Future , pin:: Pin , rc:: Rc , sync:: Arc } ;
1+ use std:: { borrow:: Cow , fmt, future:: Future , pin:: Pin , rc:: Rc , sync:: Arc } ;
22
33use actix_utils:: future:: { ready, Ready } ;
44use actix_web:: {
@@ -8,6 +8,7 @@ use actix_web::{
88 http:: header:: { HeaderValue , SET_COOKIE } ,
99 HttpResponse ,
1010} ;
11+ use serde_json:: { Map , Value } ;
1112
1213use super :: {
1314 config:: {
@@ -31,7 +32,8 @@ use crate::{memorydb::MemoryDB, Result};
3132/// Use [`SessionMiddleware::new`] to initialize the session framework using the default parameters.
3233/// To create a new instance of [`SessionMiddleware`] you need to provide:
3334///
34- /// - an instance of the session storage backend you wish to use (i.e. an implementation of SessionStore);
35+ /// - an instance of the session storage backend you wish to use (i.e. an implementation of
36+ /// [`SessionStore`]);
3537/// - a secret key, to sign or encrypt the content of client-side session cookie.
3638///
3739/// # How did we choose defaults?
@@ -53,7 +55,8 @@ impl SessionMiddleware {
5355 /// parameters.
5456 ///
5557 /// To create a new instance of [`SessionMiddleware`] you need to provide:
56- /// - an instance of the session storage backend you wish to use (i.e. an implementation of SessionStore);
58+ /// - an instance of the session storage backend you wish to use (i.e. an implementation of
59+ /// [`SessionStore`]);
5760 /// - a secret key, to sign or encrypt the content of client-side session cookie.
5861 pub fn new ( client : Arc < dyn MemoryDB > , key : Key ) -> Self {
5962 Self :: builder ( client, key) . build ( )
@@ -62,7 +65,8 @@ impl SessionMiddleware {
6265 /// A fluent API to configure [`SessionMiddleware`].
6366 ///
6467 /// It takes as input the two required inputs to create a new instance of [`SessionMiddleware`]:
65- /// - an instance of the session storage backend you wish to use (i.e. an implementation of SessionStore);
68+ /// - an instance of the session storage backend you wish to use (i.e. an implementation of
69+ /// [`SessionStore`]);
6670 /// - a secret key, to sign or encrypt the content of client-side session cookie.
6771 pub fn builder ( client : Arc < dyn MemoryDB > , key : Key ) -> SessionMiddlewareBuilder {
6872 SessionMiddlewareBuilder :: new ( client, config:: default_configuration ( key) )
@@ -151,7 +155,7 @@ where
151155 let mut ttl = configuration. session . state_ttl ;
152156 let mut cookie = Cow :: Borrowed ( & configuration. cookie ) ;
153157 if let Some ( x) = session_state. get ( "_ttl" ) {
154- if let Ok ( x) = x. parse ( ) {
158+ if let Some ( x) = x. as_i64 ( ) {
155159 ttl = Duration :: seconds ( x) ;
156160 let mut tmp = cookie. into_owned ( ) ;
157161 tmp. max_age = Some ( ttl) ;
@@ -160,7 +164,7 @@ where
160164 }
161165 let id = session_state
162166 . get ( "_id" )
163- . map ( |x| x. trim_matches ( '"' ) . to_owned ( ) ) ;
167+ . map ( |x| x. to_string ( ) . trim_matches ( '"' ) . to_owned ( ) ) ;
164168
165169 match session_key {
166170 None => {
@@ -268,7 +272,7 @@ fn extract_session_key(req: &ServiceRequest, config: &CookieConfiguration) -> Op
268272async fn load_session_state (
269273 session_key : Option < SessionKey > ,
270274 storage_backend : & SessionStore ,
271- ) -> Result < ( Option < SessionKey > , HashMap < String , String > ) , actix_web:: Error > {
275+ ) -> Result < ( Option < SessionKey > , Map < String , Value > ) , actix_web:: Error > {
272276 if let Some ( session_key) = session_key {
273277 match storage_backend. load ( & session_key) . await {
274278 Ok ( state) => {
@@ -281,14 +285,14 @@ async fn load_session_state(
281285 // instead of the `update` workflow if the session state is modified during the
282286 // lifecycle of the current request.
283287
284- Ok ( ( None , HashMap :: new ( ) ) )
288+ Ok ( ( None , Map :: new ( ) ) )
285289 }
286290 }
287291
288292 Err ( err) => Err ( e500 ( err) ) ,
289293 }
290294 } else {
291- Ok ( ( None , HashMap :: new ( ) ) )
295+ Ok ( ( None , Map :: new ( ) ) )
292296 }
293297}
294298
0 commit comments