From 2f8491414604c397754c9ab18c0028aa46002194 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Mon, 19 Oct 2020 11:52:05 +0900 Subject: [PATCH 1/5] Skip some tests that cause ICE on nightly (#1740) --- actix-web-codegen/tests/trybuild.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/actix-web-codegen/tests/trybuild.rs b/actix-web-codegen/tests/trybuild.rs index 1bc2bd25e..6c7c58986 100644 --- a/actix-web-codegen/tests/trybuild.rs +++ b/actix-web-codegen/tests/trybuild.rs @@ -6,9 +6,8 @@ fn compile_macros() { t.compile_fail("tests/trybuild/simple-fail.rs"); t.pass("tests/trybuild/route-ok.rs"); - t.compile_fail("tests/trybuild/route-duplicate-method-fail.rs"); - t.compile_fail("tests/trybuild/route-unexpected-method-fail.rs"); + test_route_duplicate_unexpected_method(&t); test_route_missing_method(&t) } @@ -25,3 +24,13 @@ fn test_route_missing_method(t: &trybuild::TestCases) { #[rustversion::nightly] fn test_route_missing_method(_t: &trybuild::TestCases) {} + +// FIXME: Re-test them on nightly once rust-lang/rust#77993 is fixed. +#[rustversion::not(nightly)] +fn test_route_duplicate_unexpected_method(t: &trybuild::TestCases) { + t.compile_fail("tests/trybuild/route-duplicate-method-fail.rs"); + t.compile_fail("tests/trybuild/route-unexpected-method-fail.rs"); +} + +#[rustversion::nightly] +fn test_route_duplicate_unexpected_method(_t: &trybuild::TestCases) {} From cfd5b381f13937bb00be6bc427c8687a5f5b9732 Mon Sep 17 00:00:00 2001 From: Matt Gathu Date: Mon, 19 Oct 2020 08:18:16 +0200 Subject: [PATCH 2/5] Implement Logger middleware regex exclude pattern (#1723) Co-authored-by: Rob Ede --- CHANGES.md | 2 ++ Cargo.toml | 2 +- src/middleware/logger.rs | 41 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5fd3869f9..ea77607c7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,9 @@ # Changes ## Unreleased - 2020-xx-xx +* Implement Logger middleware regex exclude pattern [#1723] +[#1723]: https://github.com/actix/actix-web/pull/1723 ## 3.1.0 - 2020-09-29 ### Changed diff --git a/Cargo.toml b/Cargo.toml index 56158389c..3960b4d36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,7 +91,7 @@ log = "0.4" mime = "0.3" socket2 = "0.3" pin-project = "0.4.17" -regex = "1.3" +regex = "1.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_urlencoded = "0.6.1" diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index 51d4722d7..9a38d345b 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -13,7 +13,7 @@ use actix_service::{Service, Transform}; use bytes::Bytes; use futures_util::future::{ok, Ready}; use log::debug; -use regex::Regex; +use regex::{Regex, RegexSet}; use time::OffsetDateTime; use crate::dev::{BodySize, MessageBody, ResponseBody}; @@ -92,6 +92,7 @@ pub struct Logger(Rc); struct Inner { format: Format, exclude: HashSet, + exclude_regex: RegexSet, } impl Logger { @@ -100,6 +101,7 @@ impl Logger { Logger(Rc::new(Inner { format: Format::new(format), exclude: HashSet::new(), + exclude_regex: RegexSet::empty(), })) } @@ -111,6 +113,16 @@ impl Logger { .insert(path.into()); self } + + /// Ignore and do not log access info for paths that match regex + pub fn exclude_regex>(mut self, path: T) -> Self { + let inner = Rc::get_mut(&mut self.0).unwrap(); + let mut patterns = inner.exclude_regex.patterns().to_vec(); + patterns.push(path.into()); + let regex_set = RegexSet::new(patterns).unwrap(); + inner.exclude_regex = regex_set; + self + } } impl Default for Logger { @@ -123,6 +135,7 @@ impl Default for Logger { Logger(Rc::new(Inner { format: Format::default(), exclude: HashSet::new(), + exclude_regex: RegexSet::empty(), })) } } @@ -168,7 +181,9 @@ where } fn call(&mut self, req: ServiceRequest) -> Self::Future { - if self.inner.exclude.contains(req.path()) { + if self.inner.exclude.contains(req.path()) + || self.inner.exclude_regex.is_match(req.path()) + { LoggerResponse { fut: self.service.call(req), format: None, @@ -538,6 +553,28 @@ mod tests { let _res = srv.call(req).await; } + #[actix_rt::test] + async fn test_logger_exclude_regex() { + let srv = |req: ServiceRequest| { + ok(req.into_response( + HttpResponse::build(StatusCode::OK) + .header("X-Test", "ttt") + .finish(), + )) + }; + let logger = Logger::new("%% %{User-Agent}i %{X-Test}o %{HOME}e %D test") + .exclude_regex("\\w"); + + let mut srv = logger.new_transform(srv.into_service()).await.unwrap(); + + let req = TestRequest::with_header( + header::USER_AGENT, + header::HeaderValue::from_static("ACTIX-WEB"), + ) + .to_srv_request(); + let _res = srv.call(req).await.unwrap(); + } + #[actix_rt::test] async fn test_url_path() { let mut format = Format::new("%T %U"); From e563025b1644be0d332eba381745fd47e5b626ef Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 19 Oct 2020 12:51:30 +0100 Subject: [PATCH 3/5] always construct shortslice using debug checked new constructor (#1741) --- actix-http/src/ws/mask.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/actix-http/src/ws/mask.rs b/actix-http/src/ws/mask.rs index 726b1a4a1..d37d57eb1 100644 --- a/actix-http/src/ws/mask.rs +++ b/actix-http/src/ws/mask.rs @@ -4,7 +4,9 @@ use std::ptr::copy_nonoverlapping; use std::slice; // Holds a slice guaranteed to be shorter than 8 bytes -struct ShortSlice<'a>(&'a mut [u8]); +struct ShortSlice<'a> { + inner: &'a mut [u8], +} impl<'a> ShortSlice<'a> { /// # Safety @@ -12,10 +14,11 @@ impl<'a> ShortSlice<'a> { unsafe fn new(slice: &'a mut [u8]) -> Self { // Sanity check for debug builds debug_assert!(slice.len() < 8); - ShortSlice(slice) + ShortSlice { inner: slice } } + fn len(&self) -> usize { - self.0.len() + self.inner.len() } } @@ -56,7 +59,7 @@ pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) { fn xor_short(buf: ShortSlice<'_>, mask: u64) { // SAFETY: we know that a `ShortSlice` fits in a u64 unsafe { - let (ptr, len) = (buf.0.as_mut_ptr(), buf.0.len()); + let (ptr, len) = (buf.inner.as_mut_ptr(), buf.len()); let mut b: u64 = 0; #[allow(trivial_casts)] copy_nonoverlapping(ptr, &mut b as *mut _ as *mut u8, len); @@ -96,7 +99,13 @@ fn align_buf(buf: &mut [u8]) -> (ShortSlice<'_>, &mut [u64], ShortSlice<'_>) { // SAFETY: we know the middle section is correctly aligned, and the outer // sections are smaller than 8 bytes - unsafe { (ShortSlice::new(head), cast_slice(mid), ShortSlice(tail)) } + unsafe { + ( + ShortSlice::new(head), + cast_slice(mid), + ShortSlice::new(tail), + ) + } } else { // We didn't cross even one aligned boundary! From f92742bdacfab73b4df3b5c995ad67290a311f8f Mon Sep 17 00:00:00 2001 From: ghizzo01 <36126125+ghizzo01@users.noreply.github.com> Date: Mon, 19 Oct 2020 19:24:22 +0200 Subject: [PATCH 4/5] Bump base64 to 0.13 (#1744) --- actix-http/CHANGES.md | 2 +- actix-http/Cargo.toml | 2 +- awc/CHANGES.md | 2 +- awc/Cargo.toml | 2 +- test-server/CHANGES.md | 1 + test-server/Cargo.toml | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 6a98c4ca7..b72a7801a 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,7 +1,7 @@ # Changes ## Unreleased - 2020-xx-xx - +* Upgrade `base64` to `0.13`. ## 2.0.0 - 2020-09-11 * No significant changes from `2.0.0-beta.4`. diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 0bbde881d..a4c100b92 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -49,7 +49,7 @@ actix-threadpool = "0.3.1" actix-tls = { version = "2.0.0", optional = true } actix = { version = "0.10.0", optional = true } -base64 = "0.12" +base64 = "0.13" bitflags = "1.2" bytes = "0.5.3" cookie = { version = "0.14.1", features = ["percent-encode"] } diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 07a469746..8babba113 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -1,7 +1,7 @@ # Changes ## Unreleased - 2020-xx-xx - +* Upgrade `base64` to `0.13`. ## 2.0.0 - 2020-09-11 ### Changed diff --git a/awc/Cargo.toml b/awc/Cargo.toml index c67b6ba6f..b8cf53e06 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -42,7 +42,7 @@ actix-service = "1.0.6" actix-http = "2.0.0" actix-rt = "1.0.0" -base64 = "0.12" +base64 = "0.13" bytes = "0.5.3" derive_more = "0.99.2" futures-core = { version = "0.3.5", default-features = false } diff --git a/test-server/CHANGES.md b/test-server/CHANGES.md index 0a11e2cae..e3a59e5bf 100644 --- a/test-server/CHANGES.md +++ b/test-server/CHANGES.md @@ -3,6 +3,7 @@ ## Unreleased - 2020-xx-xx * add ability to set address for `TestServer` [#1645] +* Upgrade `base64` to `0.13`. [#1645]: https://github.com/actix/actix-web/pull/1645 diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index d06bd5dec..3ee6b8a30 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -38,7 +38,7 @@ actix-server = "1.0.0" actix-testing = "1.0.0" awc = "2.0.0" -base64 = "0.12" +base64 = "0.13" bytes = "0.5.3" futures-core = { version = "0.3.5", default-features = false } http = "0.2.0" From 98243db9f102627550bacbeced0f2b197a0ad51a Mon Sep 17 00:00:00 2001 From: cquintana-verbio <51116651+cquintana-verbio@users.noreply.github.com> Date: Tue, 20 Oct 2020 18:35:34 +0200 Subject: [PATCH 5/5] Print unconfigured `Data` type when attempting extraction (#1743) Co-authored-by: Rob Ede --- CHANGES.md | 2 ++ src/data.rs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ea77607c7..b3d3c180c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,8 +2,10 @@ ## Unreleased - 2020-xx-xx * Implement Logger middleware regex exclude pattern [#1723] +* Print unconfigured `Data` type when attempting extraction. [#1743] [#1723]: https://github.com/actix/actix-web/pull/1723 +[#1743]: https://github.com/actix/actix-web/pull/1743 ## 3.1.0 - 2020-09-29 ### Changed diff --git a/src/data.rs b/src/data.rs index 6405fd901..01d36569b 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,3 +1,4 @@ +use std::any::type_name; use std::ops::Deref; use std::sync::Arc; @@ -121,8 +122,9 @@ impl FromRequest for Data { } else { log::debug!( "Failed to construct App-level Data extractor. \ - Request path: {:?}", - req.path() + Request path: {:?} (type: {})", + req.path(), + type_name::(), ); err(ErrorInternalServerError( "App data is not configured, to configure use App::data()",