diff --git a/ntex-cors/Cargo.toml b/ntex-cors/Cargo.toml index 169d31f0..4b2337c5 100644 --- a/ntex-cors/Cargo.toml +++ b/ntex-cors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-cors" -version = "0.3.0" +version = "0.4.0" authors = ["ntex contributors "] description = "Cross-origin resource sharing (CORS) for ntex applications." readme = "README.md" @@ -16,9 +16,9 @@ name = "ntex_cors" path = "src/lib.rs" [dependencies] -ntex = "0.6.5" +ntex = "0.7.0-beta.1" derive_more = "0.99" futures = "0.3" [dev-dependencies] -ntex = { version = "0.6.5", features=["tokio"] } +ntex = { version = "0.7.0-beta.1", features=["tokio"] } diff --git a/ntex-cors/src/lib.rs b/ntex-cors/src/lib.rs index 1035c73f..a0b6d72d 100644 --- a/ntex-cors/src/lib.rs +++ b/ntex-cors/src/lib.rs @@ -54,7 +54,7 @@ use derive_more::Display; use futures::future::{ok, Either, FutureExt, LocalBoxFuture, Ready}; use ntex::http::header::{self, HeaderName, HeaderValue}; use ntex::http::{error::HttpError, HeaderMap, Method, RequestHead, StatusCode, Uri}; -use ntex::service::{Middleware, Service}; +use ntex::service::{Middleware, Service, ServiceCtx}; use ntex::web::{ DefaultError, ErrorRenderer, HttpResponse, WebRequest, WebResponse, WebResponseError, }; @@ -760,18 +760,17 @@ where self.service.poll_shutdown(cx) } - fn call(&self, req: WebRequest) -> Self::Future<'_> { + fn call<'a>(&'a self, req: WebRequest, ctx: ServiceCtx<'a, Self>) -> Self::Future<'a> { match self.inner.preflight_check(req.head()) { Ok(Either::Left(res)) => Either::Left(ok(req.into_response(res))), Ok(Either::Right(_)) => { let inner = self.inner.clone(); let has_origin = req.headers().contains_key(&header::ORIGIN); let allowed_origin = inner.access_control_allow_origin(req.headers()); - let fut = self.service.call(req); Either::Right( async move { - let mut res = fut.await?; + let mut res = ctx.call(&self.service, req).await?; if has_origin { inner.handle_response(res.headers_mut(), allowed_origin); diff --git a/ntex-files/Cargo.toml b/ntex-files/Cargo.toml index f7f14bfe..f74fea63 100644 --- a/ntex-files/Cargo.toml +++ b/ntex-files/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-files" -version = "0.2.2" +version = "0.3.0" authors = ["ntex contributors "] description = "Static files support for ntex web." readme = "README.md" @@ -18,7 +18,7 @@ name = "ntex_files" path = "src/lib.rs" [dependencies] -ntex = "0.6.5" +ntex = "0.7.0-beta.1" ntex-http = "0.1.8" bitflags = "2.1" futures = "0.3" @@ -34,4 +34,4 @@ language-tags = "0.3.2" httpdate = "1.0.2" [dev-dependencies] -ntex = { version = "0.6.5", features = ["tokio", "openssl", "compress"] } +ntex = { version = "0.7.0-beta.1", features = ["tokio", "openssl", "compress"] } diff --git a/ntex-files/src/lib.rs b/ntex-files/src/lib.rs index b78238f1..6bdecdea 100644 --- a/ntex-files/src/lib.rs +++ b/ntex-files/src/lib.rs @@ -14,7 +14,7 @@ use ntex::http::error::BlockingError; use ntex::http::{header, Method, Payload, Uri}; use ntex::router::{ResourceDef, ResourcePath}; use ntex::service::boxed::{self, BoxService, BoxServiceFactory}; -use ntex::service::{IntoServiceFactory, Service, ServiceFactory}; +use ntex::service::{IntoServiceFactory, Service, ServiceCall, ServiceCtx, ServiceFactory}; use ntex::util::Bytes; use ntex::web::dev::{WebServiceConfig, WebServiceFactory}; use ntex::web::error::ErrorRenderer; @@ -452,17 +452,18 @@ impl FilesService where Err::Container: From, { - fn handle_io_error( - &self, + fn handle_io_error<'a>( + &'a self, e: io::Error, req: WebRequest, + ctx: ServiceCtx<'a, Self>, ) -> Either< Ready>, - LocalBoxFuture<'_, Result>, + ServiceCall<'a, HttpService, WebRequest>, > { log::debug!("Files: Failed to handle {}: {}", req.path(), e); if let Some(ref default) = self.default { - Either::Right(default.call(req)) + Either::Right(ctx.call(default, req)) } else { Either::Left(ok(req.error_response(FilesError::from(e)))) } @@ -478,10 +479,10 @@ where type Error = Err::Container; type Future<'f> = Either< Ready>, - LocalBoxFuture<'f, Result>, + ServiceCall<'f, HttpService, WebRequest>, >; - fn call(&self, req: WebRequest) -> Self::Future<'_> { + fn call<'a>(&'a self, req: WebRequest, ctx: ServiceCtx<'a, Self>) -> Self::Future<'a> { let is_method_valid = if let Some(guard) = &self.guards { // execute user defined guards (**guard).check(req.head()) @@ -502,7 +503,7 @@ where // full filepath let path = match self.directory.join(real_path.0).canonicalize() { Ok(path) => path, - Err(e) => return self.handle_io_error(e, req), + Err(e) => return self.handle_io_error(e, req, ctx), }; if path.is_dir() { @@ -531,7 +532,7 @@ where let (req, _) = req.into_parts(); Either::Left(ok(WebResponse::new(named_file.into_response(&req), req))) } - Err(e) => self.handle_io_error(e, req), + Err(e) => self.handle_io_error(e, req, ctx), } } else if self.show_index { let dir = Directory::new(self.directory.clone(), path); @@ -562,7 +563,7 @@ where let (req, _) = req.into_parts(); Either::Left(ok(WebResponse::new(named_file.into_response(&req), req))) } - Err(e) => self.handle_io_error(e, req), + Err(e) => self.handle_io_error(e, req, ctx), } } } diff --git a/ntex-identity/Cargo.toml b/ntex-identity/Cargo.toml index 22a3afa3..f09af98b 100644 --- a/ntex-identity/Cargo.toml +++ b/ntex-identity/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-identity" -version = "0.2.0" +version = "0.3.0" authors = ["ntex contributors "] description = "Identity service for ntex web framework." readme = "README.md" @@ -21,7 +21,7 @@ default = ["cookie-policy"] cookie-policy = ["cookie/secure", "ntex/cookie"] [dependencies] -ntex = "0.6.5" +ntex = "0.7.0-beta.1" futures = "0.3" serde = "1.0" serde_json = "1.0" @@ -30,4 +30,4 @@ cookie = { version = "0.17", features = ["private"] } 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"] } diff --git a/ntex-identity/src/lib.rs b/ntex-identity/src/lib.rs index 93f4dea5..6a16bf90 100644 --- a/ntex-identity/src/lib.rs +++ b/ntex-identity/src/lib.rs @@ -54,10 +54,9 @@ use futures::future::{ok, FutureExt, LocalBoxFuture, Ready}; use serde::{Deserialize, Serialize}; use time::Duration; -use ntex::http::error::HttpError; use ntex::http::header::{self, HeaderValue}; -use ntex::http::{HttpMessage, Payload}; -use ntex::service::{Middleware, Service}; +use ntex::http::{error::HttpError, HttpMessage, Payload}; +use ntex::service::{Middleware, Service, ServiceCtx}; use ntex::util::Extensions; use ntex::web::{ DefaultError, ErrorRenderer, FromRequest, HttpRequest, WebRequest, WebResponse, @@ -224,17 +223,17 @@ impl Middleware for IdentityService { type Service = IdentityServiceMiddleware; fn create(&self, service: S) -> Self::Service { - IdentityServiceMiddleware { backend: self.backend.clone(), service: Rc::new(service) } + IdentityServiceMiddleware { service, backend: self.backend.clone() } } } #[doc(hidden)] pub struct IdentityServiceMiddleware { backend: Rc, - service: Rc, + service: S, } -impl Clone for IdentityServiceMiddleware { +impl Clone for IdentityServiceMiddleware { fn clone(&self) -> Self { Self { backend: self.backend.clone(), service: self.service.clone() } } @@ -260,23 +259,22 @@ where self.service.poll_shutdown(cx) } - fn call(&self, mut req: WebRequest) -> Self::Future<'_> { - let srv = self.service.clone(); - let backend = self.backend.clone(); - let fut = self.backend.from_request(&mut req); - + fn call<'a>( + &'a self, + mut req: WebRequest, + ctx: ServiceCtx<'a, Self>, + ) -> Self::Future<'a> { async move { - match fut.await { + match self.backend.from_request(&mut req).await { Ok(id) => { req.extensions_mut().insert(IdentityItem { id, changed: false }); // https://github.com/actix/actix-web/issues/1263 - let fut = { srv.call(req) }; - let mut res = fut.await?; + let mut res = ctx.call(&self.service, req).await?; let id = res.request().extensions_mut().remove::(); if let Some(id) = id { - match backend.to_response(id.id, id.changed, &mut res).await { + match self.backend.to_response(id.id, id.changed, &mut res).await { Ok(_) => Ok(res), Err(e) => Ok(WebResponse::error_response::(res, e)), } diff --git a/ntex-multipart/Cargo.toml b/ntex-multipart/Cargo.toml index c3fde52f..45ba2e11 100644 --- a/ntex-multipart/Cargo.toml +++ b/ntex-multipart/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-multipart" -version = "0.2.0" +version = "0.3.0" authors = ["ntex contributors "] description = "Multipart support for ntex web framework." readme = "README.md" @@ -16,7 +16,7 @@ name = "ntex_multipart" path = "src/lib.rs" [dependencies] -ntex = "0.6.5" +ntex = "0.7.0-beta.1" derive_more = "0.99" httparse = "1.3" futures = "0.3" @@ -25,4 +25,4 @@ mime = "0.3" twoway = "0.2" [dev-dependencies] -ntex = { version = "0.6.5", features=["tokio"] } +ntex = { version = "0.7.0-beta.1", features=["tokio"] } diff --git a/ntex-session/Cargo.toml b/ntex-session/Cargo.toml index 74a38344..3109fb89 100644 --- a/ntex-session/Cargo.toml +++ b/ntex-session/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-session" -version = "0.2.0" +version = "0.3.0" authors = ["ntex contributors "] 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"] } diff --git a/ntex-session/src/cookie.rs b/ntex-session/src/cookie.rs index b8329931..8fe53096 100644 --- a/ntex-session/src/cookie.rs +++ b/ntex-session/src/cookie.rs @@ -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) -> Self::Future<'_> { + fn call<'a>(&'a self, req: WebRequest, 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)) => {