Upgrade to ntex-0.7

This commit is contained in:
Nikolay Kim 2023-06-19 20:00:40 +06:00
parent c7f1ba1d48
commit fe130477bf
9 changed files with 45 additions and 49 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "ntex-session"
version = "0.2.0"
version = "0.3.0"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Session for ntex web framework."
readme = "README.md"
@ -22,7 +22,7 @@ default = ["cookie-session"]
cookie-session = ["cookie/secure", "ntex/cookie"]
[dependencies]
ntex = "0.6.5"
ntex = "0.7.0-beta.1"
cookie = "0.17"
derive_more = "0.99"
futures = "0.3"
@ -31,4 +31,4 @@ serde_json = "1.0"
time = { version = "0.3", default-features = false, features = ["std"] }
[dev-dependencies]
ntex = { version = "0.6.5", features=["tokio"] }
ntex = { version = "0.7.0-beta.1", features=["tokio"] }

View file

@ -22,7 +22,7 @@ use cookie::{Cookie, CookieJar, Key, SameSite};
use derive_more::{Display, From};
use futures::future::{FutureExt, LocalBoxFuture};
use ntex::http::{header::HeaderValue, header::SET_COOKIE, HttpMessage};
use ntex::service::{Middleware, Service};
use ntex::service::{Middleware, Service, ServiceCtx};
use ntex::web::{DefaultError, ErrorRenderer, WebRequest, WebResponse, WebResponseError};
use serde_json::error::Error as JsonError;
use time::{Duration, OffsetDateTime};
@ -316,16 +316,14 @@ where
/// 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, req: WebRequest<Err>) -> Self::Future<'_> {
fn call<'a>(&'a self, req: WebRequest<Err>, ctx: ServiceCtx<'a, Self>) -> Self::Future<'a> {
let inner = self.inner.clone();
let (is_new, state) = self.inner.load(&req);
let prolong_expiration = self.inner.expires_in.is_some();
Session::set_session(state.into_iter(), &req);
let fut = self.service.call(req);
async move {
fut.await.map(|mut res| {
ctx.call(&self.service, req).await.map(|mut res| {
match Session::get_changes(&mut res) {
(SessionStatus::Changed, Some(state))
| (SessionStatus::Renewed, Some(state)) => {