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