fn call(&self, mut req: ServiceRequest) -> Self::Future {
        let cookie = self.cookie.clone();
        let (is_new, state) = self.cookie.load(&req);
        let prolong_expiration = self.cookie.expires_in.is_some();
        Session::set_session(&mut req, state);

        let fut = self.service.call(req);

        async move {
            let mut res = fut.await?;

            let result = match Session::get_changes(&mut res) {
                (SessionStatus::Changed, id) | (SessionStatus::Renewed, id) => {
                    cookie.set_cookie(&mut res, id)
                }

                (SessionStatus::Unchanged, id) if prolong_expiration => {
                    cookie.set_cookie(&mut res, id)
                }

                // set a new session cookie upon first request (new client)
                (SessionStatus::Unchanged, _) => {
                    if is_new {
                        let id = get_random(DEFAULT_SESSION_ID_LEN);
                        cookie.set_cookie(&mut res, id)
                    } else {
                        Ok(())
                    }
                }

                (SessionStatus::Purged, _) => {
                    let _ = cookie.remove_cookie(&mut res);
                    Ok(())
                }
            };

            match result {
                Ok(()) => Ok(res.map_body(|_, body| AnyBody::from_message(body))),
                Err(error) => Ok(res.error_response(error)),
            }
        }
        .boxed_local()
    }
/// On first request, a new session cookie is returned in response, regardless
/// of whether any session state is set.  With subsequent requests, if the
/// session state changes, then set-cookie is returned in response.  As
/// a user logs out, call session.purge() to set SessionStatus accordingly
/// and this will trigger removal of the session cookie in the response.
On first request, a new session cookie is returned in response, regardless
of whether any session state is set.  With subsequent requests, if the
session state changes, then set-cookie is returned in response.  As
a user logs out, call session.purge() to set SessionStatus accordingly
and this will trigger removal of the session cookie in the response.
On first request a new session cookie is returned in response regardless of whether any session state is set . With subsequent requests if the session state changes then set - cookie is returned in response . As a user logs out call session . purge () to set SessionStatus accordingly and this will trigger removal of the session cookie in the response .
fn call(&self, mut req: ServiceRequest) -> Self::Future {
        let cookie = self.cookie.clone();
        let (is_new, state) = self.cookie.load(&req);
        let prolong_expiration = self.cookie.expires_in.is_some();
        Session::set_session(&mut req, state);
        let fut = self.service.call(req);
        async move {
            let mut res = fut.await?;
            let result = match Session::get_changes(&mut res) {
                (SessionStatus::Changed, id) | (SessionStatus::Renewed, id) => {
                    cookie.set_cookie(&mut res, id)
                }
                (SessionStatus::Unchanged, id) if prolong_expiration => {
                    cookie.set_cookie(&mut res, id)
                }
                // set a new session cookie upon first request (new client)
                (SessionStatus::Unchanged, _) => {
                    if is_new {
                        let id = get_random(DEFAULT_SESSION_ID_LEN);
                        cookie.set_cookie(&mut res, id)
                    } else {
                        Ok(())
                    }
                }
                (SessionStatus::Purged, _) => {
                    let _ = cookie.remove_cookie(&mut res);
                    Ok(())
                }
            };
            match result {
                Ok(()) => Ok(res.map_body(|_, body| AnyBody::from_message(body))),
                Err(error) => Ok(res.error_response(error)),
            }
        }
        .boxed_local()
    }
fn call ( & self , mut req : ServiceRequest ) -> Self :: Future { let cookie = self . cookie . clone ( ) ; let ( is_new , state ) = self . cookie . load ( & req ) ; let prolong_expiration = self . cookie . expires_in . is_some ( ) ; Session :: set_session ( & mut req , state ) ; let fut = self . service . call ( req ) ; async move { let mut res = fut . await ? ; let result = match Session :: get_changes ( & mut res ) { ( SessionStatus :: Changed , id ) | ( SessionStatus :: Renewed , id ) => { cookie . set_cookie ( & mut res , id ) } ( SessionStatus :: Unchanged , id ) if prolong_expiration => { cookie . set_cookie ( & mut res , id ) } // set a new session cookie upon first request (new client) ( SessionStatus :: Unchanged , _ ) => { if is_new { let id = get_random ( DEFAULT_SESSION_ID_LEN ) ; cookie . set_cookie ( & mut res , id ) } else { Ok ( ( ) ) } } ( SessionStatus :: Purged , _ ) => { let _ = cookie . remove_cookie ( & mut res ) ; Ok ( ( ) ) } } ; match result { Ok ( ( ) ) => Ok ( res . map_body ( | _ , body | AnyBody :: from_message ( body ) ) ) , Err ( error ) => Ok ( res . error_response ( error ) ) , } } . boxed_local ( ) }
On first request, a new session cookie is returned in response, regardless
of whether any session state is set.
On first request a new session cookie is returned in response regardless of whether any session state is set .
&self
req
ServiceRequest
&self
req
ServiceRequest