mirror of
https://github.com/ntex-rs/ntex-extras.git
synced 2025-04-03 21:07:40 +03:00
Upgrade to ntex-0.7
This commit is contained in:
parent
c7f1ba1d48
commit
fe130477bf
9 changed files with 45 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-cors"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
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"] }
|
||||
|
|
|
@ -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<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()) {
|
||||
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);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-files"
|
||||
version = "0.2.2"
|
||||
version = "0.3.0"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
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"] }
|
||||
|
|
|
@ -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<Err: ErrorRenderer> FilesService<Err>
|
|||
where
|
||||
Err::Container: From<FilesError>,
|
||||
{
|
||||
fn handle_io_error(
|
||||
&self,
|
||||
fn handle_io_error<'a>(
|
||||
&'a self,
|
||||
e: io::Error,
|
||||
req: WebRequest<Err>,
|
||||
ctx: ServiceCtx<'a, Self>,
|
||||
) -> Either<
|
||||
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);
|
||||
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<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 {
|
||||
// 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-identity"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
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"] }
|
||||
|
|
|
@ -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<S, T> Middleware<S> for IdentityService<T> {
|
|||
type Service = IdentityServiceMiddleware<S, T>;
|
||||
|
||||
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<S, 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 {
|
||||
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<Err>) -> 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<Err>,
|
||||
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::<IdentityItem>();
|
||||
|
||||
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::<Err, _>(res, e)),
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-multipart"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
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"] }
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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)) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue