update for ntex 0.4

This commit is contained in:
liaozhou 2021-11-02 10:32:34 +08:00
parent 74148e3ddf
commit 18eab8fb1a
10 changed files with 35 additions and 68 deletions

View file

@ -16,6 +16,6 @@ name = "ntex_cors"
path = "src/lib.rs"
[dependencies]
ntex = "0.3.18"
ntex = "0.4.6"
derive_more = "0.99.11"
futures = "0.3.13"

View file

@ -56,7 +56,7 @@ 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::{Service, Transform};
use ntex::web::dev::{WebRequest, WebResponse};
use ntex::web::{WebRequest, WebResponse};
use ntex::web::{DefaultError, ErrorRenderer, HttpResponse, WebResponseError};
/// A set of errors that can occur during processing CORS
@ -728,15 +728,10 @@ where
Err::Container: From<S::Error>,
CorsError: WebResponseError<Err>,
{
type Request = WebRequest<Err>;
type Response = WebResponse;
type Error = S::Error;
type InitError = ();
type Transform = CorsMiddleware<S>;
type Future = Ready<Result<Self::Transform, Self::InitError>>;
type Service = CorsMiddleware<S>;
fn new_transform(&self, service: S) -> Self::Future {
ok(CorsMiddleware { service, inner: self.inner.clone() })
fn new_transform(&self, service: S) -> Self::Service {
CorsMiddleware { service, inner: self.inner.clone() }
}
}
@ -815,7 +810,7 @@ mod tests {
#[ntex::test]
async fn validate_origin_allows_all_origins() {
let cors = Cors::new().finish().new_transform(test::ok_service()).await.unwrap();
let cors = Cors::new().finish().new_transform(test::ok_service());
let req =
TestRequest::with_header("Origin", "https://www.example.com").to_srv_request();
@ -825,7 +820,7 @@ mod tests {
#[ntex::test]
async fn default() {
let cors = Cors::default().new_transform(test::ok_service()).await.unwrap();
let cors = Cors::default().new_transform(test::ok_service());
let req =
TestRequest::with_header("Origin", "https://www.example.com").to_srv_request();
@ -842,9 +837,7 @@ mod tests {
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
.finish()
.new_transform(test::ok_service())
.await
.unwrap();
.new_transform(test::ok_service());
let req = TestRequest::with_header("Origin", "https://www.example.com")
.method(Method::OPTIONS)
@ -923,9 +916,7 @@ mod tests {
let cors = Cors::new()
.allowed_origin("https://www.example.com")
.finish()
.new_transform(test::ok_service())
.await
.unwrap();
.new_transform(test::ok_service());
let req = TestRequest::with_header("Origin", "https://www.unknown.com")
.method(Method::GET)
@ -940,9 +931,7 @@ mod tests {
let cors = Cors::new()
.allowed_origin("https://www.example.com")
.finish()
.new_transform(test::ok_service())
.await
.unwrap();
.new_transform(test::ok_service());
let req = TestRequest::with_header("Origin", "https://www.example.com")
.method(Method::GET)
@ -957,9 +946,7 @@ mod tests {
let cors = Cors::new()
.disable_preflight()
.finish()
.new_transform(test::ok_service())
.await
.unwrap();
.new_transform(test::ok_service());
let req = TestRequest::default().method(Method::GET).to_srv_request();
let resp = test::call_service(&cors, req).await;
@ -987,9 +974,7 @@ mod tests {
.expose_headers(exposed_headers.clone())
.allowed_header(header::CONTENT_TYPE)
.finish()
.new_transform(test::ok_service())
.await
.unwrap();
.new_transform(test::ok_service());
let req = TestRequest::with_header("Origin", "https://www.example.com")
.method(Method::OPTIONS)
@ -1033,9 +1018,7 @@ mod tests {
ok::<_, std::convert::Infallible>(req.into_response(
HttpResponse::Ok().header(header::VARY, "Accept").finish(),
))
}))
.await
.unwrap();
}));
let req = TestRequest::with_header("Origin", "https://www.example.com")
.method(Method::OPTIONS)
.to_srv_request();
@ -1050,9 +1033,7 @@ mod tests {
.allowed_origin("https://www.example.com")
.allowed_origin("https://www.google.com")
.finish()
.new_transform(test::ok_service())
.await
.unwrap();
.new_transform(test::ok_service());
let req = TestRequest::with_header("Origin", "https://www.example.com")
.method(Method::OPTIONS)
@ -1073,9 +1054,7 @@ mod tests {
.allowed_origin("https://example.org")
.allowed_methods(vec![Method::GET])
.finish()
.new_transform(test::ok_service())
.await
.unwrap();
.new_transform(test::ok_service());
let req = TestRequest::with_header("Origin", "https://example.com")
.method(Method::GET)
@ -1105,9 +1084,7 @@ mod tests {
.allowed_origin("https://example.org")
.allowed_methods(vec![Method::GET])
.finish()
.new_transform(test::ok_service())
.await
.unwrap();
.new_transform(test::ok_service());
let req = TestRequest::with_header("Origin", "https://example.com")
.header(header::ACCESS_CONTROL_REQUEST_METHOD, "GET")

View file

@ -18,7 +18,7 @@ name = "ntex_files"
path = "src/lib.rs"
[dependencies]
ntex = "0.3.18"
ntex = "0.4.6"
bitflags = "1.2"
futures = "0.3"
derive_more = "0.99.11"

View file

@ -17,7 +17,7 @@ use ntex::router::{ResourceDef, ResourcePath};
use ntex::service::boxed::{self, BoxService, BoxServiceFactory};
use ntex::service::{IntoServiceFactory, Service, ServiceFactory};
use ntex::util::Bytes;
use ntex::web::dev::{WebRequest, WebResponse, WebServiceConfig, WebServiceFactory};
use ntex::web::{WebRequest, WebResponse, dev::WebServiceConfig, WebServiceFactory};
use ntex::web::error::ErrorRenderer;
use ntex::web::guard::Guard;
use ntex::web::{self, FromRequest, HttpRequest, HttpResponse};

View file

@ -21,7 +21,7 @@ default = ["cookie-policy"]
cookie-policy = ["cookie/secure", "ntex/cookie"]
[dependencies]
ntex = "0.3.18"
ntex = "0.4.6"
futures = "0.3.13"
serde = "1.0"
serde_json = "1.0"

View file

@ -62,7 +62,7 @@ use ntex::http::header::{self, HeaderValue};
use ntex::http::{HttpMessage, Payload};
use ntex::service::{Service, Transform};
use ntex::util::Extensions;
use ntex::web::dev::{WebRequest, WebResponse};
use ntex::web::{WebRequest, WebResponse};
use ntex::web::{DefaultError, ErrorRenderer, FromRequest, HttpRequest, WebResponseError};
/// The extractor type to obtain your identity from a request.
@ -231,19 +231,14 @@ where
Err::Container: From<S::Error>,
Err::Container: From<T::Error>,
{
type Request = WebRequest<Err>;
type Response = WebResponse;
type Error = S::Error;
type InitError = ();
type Transform = IdentityServiceMiddleware<S, T, Err>;
type Future = Ready<Result<Self::Transform, Self::InitError>>;
type Service = IdentityServiceMiddleware<S, T, Err>;
fn new_transform(&self, service: S) -> Self::Future {
ok(IdentityServiceMiddleware {
fn new_transform(&self, service: S) -> Self::Service {
IdentityServiceMiddleware {
backend: self.backend.clone(),
service: Rc::new(service),
_t: PhantomData,
})
}
}
}
@ -1051,7 +1046,7 @@ mod tests {
let srv = IdentityServiceMiddleware {
backend: Rc::new(Ident),
service: Rc::new(into_service(|_: WebRequest<DefaultError>| async move {
ntex::rt::time::delay_for(std::time::Duration::from_secs(100)).await;
ntex::time::sleep(std::time::Duration::from_secs(100)).await;
Err::<WebResponse, _>(error::ErrorBadRequest("error"))
})),
_t: PhantomData,
@ -1062,7 +1057,7 @@ mod tests {
ntex::rt::spawn(async move {
let _ = srv2.call(req).await;
});
ntex::rt::time::delay_for(std::time::Duration::from_millis(50)).await;
ntex::time::sleep(std::time::Duration::from_millis(50)).await;
let _ = lazy(|cx| srv.poll_ready(cx)).await;
}

View file

@ -16,7 +16,7 @@ name = "ntex_multipart"
path = "src/lib.rs"
[dependencies]
ntex = "0.3.18"
ntex = "0.4.6"
derive_more = "0.99.11"
httparse = "1.3"
futures = "0.3.13"

View file

@ -22,7 +22,7 @@ default = ["cookie-session"]
cookie-session = ["cookie/secure", "ntex/cookie"]
[dependencies]
ntex = "0.3.18"
ntex = "0.4.6"
cookie = "0.15"
derive_more = "0.99.11"
futures = "0.3.13"

View file

@ -23,11 +23,11 @@ use std::task::{Context, Poll};
use cookie::{Cookie, CookieJar, Key, SameSite};
use derive_more::{Display, From};
use futures::future::{ok, FutureExt, LocalBoxFuture, Ready};
use futures::future::{FutureExt, LocalBoxFuture};
use ntex::http::header::{HeaderValue, SET_COOKIE};
use ntex::http::HttpMessage;
use ntex::service::{Service, Transform};
use ntex::web::dev::{WebRequest, WebResponse};
use ntex::web::{WebRequest, WebResponse};
use ntex::web::{DefaultError, ErrorRenderer, WebResponseError};
use serde_json::error::Error as JsonError;
use time::{Duration, OffsetDateTime};
@ -293,15 +293,10 @@ where
Err: ErrorRenderer,
Err::Container: From<CookieSessionError>,
{
type Request = WebRequest<Err>;
type Response = WebResponse;
type Error = S::Error;
type InitError = ();
type Transform = CookieSessionMiddleware<S, Err>;
type Future = Ready<Result<Self::Transform, Self::InitError>>;
type Service = CookieSessionMiddleware<S, Err>;
fn new_transform(&self, service: S) -> Self::Future {
ok(CookieSessionMiddleware { service, inner: self.0.clone() })
fn new_transform(&self, service: S) -> Self::Service {
CookieSessionMiddleware { service, inner: self.0.clone() }
}
}
@ -494,7 +489,7 @@ mod tests {
.expires()
.expect("Expiration is set");
ntex::rt::time::delay_for(std::time::Duration::from_secs(1)).await;
ntex::time::sleep(std::time::Duration::from_secs(1)).await;
let request = test::TestRequest::with_uri("/test/").to_request();
let response = app.call(request).await.unwrap();

View file

@ -49,7 +49,7 @@ use std::rc::Rc;
use futures::future::{ok, Ready};
use ntex::http::{Payload, RequestHead};
use ntex::util::Extensions;
use ntex::web::dev::{WebRequest, WebResponse};
use ntex::web::{WebRequest, WebResponse};
use ntex::web::{Error, FromRequest, HttpRequest};
use serde::de::DeserializeOwned;
use serde::Serialize;