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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue