From 0805f2b1c64c36e430d0514565c9f0ea460b20e3 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 13 Dec 2021 02:49:27 +0000 Subject: [PATCH] stop cloning request across service call (#213) --- actix-cors/CHANGES.md | 6 ++++++ actix-cors/Cargo.toml | 2 +- actix-cors/README.md | 4 ++-- actix-cors/examples/cors.rs | 6 +++++- actix-cors/src/middleware.rs | 15 +-------------- actix-web-httpauth/Cargo.toml | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/actix-cors/CHANGES.md b/actix-cors/CHANGES.md index e81606374..551af1bea 100644 --- a/actix-cors/CHANGES.md +++ b/actix-cors/CHANGES.md @@ -3,6 +3,12 @@ ## Unreleased - 2021-xx-xx +## 0.6.0-beta.6 - 2021-12-13 +* Fix panic when wrapping routes with dynamic segments in their paths. [#213] + +[#213]: https://github.com/actix/actix-extras/pull/213 + + ## 0.6.0-beta.5 - 2021-12-12 * Update `actix-web` dependency to `4.0.0.beta-14`. [#209] diff --git a/actix-cors/Cargo.toml b/actix-cors/Cargo.toml index a6ebd8b95..b7531b9e6 100644 --- a/actix-cors/Cargo.toml +++ b/actix-cors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-cors" -version = "0.6.0-beta.5" +version = "0.6.0-beta.6" authors = [ "Nikolay Kim ", "Rob Ede ", diff --git a/actix-cors/README.md b/actix-cors/README.md index 0a0908e6d..a54fcc72a 100644 --- a/actix-cors/README.md +++ b/actix-cors/README.md @@ -3,9 +3,9 @@ > Cross-origin resource sharing (CORS) for Actix Web. [![crates.io](https://img.shields.io/crates/v/actix-cors?label=latest)](https://crates.io/crates/actix-cors) -[![Documentation](https://docs.rs/actix-cors/badge.svg?version=0.6.0-beta.5)](https://docs.rs/actix-cors/0.6.0-beta.5) +[![Documentation](https://docs.rs/actix-cors/badge.svg?version=0.6.0-beta.6)](https://docs.rs/actix-cors/0.6.0-beta.6) ![Apache 2.0 or MIT licensed](https://img.shields.io/crates/l/actix-cors) -[![Dependency Status](https://deps.rs/crate/actix-cors/0.6.0-beta.5/status.svg)](https://deps.rs/crate/actix-cors/0.6.0-beta.5) +[![Dependency Status](https://deps.rs/crate/actix-cors/0.6.0-beta.6/status.svg)](https://deps.rs/crate/actix-cors/0.6.0-beta.6) ## Documentation & Resources diff --git a/actix-cors/examples/cors.rs b/actix-cors/examples/cors.rs index 2ac419447..3b9a39df6 100644 --- a/actix-cors/examples/cors.rs +++ b/actix-cors/examples/cors.rs @@ -35,9 +35,13 @@ async fn main() -> std::io::Result<()> { .allowed_header(header::CONTENT_TYPE) // set list of headers that are safe to expose .expose_headers(&[header::CONTENT_DISPOSITION]) - // set CORS rules ttl + // set preflight cache TTL .max_age(3600), ) + .route( + "/{n}/init", + web::to(|path: web::Path| async move { path.into_inner() }), + ) .default_service(web::to(|| async { "Hello world!" })) }) .bind("127.0.0.1:8080")? diff --git a/actix-cors/src/middleware.rs b/actix-cors/src/middleware.rs index e07b7cbdf..54cfacf86 100644 --- a/actix-cors/src/middleware.rs +++ b/actix-cors/src/middleware.rs @@ -163,10 +163,6 @@ where } } - let (req, pl) = req.into_parts(); - let req2 = req.clone(); - let req = ServiceRequest::from_parts(req, pl); - let inner = Rc::clone(&self.inner); let fut = self.service.call(req); @@ -174,16 +170,7 @@ where let res = fut.await; if origin.is_some() { - let res = match res { - Ok(res) => res, - Err(err) => { - let res = HttpResponse::from_error(err); - let res = ServiceResponse::new(req2, res); - return Ok(res.map_into_right_body()); - } - }; - - Ok(Self::augment_response(&inner, res)) + Ok(Self::augment_response(&inner, res?)) } else { res } diff --git a/actix-web-httpauth/Cargo.toml b/actix-web-httpauth/Cargo.toml index 34d1e9295..144eff04c 100644 --- a/actix-web-httpauth/Cargo.toml +++ b/actix-web-httpauth/Cargo.toml @@ -28,5 +28,5 @@ futures-core = { version = "0.3.7", default-features = false } pin-project-lite = "0.2.7" [dev-dependencies] -actix-cors = "0.6.0-beta.5" +actix-cors = "0.6.0-beta.6" actix-rt = "2"