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] [package]
name = "ntex-cors" name = "ntex-cors"
version = "0.3.0" version = "0.4.0"
authors = ["ntex contributors <team@ntex.rs>"] authors = ["ntex contributors <team@ntex.rs>"]
description = "Cross-origin resource sharing (CORS) for ntex applications." description = "Cross-origin resource sharing (CORS) for ntex applications."
readme = "README.md" readme = "README.md"
@ -16,9 +16,9 @@ name = "ntex_cors"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
ntex = "0.6.5" ntex = "0.7.0-beta.1"
derive_more = "0.99" derive_more = "0.99"
futures = "0.3" futures = "0.3"
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.5", features=["tokio"] } ntex = { version = "0.7.0-beta.1", features=["tokio"] }

View file

@ -54,7 +54,7 @@ use derive_more::Display;
use futures::future::{ok, Either, FutureExt, LocalBoxFuture, Ready}; use futures::future::{ok, Either, FutureExt, LocalBoxFuture, Ready};
use ntex::http::header::{self, HeaderName, HeaderValue}; use ntex::http::header::{self, HeaderName, HeaderValue};
use ntex::http::{error::HttpError, HeaderMap, Method, RequestHead, StatusCode, Uri}; use ntex::http::{error::HttpError, HeaderMap, Method, RequestHead, StatusCode, Uri};
use ntex::service::{Middleware, Service}; use ntex::service::{Middleware, Service, ServiceCtx};
use ntex::web::{ use ntex::web::{
DefaultError, ErrorRenderer, HttpResponse, WebRequest, WebResponse, WebResponseError, DefaultError, ErrorRenderer, HttpResponse, WebRequest, WebResponse, WebResponseError,
}; };
@ -760,18 +760,17 @@ where
self.service.poll_shutdown(cx) self.service.poll_shutdown(cx)
} }
fn call(&self, req: WebRequest<Err>) -> Self::Future<'_> { fn call<'a>(&'a self, req: WebRequest<Err>, ctx: ServiceCtx<'a, Self>) -> Self::Future<'a> {
match self.inner.preflight_check(req.head()) { match self.inner.preflight_check(req.head()) {
Ok(Either::Left(res)) => Either::Left(ok(req.into_response(res))), Ok(Either::Left(res)) => Either::Left(ok(req.into_response(res))),
Ok(Either::Right(_)) => { Ok(Either::Right(_)) => {
let inner = self.inner.clone(); let inner = self.inner.clone();
let has_origin = req.headers().contains_key(&header::ORIGIN); let has_origin = req.headers().contains_key(&header::ORIGIN);
let allowed_origin = inner.access_control_allow_origin(req.headers()); let allowed_origin = inner.access_control_allow_origin(req.headers());
let fut = self.service.call(req);
Either::Right( Either::Right(
async move { async move {
let mut res = fut.await?; let mut res = ctx.call(&self.service, req).await?;
if has_origin { if has_origin {
inner.handle_response(res.headers_mut(), allowed_origin); inner.handle_response(res.headers_mut(), allowed_origin);

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ntex-files" name = "ntex-files"
version = "0.2.2" version = "0.3.0"
authors = ["ntex contributors <team@ntex.rs>"] authors = ["ntex contributors <team@ntex.rs>"]
description = "Static files support for ntex web." description = "Static files support for ntex web."
readme = "README.md" readme = "README.md"
@ -18,7 +18,7 @@ name = "ntex_files"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
ntex = "0.6.5" ntex = "0.7.0-beta.1"
ntex-http = "0.1.8" ntex-http = "0.1.8"
bitflags = "2.1" bitflags = "2.1"
futures = "0.3" futures = "0.3"
@ -34,4 +34,4 @@ language-tags = "0.3.2"
httpdate = "1.0.2" httpdate = "1.0.2"
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.5", features = ["tokio", "openssl", "compress"] } ntex = { version = "0.7.0-beta.1", features = ["tokio", "openssl", "compress"] }

View file

@ -14,7 +14,7 @@ use ntex::http::error::BlockingError;
use ntex::http::{header, Method, Payload, Uri}; use ntex::http::{header, Method, Payload, Uri};
use ntex::router::{ResourceDef, ResourcePath}; use ntex::router::{ResourceDef, ResourcePath};
use ntex::service::boxed::{self, BoxService, BoxServiceFactory}; 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::util::Bytes;
use ntex::web::dev::{WebServiceConfig, WebServiceFactory}; use ntex::web::dev::{WebServiceConfig, WebServiceFactory};
use ntex::web::error::ErrorRenderer; use ntex::web::error::ErrorRenderer;
@ -452,17 +452,18 @@ impl<Err: ErrorRenderer> FilesService<Err>
where where
Err::Container: From<FilesError>, Err::Container: From<FilesError>,
{ {
fn handle_io_error( fn handle_io_error<'a>(
&self, &'a self,
e: io::Error, e: io::Error,
req: WebRequest<Err>, req: WebRequest<Err>,
ctx: ServiceCtx<'a, Self>,
) -> Either< ) -> Either<
Ready<Result<WebResponse, Err::Container>>, Ready<Result<WebResponse, Err::Container>>,
LocalBoxFuture<'_, Result<WebResponse, Err::Container>>, ServiceCall<'a, HttpService<Err>, WebRequest<Err>>,
> { > {
log::debug!("Files: Failed to handle {}: {}", req.path(), e); log::debug!("Files: Failed to handle {}: {}", req.path(), e);
if let Some(ref default) = self.default { if let Some(ref default) = self.default {
Either::Right(default.call(req)) Either::Right(ctx.call(default, req))
} else { } else {
Either::Left(ok(req.error_response(FilesError::from(e)))) Either::Left(ok(req.error_response(FilesError::from(e))))
} }
@ -478,10 +479,10 @@ where
type Error = Err::Container; type Error = Err::Container;
type Future<'f> = Either< type Future<'f> = Either<
Ready<Result<Self::Response, Self::Error>>, Ready<Result<Self::Response, Self::Error>>,
LocalBoxFuture<'f, Result<Self::Response, Self::Error>>, ServiceCall<'f, HttpService<Err>, WebRequest<Err>>,
>; >;
fn call(&self, req: WebRequest<Err>) -> Self::Future<'_> { fn call<'a>(&'a self, req: WebRequest<Err>, ctx: ServiceCtx<'a, Self>) -> Self::Future<'a> {
let is_method_valid = if let Some(guard) = &self.guards { let is_method_valid = if let Some(guard) = &self.guards {
// execute user defined guards // execute user defined guards
(**guard).check(req.head()) (**guard).check(req.head())
@ -502,7 +503,7 @@ where
// full filepath // full filepath
let path = match self.directory.join(real_path.0).canonicalize() { let path = match self.directory.join(real_path.0).canonicalize() {
Ok(path) => path, 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() { if path.is_dir() {
@ -531,7 +532,7 @@ where
let (req, _) = req.into_parts(); let (req, _) = req.into_parts();
Either::Left(ok(WebResponse::new(named_file.into_response(&req), req))) 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 { } else if self.show_index {
let dir = Directory::new(self.directory.clone(), path); let dir = Directory::new(self.directory.clone(), path);
@ -562,7 +563,7 @@ where
let (req, _) = req.into_parts(); let (req, _) = req.into_parts();
Either::Left(ok(WebResponse::new(named_file.into_response(&req), req))) 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),
} }
} }
} }

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ntex-identity" name = "ntex-identity"
version = "0.2.0" version = "0.3.0"
authors = ["ntex contributors <team@ntex.rs>"] authors = ["ntex contributors <team@ntex.rs>"]
description = "Identity service for ntex web framework." description = "Identity service for ntex web framework."
readme = "README.md" readme = "README.md"
@ -21,7 +21,7 @@ default = ["cookie-policy"]
cookie-policy = ["cookie/secure", "ntex/cookie"] cookie-policy = ["cookie/secure", "ntex/cookie"]
[dependencies] [dependencies]
ntex = "0.6.5" ntex = "0.7.0-beta.1"
futures = "0.3" futures = "0.3"
serde = "1.0" serde = "1.0"
serde_json = "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"] } time = { version = "0.3", default-features = false, features = ["std"] }
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.5", features=["tokio"] } ntex = { version = "0.7.0-beta.1", features=["tokio"] }

View file

@ -54,10 +54,9 @@ use futures::future::{ok, FutureExt, LocalBoxFuture, Ready};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use time::Duration; use time::Duration;
use ntex::http::error::HttpError;
use ntex::http::header::{self, HeaderValue}; use ntex::http::header::{self, HeaderValue};
use ntex::http::{HttpMessage, Payload}; use ntex::http::{error::HttpError, HttpMessage, Payload};
use ntex::service::{Middleware, Service}; use ntex::service::{Middleware, Service, ServiceCtx};
use ntex::util::Extensions; use ntex::util::Extensions;
use ntex::web::{ use ntex::web::{
DefaultError, ErrorRenderer, FromRequest, HttpRequest, WebRequest, WebResponse, DefaultError, ErrorRenderer, FromRequest, HttpRequest, WebRequest, WebResponse,
@ -224,17 +223,17 @@ impl<S, T> Middleware<S> for IdentityService<T> {
type Service = IdentityServiceMiddleware<S, T>; type Service = IdentityServiceMiddleware<S, T>;
fn create(&self, service: S) -> Self::Service { fn create(&self, service: S) -> Self::Service {
IdentityServiceMiddleware { backend: self.backend.clone(), service: Rc::new(service) } IdentityServiceMiddleware { service, backend: self.backend.clone() }
} }
} }
#[doc(hidden)] #[doc(hidden)]
pub struct IdentityServiceMiddleware<S, T> { pub struct IdentityServiceMiddleware<S, T> {
backend: Rc<T>, backend: Rc<T>,
service: Rc<S>, service: S,
} }
impl<S, T> Clone for IdentityServiceMiddleware<S, T> { impl<S: Clone, T> Clone for IdentityServiceMiddleware<S, T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { backend: self.backend.clone(), service: self.service.clone() } Self { backend: self.backend.clone(), service: self.service.clone() }
} }
@ -260,23 +259,22 @@ where
self.service.poll_shutdown(cx) self.service.poll_shutdown(cx)
} }
fn call(&self, mut req: WebRequest<Err>) -> Self::Future<'_> { fn call<'a>(
let srv = self.service.clone(); &'a self,
let backend = self.backend.clone(); mut req: WebRequest<Err>,
let fut = self.backend.from_request(&mut req); ctx: ServiceCtx<'a, Self>,
) -> Self::Future<'a> {
async move { async move {
match fut.await { match self.backend.from_request(&mut req).await {
Ok(id) => { Ok(id) => {
req.extensions_mut().insert(IdentityItem { id, changed: false }); req.extensions_mut().insert(IdentityItem { id, changed: false });
// https://github.com/actix/actix-web/issues/1263 // https://github.com/actix/actix-web/issues/1263
let fut = { srv.call(req) }; let mut res = ctx.call(&self.service, req).await?;
let mut res = fut.await?;
let id = res.request().extensions_mut().remove::<IdentityItem>(); let id = res.request().extensions_mut().remove::<IdentityItem>();
if let Some(id) = id { 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), Ok(_) => Ok(res),
Err(e) => Ok(WebResponse::error_response::<Err, _>(res, e)), Err(e) => Ok(WebResponse::error_response::<Err, _>(res, e)),
} }

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ntex-multipart" name = "ntex-multipart"
version = "0.2.0" version = "0.3.0"
authors = ["ntex contributors <team@ntex.rs>"] authors = ["ntex contributors <team@ntex.rs>"]
description = "Multipart support for ntex web framework." description = "Multipart support for ntex web framework."
readme = "README.md" readme = "README.md"
@ -16,7 +16,7 @@ name = "ntex_multipart"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
ntex = "0.6.5" ntex = "0.7.0-beta.1"
derive_more = "0.99" derive_more = "0.99"
httparse = "1.3" httparse = "1.3"
futures = "0.3" futures = "0.3"
@ -25,4 +25,4 @@ mime = "0.3"
twoway = "0.2" twoway = "0.2"
[dev-dependencies] [dev-dependencies]
ntex = { version = "0.6.5", features=["tokio"] } ntex = { version = "0.7.0-beta.1", features=["tokio"] }

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ntex-session" name = "ntex-session"
version = "0.2.0" version = "0.3.0"
authors = ["ntex contributors <team@ntex.rs>"] authors = ["ntex contributors <team@ntex.rs>"]
description = "Session for ntex web framework." description = "Session for ntex web framework."
readme = "README.md" readme = "README.md"
@ -22,7 +22,7 @@ default = ["cookie-session"]
cookie-session = ["cookie/secure", "ntex/cookie"] cookie-session = ["cookie/secure", "ntex/cookie"]
[dependencies] [dependencies]
ntex = "0.6.5" ntex = "0.7.0-beta.1"
cookie = "0.17" cookie = "0.17"
derive_more = "0.99" derive_more = "0.99"
futures = "0.3" futures = "0.3"
@ -31,4 +31,4 @@ serde_json = "1.0"
time = { version = "0.3", default-features = false, features = ["std"] } time = { version = "0.3", default-features = false, features = ["std"] }
[dev-dependencies] [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 derive_more::{Display, From};
use futures::future::{FutureExt, LocalBoxFuture}; use futures::future::{FutureExt, LocalBoxFuture};
use ntex::http::{header::HeaderValue, header::SET_COOKIE, HttpMessage}; 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 ntex::web::{DefaultError, ErrorRenderer, WebRequest, WebResponse, WebResponseError};
use serde_json::error::Error as JsonError; use serde_json::error::Error as JsonError;
use time::{Duration, OffsetDateTime}; use time::{Duration, OffsetDateTime};
@ -316,16 +316,14 @@ where
/// session state changes, then set-cookie is returned in response. As /// session state changes, then set-cookie is returned in response. As
/// a user logs out, call session.purge() to set SessionStatus accordingly /// a user logs out, call session.purge() to set SessionStatus accordingly
/// and this will trigger removal of the session cookie in the response. /// 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 inner = self.inner.clone();
let (is_new, state) = self.inner.load(&req); let (is_new, state) = self.inner.load(&req);
let prolong_expiration = self.inner.expires_in.is_some(); let prolong_expiration = self.inner.expires_in.is_some();
Session::set_session(state.into_iter(), &req); Session::set_session(state.into_iter(), &req);
let fut = self.service.call(req);
async move { async move {
fut.await.map(|mut res| { ctx.call(&self.service, req).await.map(|mut res| {
match Session::get_changes(&mut res) { match Session::get_changes(&mut res) {
(SessionStatus::Changed, Some(state)) (SessionStatus::Changed, Some(state))
| (SessionStatus::Renewed, Some(state)) => { | (SessionStatus::Renewed, Some(state)) => {