mirror of
https://github.com/ntex-rs/ntex-extras.git
synced 2025-04-05 05:47:44 +03:00
update ntex
This commit is contained in:
parent
bf9bd1825d
commit
6abb5a40df
9 changed files with 41 additions and 59 deletions
|
@ -17,6 +17,6 @@ name = "ntex_cors"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ntex = "0.1.7"
|
ntex = "0.1.8"
|
||||||
derive_more = "0.99.5"
|
derive_more = "0.99.5"
|
||||||
futures = "0.3.4"
|
futures = "0.3.4"
|
|
@ -48,7 +48,6 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
|
@ -172,19 +171,14 @@ impl<T> AllOrSome<T> {
|
||||||
/// .max_age(3600);
|
/// .max_age(3600);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Cors<Err: ErrorRenderer> {
|
pub struct Cors {
|
||||||
cors: Option<Inner>,
|
cors: Option<Inner>,
|
||||||
methods: bool,
|
methods: bool,
|
||||||
expose_hdrs: HashSet<HeaderName>,
|
expose_hdrs: HashSet<HeaderName>,
|
||||||
error: Option<HttpError>,
|
error: Option<HttpError>,
|
||||||
_t: PhantomData<Err>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Err: ErrorRenderer> Cors<Err>
|
impl Cors {
|
||||||
where
|
|
||||||
Err: ErrorRenderer,
|
|
||||||
CorsError: WebResponseError<Err>,
|
|
||||||
{
|
|
||||||
/// Build a new CORS middleware instance
|
/// Build a new CORS middleware instance
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Cors {
|
Cors {
|
||||||
|
@ -203,12 +197,11 @@ where
|
||||||
methods: false,
|
methods: false,
|
||||||
error: None,
|
error: None,
|
||||||
expose_hdrs: HashSet::new(),
|
expose_hdrs: HashSet::new(),
|
||||||
_t: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a new CORS default middleware
|
/// Build a new CORS default middleware
|
||||||
pub fn default() -> CorsFactory<Err> {
|
pub fn default() -> CorsFactory {
|
||||||
let inner = Inner {
|
let inner = Inner {
|
||||||
origins: AllOrSome::default(),
|
origins: AllOrSome::default(),
|
||||||
origins_str: None,
|
origins_str: None,
|
||||||
|
@ -234,7 +227,6 @@ where
|
||||||
};
|
};
|
||||||
CorsFactory {
|
CorsFactory {
|
||||||
inner: Rc::new(inner),
|
inner: Rc::new(inner),
|
||||||
_t: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +469,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct cors middleware
|
/// Construct cors middleware
|
||||||
pub fn finish(self) -> CorsFactory<Err> {
|
pub fn finish(self) -> CorsFactory {
|
||||||
let mut slf = if !self.methods {
|
let mut slf = if !self.methods {
|
||||||
self.allowed_methods(vec![
|
self.allowed_methods(vec![
|
||||||
Method::GET,
|
Method::GET,
|
||||||
|
@ -520,7 +512,6 @@ where
|
||||||
|
|
||||||
CorsFactory {
|
CorsFactory {
|
||||||
inner: Rc::new(cors),
|
inner: Rc::new(cors),
|
||||||
_t: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -539,32 +530,29 @@ fn cors<'a>(
|
||||||
///
|
///
|
||||||
/// The Cors struct contains the settings for CORS requests to be validated and
|
/// The Cors struct contains the settings for CORS requests to be validated and
|
||||||
/// for responses to be generated.
|
/// for responses to be generated.
|
||||||
pub struct CorsFactory<Err> {
|
pub struct CorsFactory {
|
||||||
inner: Rc<Inner>,
|
inner: Rc<Inner>,
|
||||||
_t: PhantomData<Err>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, B, Err> Transform<S> for CorsFactory<Err>
|
impl<S, Err> Transform<S> for CorsFactory
|
||||||
where
|
where
|
||||||
S: Service<Request = WebRequest<Err>, Response = WebResponse<B>>,
|
S: Service<Request = WebRequest<Err>, Response = WebResponse>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
B: 'static,
|
|
||||||
Err: ErrorRenderer,
|
Err: ErrorRenderer,
|
||||||
Err::Container: From<S::Error>,
|
Err::Container: From<S::Error>,
|
||||||
CorsError: WebResponseError<Err>,
|
CorsError: WebResponseError<Err>,
|
||||||
{
|
{
|
||||||
type Request = WebRequest<Err>;
|
type Request = WebRequest<Err>;
|
||||||
type Response = WebResponse<B>;
|
type Response = WebResponse;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = CorsMiddleware<S, Err>;
|
type Transform = CorsMiddleware<S>;
|
||||||
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
||||||
|
|
||||||
fn new_transform(&self, service: S) -> Self::Future {
|
fn new_transform(&self, service: S) -> Self::Future {
|
||||||
ok(CorsMiddleware {
|
ok(CorsMiddleware {
|
||||||
service,
|
service,
|
||||||
inner: self.inner.clone(),
|
inner: self.inner.clone(),
|
||||||
_t: PhantomData,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -574,10 +562,9 @@ where
|
||||||
/// The Cors struct contains the settings for CORS requests to be validated and
|
/// The Cors struct contains the settings for CORS requests to be validated and
|
||||||
/// for responses to be generated.
|
/// for responses to be generated.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CorsMiddleware<S, Err> {
|
pub struct CorsMiddleware<S> {
|
||||||
service: S,
|
service: S,
|
||||||
inner: Rc<Inner>,
|
inner: Rc<Inner>,
|
||||||
_t: PhantomData<Err>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Inner {
|
struct Inner {
|
||||||
|
@ -692,17 +679,16 @@ impl Inner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, B, Err> Service for CorsMiddleware<S, Err>
|
impl<S, Err> Service for CorsMiddleware<S>
|
||||||
where
|
where
|
||||||
S: Service<Request = WebRequest<Err>, Response = WebResponse<B>>,
|
S: Service<Request = WebRequest<Err>, Response = WebResponse>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
B: 'static,
|
|
||||||
Err: ErrorRenderer,
|
Err: ErrorRenderer,
|
||||||
Err::Container: From<S::Error>,
|
Err::Container: From<S::Error>,
|
||||||
CorsError: WebResponseError<Err>,
|
CorsError: WebResponseError<Err>,
|
||||||
{
|
{
|
||||||
type Request = WebRequest<Err>;
|
type Request = WebRequest<Err>;
|
||||||
type Response = WebResponse<B>;
|
type Response = WebResponse;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
Ready<Result<Self::Response, S::Error>>,
|
Ready<Result<Self::Response, S::Error>>,
|
||||||
|
|
|
@ -18,7 +18,7 @@ name = "ntex_files"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ntex = "0.1.7"
|
ntex = "0.1.8"
|
||||||
bitflags = "1"
|
bitflags = "1"
|
||||||
bytes = "0.5.4"
|
bytes = "0.5.4"
|
||||||
futures = "0.3.4"
|
futures = "0.3.4"
|
||||||
|
|
|
@ -21,7 +21,7 @@ default = ["cookie-policy"]
|
||||||
cookie-policy = ["cookie/secure", "ntex/cookie"]
|
cookie-policy = ["cookie/secure", "ntex/cookie"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ntex = "0.1.7"
|
ntex = "0.1.8"
|
||||||
futures = "0.3.4"
|
futures = "0.3.4"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
|
@ -190,11 +190,11 @@ pub trait IdentityPolicy<Err>: Sized + 'static {
|
||||||
fn from_request(&self, request: &mut WebRequest<Err>) -> Self::Future;
|
fn from_request(&self, request: &mut WebRequest<Err>) -> Self::Future;
|
||||||
|
|
||||||
/// Write changes to response
|
/// Write changes to response
|
||||||
fn to_response<B>(
|
fn to_response(
|
||||||
&self,
|
&self,
|
||||||
identity: Option<String>,
|
identity: Option<String>,
|
||||||
changed: bool,
|
changed: bool,
|
||||||
response: &mut WebResponse<B>,
|
response: &mut WebResponse,
|
||||||
) -> Self::ResponseFuture;
|
) -> Self::ResponseFuture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,18 +226,17 @@ impl<T, Err> IdentityService<T, Err> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T, B, Err> Transform<S> for IdentityService<T, Err>
|
impl<S, T, Err> Transform<S> for IdentityService<T, Err>
|
||||||
where
|
where
|
||||||
S: Service<Request = WebRequest<Err>, Response = WebResponse<B>> + 'static,
|
S: Service<Request = WebRequest<Err>, Response = WebResponse> + 'static,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
T: IdentityPolicy<Err>,
|
T: IdentityPolicy<Err>,
|
||||||
B: 'static,
|
|
||||||
Err: ErrorRenderer,
|
Err: ErrorRenderer,
|
||||||
Err::Container: From<S::Error>,
|
Err::Container: From<S::Error>,
|
||||||
Err::Container: From<T::Error>,
|
Err::Container: From<T::Error>,
|
||||||
{
|
{
|
||||||
type Request = WebRequest<Err>;
|
type Request = WebRequest<Err>;
|
||||||
type Response = WebResponse<B>;
|
type Response = WebResponse;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = IdentityServiceMiddleware<S, T, Err>;
|
type Transform = IdentityServiceMiddleware<S, T, Err>;
|
||||||
|
@ -269,10 +268,9 @@ impl<S, T, Err> Clone for IdentityServiceMiddleware<S, T, Err> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T, B, Err> Service for IdentityServiceMiddleware<S, T, Err>
|
impl<S, T, Err> Service for IdentityServiceMiddleware<S, T, Err>
|
||||||
where
|
where
|
||||||
B: 'static,
|
S: Service<Request = WebRequest<Err>, Response = WebResponse> + 'static,
|
||||||
S: Service<Request = WebRequest<Err>, Response = WebResponse<B>> + 'static,
|
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
T: IdentityPolicy<Err>,
|
T: IdentityPolicy<Err>,
|
||||||
Err: ErrorRenderer,
|
Err: ErrorRenderer,
|
||||||
|
@ -280,7 +278,7 @@ where
|
||||||
Err::Container: From<T::Error>,
|
Err::Container: From<T::Error>,
|
||||||
{
|
{
|
||||||
type Request = WebRequest<Err>;
|
type Request = WebRequest<Err>;
|
||||||
type Response = WebResponse<B>;
|
type Response = WebResponse;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||||
|
|
||||||
|
@ -370,9 +368,9 @@ impl<Err: ErrorRenderer> CookieIdentityInner<Err> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_cookie<B>(
|
fn set_cookie(
|
||||||
&self,
|
&self,
|
||||||
resp: &mut WebResponse<B>,
|
resp: &mut WebResponse,
|
||||||
value: Option<CookieValue>,
|
value: Option<CookieValue>,
|
||||||
) -> Result<(), CookieIdentityPolicyError> {
|
) -> Result<(), CookieIdentityPolicyError> {
|
||||||
let add_cookie = value.is_some();
|
let add_cookie = value.is_some();
|
||||||
|
@ -592,11 +590,11 @@ impl<Err: ErrorRenderer> IdentityPolicy<Err> for CookieIdentityPolicy<Err> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_response<B>(
|
fn to_response(
|
||||||
&self,
|
&self,
|
||||||
id: Option<String>,
|
id: Option<String>,
|
||||||
changed: bool,
|
changed: bool,
|
||||||
res: &mut WebResponse<B>,
|
res: &mut WebResponse,
|
||||||
) -> Self::ResponseFuture {
|
) -> Self::ResponseFuture {
|
||||||
let _ = if changed {
|
let _ = if changed {
|
||||||
let login_timestamp = SystemTime::now();
|
let login_timestamp = SystemTime::now();
|
||||||
|
|
|
@ -16,7 +16,7 @@ name = "ntex_multipart"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ntex = "0.1.7"
|
ntex = "0.1.8"
|
||||||
bytes = "0.5.4"
|
bytes = "0.5.4"
|
||||||
derive_more = "0.99.5"
|
derive_more = "0.99.5"
|
||||||
httparse = "1.3"
|
httparse = "1.3"
|
||||||
|
|
|
@ -22,7 +22,7 @@ default = ["cookie-session"]
|
||||||
cookie-session = ["cookie/secure", "ntex/cookie"]
|
cookie-session = ["cookie/secure", "ntex/cookie"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ntex = "0.1.7"
|
ntex = "0.1.8"
|
||||||
bytes = "0.5.4"
|
bytes = "0.5.4"
|
||||||
cookie = "0.13.3"
|
cookie = "0.13.3"
|
||||||
derive_more = "0.99.5"
|
derive_more = "0.99.5"
|
||||||
|
|
|
@ -83,9 +83,9 @@ impl<Err> CookieSessionInner<Err> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_cookie<B>(
|
fn set_cookie(
|
||||||
&self,
|
&self,
|
||||||
res: &mut WebResponse<B>,
|
res: &mut WebResponse,
|
||||||
state: impl Iterator<Item = (String, String)>,
|
state: impl Iterator<Item = (String, String)>,
|
||||||
) -> Result<(), CookieSessionError> {
|
) -> Result<(), CookieSessionError> {
|
||||||
let state: HashMap<String, String> = state.collect();
|
let state: HashMap<String, String> = state.collect();
|
||||||
|
@ -132,7 +132,7 @@ impl<Err> CookieSessionInner<Err> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// invalidates session cookie
|
/// invalidates session cookie
|
||||||
fn remove_cookie<B>(&self, res: &mut WebResponse<B>) -> Result<(), Infallible> {
|
fn remove_cookie(&self, res: &mut WebResponse) -> Result<(), Infallible> {
|
||||||
let mut cookie = Cookie::named(self.name.clone());
|
let mut cookie = Cookie::named(self.name.clone());
|
||||||
cookie.set_value("");
|
cookie.set_value("");
|
||||||
cookie.set_max_age(Duration::zero());
|
cookie.set_max_age(Duration::zero());
|
||||||
|
@ -294,17 +294,16 @@ impl<Err> CookieSession<Err> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, B, Err> Transform<S> for CookieSession<Err>
|
impl<S, Err> Transform<S> for CookieSession<Err>
|
||||||
where
|
where
|
||||||
S: Service<Request = WebRequest<Err>, Response = WebResponse<B>>,
|
S: Service<Request = WebRequest<Err>, Response = WebResponse>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
S::Error: 'static,
|
||||||
B: 'static,
|
|
||||||
Err: ErrorRenderer,
|
Err: ErrorRenderer,
|
||||||
Err::Container: From<CookieSessionError>,
|
Err::Container: From<CookieSessionError>,
|
||||||
{
|
{
|
||||||
type Request = WebRequest<Err>;
|
type Request = WebRequest<Err>;
|
||||||
type Response = WebResponse<B>;
|
type Response = WebResponse;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = CookieSessionMiddleware<S, Err>;
|
type Transform = CookieSessionMiddleware<S, Err>;
|
||||||
|
@ -324,17 +323,16 @@ pub struct CookieSessionMiddleware<S, Err> {
|
||||||
inner: Rc<CookieSessionInner<Err>>,
|
inner: Rc<CookieSessionInner<Err>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, B, Err> Service for CookieSessionMiddleware<S, Err>
|
impl<S, Err> Service for CookieSessionMiddleware<S, Err>
|
||||||
where
|
where
|
||||||
S: Service<Request = WebRequest<Err>, Response = WebResponse<B>>,
|
S: Service<Request = WebRequest<Err>, Response = WebResponse>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
S::Error: 'static,
|
||||||
B: 'static,
|
|
||||||
Err: ErrorRenderer,
|
Err: ErrorRenderer,
|
||||||
Err::Container: From<CookieSessionError>,
|
Err::Container: From<CookieSessionError>,
|
||||||
{
|
{
|
||||||
type Request = WebRequest<Err>;
|
type Request = WebRequest<Err>;
|
||||||
type Response = WebResponse<B>;
|
type Response = WebResponse;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
|
||||||
|
|
||||||
|
|
|
@ -188,8 +188,8 @@ impl Session {
|
||||||
inner.state.extend(data);
|
inner.state.extend(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_changes<B>(
|
pub fn get_changes(
|
||||||
res: &mut WebResponse<B>,
|
res: &mut WebResponse,
|
||||||
) -> (
|
) -> (
|
||||||
SessionStatus,
|
SessionStatus,
|
||||||
Option<impl Iterator<Item = (String, String)>>,
|
Option<impl Iterator<Item = (String, String)>>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue