From b653bf557f191683896829ae682343e345778b78 Mon Sep 17 00:00:00 2001 From: Darin Gordon Date: Mon, 7 Feb 2022 14:04:03 -0500 Subject: [PATCH 01/27] added note to v4 migration guide about worker thread update (#2634) --- actix-web/MIGRATION-4.0.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index 202531c62..65f638c2e 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -9,6 +9,7 @@ Headings marked with :warning: are **breaking behavioral changes** and will prob ## Table of Contents: - [MSRV](#msrv) +- [Server Settings](#server-settings) - [Module Structure](#module-structure) - [`NormalizePath` Middleware :warning:](#normalizepath-middleware-warning) - [`FromRequest` Trait](#fromrequest-trait) @@ -20,6 +21,11 @@ Headings marked with :warning: are **breaking behavioral changes** and will prob The MSRV of Actix Web has been raised from 1.42 to 1.54. +## Server Settings + +Until actix-web v4, actix-server used the total number of available logical cores as the default number of worker threads. The new default number of worker threads for actix-server is the number of [physical CPU cores available](https://github.com/actix/actix-net/commit/3a3d654cea5e55b169f6fd05693b765799733b1b#diff-96893e8cb2125e6eefc96105a8462c4fd834943ef5129ffbead1a114133ebb78). For more information about this change, refer to [this analysis](https://github.com/actix/actix-web/issues/957). + + ## Module Structure Lots of modules has been organized in this release. If a compile error refers to "item XYZ not found in module..." or "module XYZ not found", refer to the [documentation on docs.rs](https://docs.rs/actix-web) to to search for items' new locations. From b0fbe0dfd8da9ef09b5d3043f49f6bd11d9a2407 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 06:58:26 +0000 Subject: [PATCH 02/27] fix workers doc --- actix-web/MIGRATION-4.0.md | 4 ++++ actix-web/src/server.rs | 2 +- scripts/unreleased | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index 65f638c2e..f6c2f9bc6 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -139,3 +139,7 @@ TODO ## HttpResponse no longer implements Future TODO + +## `#[actix_web::main]` and `#[tokio::main]` + +TODO diff --git a/actix-web/src/server.rs b/actix-web/src/server.rs index c9d9cc9bd..bdcfbf48a 100644 --- a/actix-web/src/server.rs +++ b/actix-web/src/server.rs @@ -128,7 +128,7 @@ where /// Set number of workers to start. /// - /// By default, server uses number of available logical CPU as thread count. + /// By default, the number of available physical CPUs is used as the worker count. pub fn workers(mut self, num: usize) -> Self { self.builder = self.builder.workers(num); self diff --git a/scripts/unreleased b/scripts/unreleased index 4dfa2d9ae..e664c0879 100755 --- a/scripts/unreleased +++ b/scripts/unreleased @@ -9,7 +9,16 @@ unreleased_for() { DIR=$1 CARGO_MANIFEST=$DIR/Cargo.toml - CHANGELOG_FILE=$DIR/CHANGES.md + + # determine changelog file name + if [ -f "$DIR/CHANGES.md" ]; then + CHANGELOG_FILE=$DIR/CHANGES.md + elif [ -f "$DIR/CHANGELOG.md" ]; then + CHANGELOG_FILE=$DIR/CHANGELOG.md + else + echo "No changelog file found" + exit 1 + fi # get current version PACKAGE_NAME="$(sed -nE 's/^name ?= ?"([^"]+)"$/\1/ p' "$CARGO_MANIFEST" | head -n 1)" @@ -36,6 +45,6 @@ unreleased_for() { cat "$CHANGE_CHUNK_FILE" } -for f in $(fd --absolute-path CHANGES.md); do +for f in $(fd --absolute-path 'CHANGE\w+.md'); do unreleased_for $(dirname $f) done From 0c144054cba2fee55bad6183865b98f3d96a74a2 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Tue, 8 Feb 2022 10:50:05 +0300 Subject: [PATCH 03/27] make `Condition` generic over body type (#2635) Co-authored-by: Rob Ede --- actix-web/CHANGES.md | 4 + actix-web/src/middleware/condition.rs | 120 ++++++++++++++++++-------- 2 files changed, 88 insertions(+), 36 deletions(-) diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 37fe6ca6a..78fd50c8c 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -1,11 +1,15 @@ # Changes ## Unreleased - 2021-xx-xx +### Changed +- `middleware::Condition` gained a broader compatibility; `Compat` is needed in fewer cases. [#2635] + ### Added - Implement `Responder` for `Vec`. [#2625] - Re-export `KeepAlive` in `http` mod. [#2625] [#2625]: https://github.com/actix/actix-web/pull/2625 +[#2635]: https://github.com/actix/actix-web/pull/2635 ## 4.0.0-rc.2 - 2022-02-02 diff --git a/actix-web/src/middleware/condition.rs b/actix-web/src/middleware/condition.rs index 659f88bc9..65f25a67c 100644 --- a/actix-web/src/middleware/condition.rs +++ b/actix-web/src/middleware/condition.rs @@ -1,18 +1,22 @@ //! For middleware documentation, see [`Condition`]. -use std::task::{Context, Poll}; +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, +}; -use actix_service::{Service, Transform}; -use actix_utils::future::Either; -use futures_core::future::LocalBoxFuture; +use futures_core::{future::LocalBoxFuture, ready}; use futures_util::future::FutureExt as _; +use pin_project_lite::pin_project; + +use crate::{ + body::EitherBody, + dev::{Service, ServiceResponse, Transform}, +}; /// Middleware for conditionally enabling other middleware. /// -/// The controlled middleware must not change the `Service` interfaces. This means you cannot -/// control such middlewares like `Logger` or `Compress` directly. See the [`Compat`](super::Compat) -/// middleware for a workaround. -/// /// # Examples /// ``` /// use actix_web::middleware::{Condition, NormalizePath}; @@ -36,16 +40,16 @@ impl Condition { } } -impl Transform for Condition +impl Transform for Condition where - S: Service + 'static, - T: Transform, + S: Service, Error = Err> + 'static, + T: Transform, Error = Err>, T::Future: 'static, T::InitError: 'static, T::Transform: 'static, { - type Response = S::Response; - type Error = S::Error; + type Response = ServiceResponse>; + type Error = Err; type Transform = ConditionMiddleware; type InitError = T::InitError; type Future = LocalBoxFuture<'static, Result>; @@ -69,14 +73,14 @@ pub enum ConditionMiddleware { Disable(D), } -impl Service for ConditionMiddleware +impl Service for ConditionMiddleware where - E: Service, - D: Service, + E: Service, Error = Err>, + D: Service, Error = Err>, { - type Response = E::Response; - type Error = E::Error; - type Future = Either; + type Response = ServiceResponse>; + type Error = Err; + type Future = ConditionMiddlewareFuture; fn poll_ready(&self, cx: &mut Context<'_>) -> Poll> { match self { @@ -87,27 +91,59 @@ where fn call(&self, req: Req) -> Self::Future { match self { - ConditionMiddleware::Enable(service) => Either::left(service.call(req)), - ConditionMiddleware::Disable(service) => Either::right(service.call(req)), + ConditionMiddleware::Enable(service) => ConditionMiddlewareFuture::Enabled { + fut: service.call(req), + }, + ConditionMiddleware::Disable(service) => ConditionMiddlewareFuture::Disabled { + fut: service.call(req), + }, } } } +pin_project! { + #[doc(hidden)] + #[project = ConditionProj] + pub enum ConditionMiddlewareFuture { + Enabled { #[pin] fut: E, }, + Disabled { #[pin] fut: D, }, + } +} + +impl Future for ConditionMiddlewareFuture +where + E: Future, Err>>, + D: Future, Err>>, +{ + type Output = Result>, Err>; + + #[inline] + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + let res = match self.project() { + ConditionProj::Enabled { fut } => ready!(fut.poll(cx))?.map_into_left_body(), + ConditionProj::Disabled { fut } => ready!(fut.poll(cx))?.map_into_right_body(), + }; + + Poll::Ready(Ok(res)) + } +} + #[cfg(test)] mod tests { - use actix_service::IntoService; - use actix_utils::future::ok; + use actix_service::IntoService as _; use super::*; use crate::{ + body::BoxBody, dev::{ServiceRequest, ServiceResponse}, error::Result, http::{ header::{HeaderValue, CONTENT_TYPE}, StatusCode, }, - middleware::{err_handlers::*, Compat}, + middleware::{self, ErrorHandlerResponse, ErrorHandlers}, test::{self, TestRequest}, + web::Bytes, HttpResponse, }; @@ -120,40 +156,52 @@ mod tests { Ok(ErrorHandlerResponse::Response(res.map_into_left_body())) } + #[test] + fn compat_with_builtin_middleware() { + let _ = Condition::new(true, middleware::Compat::noop()); + let _ = Condition::new(true, middleware::Logger::default()); + let _ = Condition::new(true, middleware::Compress::default()); + let _ = Condition::new(true, middleware::NormalizePath::trim()); + let _ = Condition::new(true, middleware::DefaultHeaders::new()); + let _ = Condition::new(true, middleware::ErrorHandlers::::new()); + let _ = Condition::new(true, middleware::ErrorHandlers::::new()); + } + #[actix_rt::test] async fn test_handler_enabled() { - let srv = |req: ServiceRequest| { - ok(req.into_response(HttpResponse::InternalServerError().finish())) + let srv = |req: ServiceRequest| async move { + let resp = HttpResponse::InternalServerError().message_body(String::new())?; + Ok(req.into_response(resp)) }; - let mw = Compat::new( - ErrorHandlers::new().handler(StatusCode::INTERNAL_SERVER_ERROR, render_500), - ); + let mw = ErrorHandlers::new().handler(StatusCode::INTERNAL_SERVER_ERROR, render_500); let mw = Condition::new(true, mw) .new_transform(srv.into_service()) .await .unwrap(); - let resp = test::call_service(&mw, TestRequest::default().to_srv_request()).await; + + let resp: ServiceResponse, String>> = + test::call_service(&mw, TestRequest::default().to_srv_request()).await; assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "0001"); } #[actix_rt::test] async fn test_handler_disabled() { - let srv = |req: ServiceRequest| { - ok(req.into_response(HttpResponse::InternalServerError().finish())) + let srv = |req: ServiceRequest| async move { + let resp = HttpResponse::InternalServerError().message_body(String::new())?; + Ok(req.into_response(resp)) }; - let mw = Compat::new( - ErrorHandlers::new().handler(StatusCode::INTERNAL_SERVER_ERROR, render_500), - ); + let mw = ErrorHandlers::new().handler(StatusCode::INTERNAL_SERVER_ERROR, render_500); let mw = Condition::new(false, mw) .new_transform(srv.into_service()) .await .unwrap(); - let resp = test::call_service(&mw, TestRequest::default().to_srv_request()).await; + let resp: ServiceResponse, String>> = + test::call_service(&mw, TestRequest::default().to_srv_request()).await; assert_eq!(resp.headers().get(CONTENT_TYPE), None); } } From 3d621677a57a32f73d8346aeccd8968cd14f54a9 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 08:00:47 +0000 Subject: [PATCH 04/27] clippy --- actix-files/src/directory.rs | 2 +- actix-http/src/h1/client.rs | 5 ++++- actix-router/benches/router.rs | 5 +++-- actix-router/src/resource.rs | 2 +- actix-web/src/http/header/if_none_match.rs | 8 ++++---- awc/src/client/connection.rs | 10 +++++----- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/actix-files/src/directory.rs b/actix-files/src/directory.rs index 26225ea5c..32dd6365b 100644 --- a/actix-files/src/directory.rs +++ b/actix-files/src/directory.rs @@ -75,7 +75,7 @@ pub(crate) fn directory_listing( if dir.is_visible(&entry) { let entry = entry.unwrap(); let p = match entry.path().strip_prefix(&dir.path) { - Ok(p) if cfg!(windows) => base.join(p).to_string_lossy().replace("\\", "/"), + Ok(p) if cfg!(windows) => base.join(p).to_string_lossy().replace('\\', "/"), Ok(p) => base.join(p).to_string_lossy().into_owned(), Err(_) => continue, }; diff --git a/actix-http/src/h1/client.rs b/actix-http/src/h1/client.rs index 4e0ae8f48..75c88d00c 100644 --- a/actix-http/src/h1/client.rs +++ b/actix-http/src/h1/client.rs @@ -128,7 +128,10 @@ impl Decoder for ClientCodec { type Error = ParseError; fn decode(&mut self, src: &mut BytesMut) -> Result, Self::Error> { - debug_assert!(!self.inner.payload.is_some(), "Payload decoder is set"); + debug_assert!( + self.inner.payload.is_none(), + "Payload decoder should not be set" + ); if let Some((req, payload)) = self.inner.decoder.decode(src)? { if let Some(conn_type) = req.conn_type() { diff --git a/actix-router/benches/router.rs b/actix-router/benches/router.rs index a428b9f13..6f6b67b48 100644 --- a/actix-router/benches/router.rs +++ b/actix-router/benches/router.rs @@ -145,7 +145,8 @@ macro_rules! register { concat!("/user/keys"), concat!("/user/keys/", $p1), ]; - std::array::IntoIter::new(arr) + + IntoIterator::into_iter(arr) }}; } @@ -158,7 +159,7 @@ fn call() -> impl Iterator { "/repos/rust-lang/rust/releases/1.51.0", ]; - std::array::IntoIter::new(arr) + IntoIterator::into_iter(arr) } fn compare_routers(c: &mut Criterion) { diff --git a/actix-router/src/resource.rs b/actix-router/src/resource.rs index f3eaa9f42..c616b467a 100644 --- a/actix-router/src/resource.rs +++ b/actix-router/src/resource.rs @@ -898,7 +898,7 @@ impl ResourceDef { } let pattern_re_set = RegexSet::new(re_set).unwrap(); - let segments = segments.unwrap_or_else(Vec::new); + let segments = segments.unwrap_or_default(); ( PatternType::DynamicSet(pattern_re_set, pattern_data), diff --git a/actix-web/src/http/header/if_none_match.rs b/actix-web/src/http/header/if_none_match.rs index 863be70cf..86d7da9b2 100644 --- a/actix-web/src/http/header/if_none_match.rs +++ b/actix-web/src/http/header/if_none_match.rs @@ -62,18 +62,18 @@ crate::http::header::common_header! { #[cfg(test)] mod tests { + use actix_http::test::TestRequest; + use super::IfNoneMatch; use crate::http::header::{EntityTag, Header, IF_NONE_MATCH}; - use actix_http::test::TestRequest; #[test] fn test_if_none_match() { - let mut if_none_match: Result; - let req = TestRequest::default() .insert_header((IF_NONE_MATCH, "*")) .finish(); - if_none_match = Header::parse(&req); + + let mut if_none_match = IfNoneMatch::parse(&req); assert_eq!(if_none_match.ok(), Some(IfNoneMatch::Any)); let req = TestRequest::default() diff --git a/awc/src/client/connection.rs b/awc/src/client/connection.rs index 456f119aa..9de4ece4f 100644 --- a/awc/src/client/connection.rs +++ b/awc/src/client/connection.rs @@ -337,7 +337,7 @@ where match self.get_mut() { Connection::Tcp(ConnectionType::H1(conn)) => Pin::new(conn).poll_write(cx, buf), Connection::Tls(ConnectionType::H1(conn)) => Pin::new(conn).poll_write(cx, buf), - _ => unreachable!(H2_UNREACHABLE_WRITE), + _ => unreachable!("{}", H2_UNREACHABLE_WRITE), } } @@ -345,7 +345,7 @@ where match self.get_mut() { Connection::Tcp(ConnectionType::H1(conn)) => Pin::new(conn).poll_flush(cx), Connection::Tls(ConnectionType::H1(conn)) => Pin::new(conn).poll_flush(cx), - _ => unreachable!(H2_UNREACHABLE_WRITE), + _ => unreachable!("{}", H2_UNREACHABLE_WRITE), } } @@ -353,7 +353,7 @@ where match self.get_mut() { Connection::Tcp(ConnectionType::H1(conn)) => Pin::new(conn).poll_shutdown(cx), Connection::Tls(ConnectionType::H1(conn)) => Pin::new(conn).poll_shutdown(cx), - _ => unreachable!(H2_UNREACHABLE_WRITE), + _ => unreachable!("{}", H2_UNREACHABLE_WRITE), } } @@ -369,7 +369,7 @@ where Connection::Tls(ConnectionType::H1(conn)) => { Pin::new(conn).poll_write_vectored(cx, bufs) } - _ => unreachable!(H2_UNREACHABLE_WRITE), + _ => unreachable!("{}", H2_UNREACHABLE_WRITE), } } @@ -377,7 +377,7 @@ where match *self { Connection::Tcp(ConnectionType::H1(ref conn)) => conn.is_write_vectored(), Connection::Tls(ConnectionType::H1(ref conn)) => conn.is_write_vectored(), - _ => unreachable!(H2_UNREACHABLE_WRITE), + _ => unreachable!("{}", H2_UNREACHABLE_WRITE), } } } From 161861997c1f3516cc451bb115e87578eebad5d9 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 09:31:20 +0000 Subject: [PATCH 05/27] prepare actix-http release 3.0.0-rc.2 --- actix-files/Cargo.toml | 2 +- actix-http-test/Cargo.toml | 2 +- actix-http/CHANGES.md | 3 +++ actix-http/Cargo.toml | 2 +- actix-http/README.md | 4 ++-- actix-multipart/Cargo.toml | 2 +- actix-test/Cargo.toml | 2 +- actix-web-actors/Cargo.toml | 2 +- actix-web/Cargo.toml | 2 +- awc/Cargo.toml | 4 ++-- 10 files changed, 14 insertions(+), 11 deletions(-) diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index 531695c2f..f1ea3979f 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -22,7 +22,7 @@ path = "src/lib.rs" experimental-io-uring = ["actix-web/experimental-io-uring", "tokio-uring"] [dependencies] -actix-http = "3.0.0-rc.1" +actix-http = "3.0.0-rc.2" actix-service = "2" actix-utils = "3" actix-web = { version = "4.0.0-rc.2", default-features = false } diff --git a/actix-http-test/Cargo.toml b/actix-http-test/Cargo.toml index 47d44877a..7ced53bee 100644 --- a/actix-http-test/Cargo.toml +++ b/actix-http-test/Cargo.toml @@ -52,4 +52,4 @@ tokio = { version = "1.8.4", features = ["sync"] } [dev-dependencies] actix-web = { version = "4.0.0-rc.2", default-features = false, features = ["cookies"] } -actix-http = "3.0.0-rc.1" +actix-http = "3.0.0-rc.2" diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index c28013853..e9191b0fe 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx + + +## 3.0.0-rc.2 - 2022-02-08 ### Added - Implement `From>` for `Response>`. [#2625] diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 2a340ec45..da55d212c 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-http" -version = "3.0.0-rc.1" +version = "3.0.0-rc.2" authors = [ "Nikolay Kim ", "Rob Ede ", diff --git a/actix-http/README.md b/actix-http/README.md index 0087fabe3..d06db8422 100644 --- a/actix-http/README.md +++ b/actix-http/README.md @@ -3,11 +3,11 @@ > HTTP primitives for the Actix ecosystem. [![crates.io](https://img.shields.io/crates/v/actix-http?label=latest)](https://crates.io/crates/actix-http) -[![Documentation](https://docs.rs/actix-http/badge.svg?version=3.0.0-rc.1)](https://docs.rs/actix-http/3.0.0-rc.1) +[![Documentation](https://docs.rs/actix-http/badge.svg?version=3.0.0-rc.2)](https://docs.rs/actix-http/3.0.0-rc.2) [![Version](https://img.shields.io/badge/rustc-1.54+-ab6000.svg)](https://blog.rust-lang.org/2021/05/06/Rust-1.54.0.html) ![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-http.svg)
-[![dependency status](https://deps.rs/crate/actix-http/3.0.0-rc.1/status.svg)](https://deps.rs/crate/actix-http/3.0.0-rc.1) +[![dependency status](https://deps.rs/crate/actix-http/3.0.0-rc.2/status.svg)](https://deps.rs/crate/actix-http/3.0.0-rc.2) [![Download](https://img.shields.io/crates/d/actix-http.svg)](https://crates.io/crates/actix-http) [![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x) diff --git a/actix-multipart/Cargo.toml b/actix-multipart/Cargo.toml index 686d42ec8..e141dea78 100644 --- a/actix-multipart/Cargo.toml +++ b/actix-multipart/Cargo.toml @@ -28,7 +28,7 @@ twoway = "0.2" [dev-dependencies] actix-rt = "2.2" -actix-http = "3.0.0-rc.1" +actix-http = "3.0.0-rc.2" futures-util = { version = "0.3.7", default-features = false, features = ["alloc"] } tokio = { version = "1.8.4", features = ["sync"] } tokio-stream = "0.1" diff --git a/actix-test/Cargo.toml b/actix-test/Cargo.toml index 69821a6f2..0083c5ac8 100644 --- a/actix-test/Cargo.toml +++ b/actix-test/Cargo.toml @@ -29,7 +29,7 @@ openssl = ["tls-openssl", "actix-http/openssl", "awc/openssl"] [dependencies] actix-codec = "0.4.1" -actix-http = "3.0.0-rc.1" +actix-http = "3.0.0-rc.2" actix-http-test = "3.0.0-beta.12" actix-rt = "2.1" actix-service = "2.0.0" diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index bb65abd3d..08bae25e0 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -16,7 +16,7 @@ path = "src/lib.rs" [dependencies] actix = { version = "0.12.0", default-features = false } actix-codec = "0.4.1" -actix-http = "3.0.0-rc.1" +actix-http = "3.0.0-rc.2" actix-web = { version = "4.0.0-rc.2", default-features = false } bytes = "1" diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index 76ff5cfd0..038c65857 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -71,7 +71,7 @@ actix-service = "2" actix-utils = "3" actix-tls = { version = "3", default-features = false, optional = true } -actix-http = { version = "3.0.0-rc.1", features = ["http2", "ws"] } +actix-http = { version = "3.0.0-rc.2", features = ["http2", "ws"] } actix-router = "0.5.0-rc.3" actix-web-codegen = { version = "0.5.0-rc.2", optional = true } diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 089fdf88f..93c0c5f9e 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -60,7 +60,7 @@ dangerous-h2c = [] [dependencies] actix-codec = "0.4.1" actix-service = "2.0.0" -actix-http = { version = "3.0.0-rc.1", features = ["http2", "ws"] } +actix-http = { version = "3.0.0-rc.2", features = ["http2", "ws"] } actix-rt = { version = "2.1", default-features = false } actix-tls = { version = "3.0.0", features = ["connect", "uri"] } actix-utils = "3.0.0" @@ -93,7 +93,7 @@ tls-rustls = { package = "rustls", version = "0.20.0", optional = true, features trust-dns-resolver = { version = "0.20.0", optional = true } [dev-dependencies] -actix-http = { version = "3.0.0-rc.1", features = ["openssl"] } +actix-http = { version = "3.0.0-rc.2", features = ["openssl"] } actix-http-test = { version = "3.0.0-beta.12", features = ["openssl"] } actix-server = "2" actix-test = { version = "0.1.0-beta.12", features = ["openssl", "rustls"] } From 593fbde46ab169362a3dad6aeedbb6fda4d542ba Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 09:31:48 +0000 Subject: [PATCH 06/27] prepare actix-web release 4.0.0-rc.3 --- actix-files/Cargo.toml | 4 ++-- actix-http-test/Cargo.toml | 2 +- actix-http/Cargo.toml | 2 +- actix-multipart/Cargo.toml | 2 +- actix-test/Cargo.toml | 2 +- actix-web-actors/Cargo.toml | 2 +- actix-web-codegen/Cargo.toml | 2 +- actix-web/CHANGES.md | 3 +++ actix-web/Cargo.toml | 2 +- actix-web/README.md | 4 ++-- awc/Cargo.toml | 2 +- 11 files changed, 15 insertions(+), 12 deletions(-) diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index f1ea3979f..08bd2f359 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -25,7 +25,7 @@ experimental-io-uring = ["actix-web/experimental-io-uring", "tokio-uring"] actix-http = "3.0.0-rc.2" actix-service = "2" actix-utils = "3" -actix-web = { version = "4.0.0-rc.2", default-features = false } +actix-web = { version = "4.0.0-rc.3", default-features = false } askama_escape = "0.10" bitflags = "1" @@ -44,5 +44,5 @@ tokio-uring = { version = "0.2", optional = true, features = ["bytes"] } [dev-dependencies] actix-rt = "2.2" actix-test = "0.1.0-beta.12" -actix-web = "4.0.0-rc.2" +actix-web = "4.0.0-rc.3" tempfile = "3.2" diff --git a/actix-http-test/Cargo.toml b/actix-http-test/Cargo.toml index 7ced53bee..e9986ef81 100644 --- a/actix-http-test/Cargo.toml +++ b/actix-http-test/Cargo.toml @@ -51,5 +51,5 @@ tls-openssl = { version = "0.10.9", package = "openssl", optional = true } tokio = { version = "1.8.4", features = ["sync"] } [dev-dependencies] -actix-web = { version = "4.0.0-rc.2", default-features = false, features = ["cookies"] } +actix-web = { version = "4.0.0-rc.3", default-features = false, features = ["cookies"] } actix-http = "3.0.0-rc.2" diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index da55d212c..ba8f5fa1d 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -100,7 +100,7 @@ zstd = { version = "0.10", optional = true } actix-http-test = { version = "3.0.0-beta.12", features = ["openssl"] } actix-server = "2" actix-tls = { version = "3.0.0", features = ["openssl"] } -actix-web = "4.0.0-rc.2" +actix-web = "4.0.0-rc.3" async-stream = "0.3" criterion = { version = "0.3", features = ["html_reports"] } diff --git a/actix-multipart/Cargo.toml b/actix-multipart/Cargo.toml index e141dea78..414c28862 100644 --- a/actix-multipart/Cargo.toml +++ b/actix-multipart/Cargo.toml @@ -15,7 +15,7 @@ path = "src/lib.rs" [dependencies] actix-utils = "3.0.0" -actix-web = { version = "4.0.0-rc.2", default-features = false } +actix-web = { version = "4.0.0-rc.3", default-features = false } bytes = "1" derive_more = "0.99.5" diff --git a/actix-test/Cargo.toml b/actix-test/Cargo.toml index 0083c5ac8..0f8aff074 100644 --- a/actix-test/Cargo.toml +++ b/actix-test/Cargo.toml @@ -34,7 +34,7 @@ actix-http-test = "3.0.0-beta.12" actix-rt = "2.1" actix-service = "2.0.0" actix-utils = "3.0.0" -actix-web = { version = "4.0.0-rc.2", default-features = false, features = ["cookies"] } +actix-web = { version = "4.0.0-rc.3", default-features = false, features = ["cookies"] } awc = { version = "3.0.0-beta.20", default-features = false, features = ["cookies"] } futures-core = { version = "0.3.7", default-features = false, features = ["std"] } diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index 08bae25e0..0499e19e4 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -17,7 +17,7 @@ path = "src/lib.rs" actix = { version = "0.12.0", default-features = false } actix-codec = "0.4.1" actix-http = "3.0.0-rc.2" -actix-web = { version = "4.0.0-rc.2", default-features = false } +actix-web = { version = "4.0.0-rc.3", default-features = false } bytes = "1" bytestring = "1" diff --git a/actix-web-codegen/Cargo.toml b/actix-web-codegen/Cargo.toml index 759916456..d5492243e 100644 --- a/actix-web-codegen/Cargo.toml +++ b/actix-web-codegen/Cargo.toml @@ -25,7 +25,7 @@ actix-macros = "0.2.3" actix-rt = "2.2" actix-test = "0.1.0-beta.12" actix-utils = "3.0.0" -actix-web = "4.0.0-rc.2" +actix-web = "4.0.0-rc.3" futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] } trybuild = "1" diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 78fd50c8c..ba29cdaa2 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx + + +## 4.0.0-rc.3 - 2022-02-08 ### Changed - `middleware::Condition` gained a broader compatibility; `Compat` is needed in fewer cases. [#2635] diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index 038c65857..9ab7756f3 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web" -version = "4.0.0-rc.2" +version = "4.0.0-rc.3" authors = [ "Nikolay Kim ", "Rob Ede ", diff --git a/actix-web/README.md b/actix-web/README.md index 32276e81f..2a87d340d 100644 --- a/actix-web/README.md +++ b/actix-web/README.md @@ -6,10 +6,10 @@

[![crates.io](https://img.shields.io/crates/v/actix-web?label=latest)](https://crates.io/crates/actix-web) -[![Documentation](https://docs.rs/actix-web/badge.svg?version=4.0.0-rc.2)](https://docs.rs/actix-web/4.0.0-rc.2) +[![Documentation](https://docs.rs/actix-web/badge.svg?version=4.0.0-rc.3)](https://docs.rs/actix-web/4.0.0-rc.3) ![MSRV](https://img.shields.io/badge/rustc-1.54+-ab6000.svg) ![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-web.svg) -[![Dependency Status](https://deps.rs/crate/actix-web/4.0.0-rc.2/status.svg)](https://deps.rs/crate/actix-web/4.0.0-rc.2) +[![Dependency Status](https://deps.rs/crate/actix-web/4.0.0-rc.3/status.svg)](https://deps.rs/crate/actix-web/4.0.0-rc.3)
[![CI](https://github.com/actix/actix-web/actions/workflows/ci.yml/badge.svg)](https://github.com/actix/actix-web/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/actix/actix-web/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/actix-web) diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 93c0c5f9e..e9cc5d656 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -99,7 +99,7 @@ actix-server = "2" actix-test = { version = "0.1.0-beta.12", features = ["openssl", "rustls"] } actix-tls = { version = "3.0.0", features = ["openssl", "rustls"] } actix-utils = "3.0.0" -actix-web = { version = "4.0.0-rc.2", features = ["openssl"] } +actix-web = { version = "4.0.0-rc.3", features = ["openssl"] } brotli = "3.3.3" const-str = "0.3" From 074d18209da71f0bb0f5b348e3ab26a4e80e1924 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 10:21:47 +0000 Subject: [PATCH 07/27] better document relationship with tokio --- actix-web-codegen/src/lib.rs | 4 +++ actix-web/README.md | 2 +- actix-web/src/handler.rs | 6 +++- actix-web/src/lib.rs | 41 +++++++++++++------------ actix-web/src/rt.rs | 59 ++++++++++++++++++++++++++++-------- 5 files changed, 78 insertions(+), 34 deletions(-) diff --git a/actix-web-codegen/src/lib.rs b/actix-web-codegen/src/lib.rs index f41e1ce38..5ca5616b6 100644 --- a/actix-web-codegen/src/lib.rs +++ b/actix-web-codegen/src/lib.rs @@ -152,6 +152,10 @@ method_macro!(Patch, patch); /// Marks async main function as the Actix Web system entry-point. /// +/// Note that Actix Web also works under `#[tokio::main]` since version 4.0. However, this macro is +/// still necessary for actor support (since actors use a `System`). Read more in the +/// [`actix_web::rt`](https://docs.rs/actix-web/4/actix_web/rt) module docs. +/// /// # Examples /// ``` /// #[actix_web::main] diff --git a/actix-web/README.md b/actix-web/README.md index 2a87d340d..4adeb3910 100644 --- a/actix-web/README.md +++ b/actix-web/README.md @@ -32,7 +32,7 @@ - Static assets - SSL support using OpenSSL or Rustls - Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/)) -- Includes an async [HTTP client](https://docs.rs/awc/) +- Integrates with the [`awc` HTTP client](https://docs.rs/awc/) - Runs on stable Rust 1.54+ ## Documentation diff --git a/actix-web/src/handler.rs b/actix-web/src/handler.rs index 7eb70ed25..cf86cb38b 100644 --- a/actix-web/src/handler.rs +++ b/actix-web/src/handler.rs @@ -10,12 +10,16 @@ use crate::{ /// The interface for request handlers. /// /// # What Is A Request Handler -/// A request handler has three requirements: +/// In short, a handler is just an async function that receives request-based arguments, in any +/// order, and returns something that can be converted to a response. +/// +/// In particular, a request handler has three requirements: /// 1. It is an async function (or a function/closure that returns an appropriate future); /// 1. The function parameters (up to 12) implement [`FromRequest`]; /// 1. The async function (or future) resolves to a type that can be converted into an /// [`HttpResponse`] (i.e., it implements the [`Responder`] trait). /// +/// /// # Compiler Errors /// If you get the error `the trait Handler<_> is not implemented`, then your handler does not /// fulfill the _first_ of the above requirements. Missing other requirements manifest as errors on diff --git a/actix-web/src/lib.rs b/actix-web/src/lib.rs index c3313db81..34bee7529 100644 --- a/actix-web/src/lib.rs +++ b/actix-web/src/lib.rs @@ -42,28 +42,29 @@ //! and otherwise utilizing them. //! //! # Features -//! * Supports *HTTP/1.x* and *HTTP/2* -//! * Streaming and pipelining -//! * Keep-alive and slow requests handling -//! * Client/server [WebSockets](https://actix.rs/docs/websockets/) support -//! * Transparent content compression/decompression (br, gzip, deflate, zstd) -//! * Powerful [request routing](https://actix.rs/docs/url-dispatch/) -//! * Multipart streams -//! * Static assets -//! * SSL support using OpenSSL or Rustls -//! * Middlewares ([Logger, Session, CORS, etc](https://actix.rs/docs/middleware/)) -//! * Includes an async [HTTP client](https://docs.rs/awc/) -//! * Runs on stable Rust 1.54+ +//! - Supports HTTP/1.x and HTTP/2 +//! - Streaming and pipelining +//! - Powerful [request routing](https://actix.rs/docs/url-dispatch/) with optional macros +//! - Full [Tokio](https://tokio.rs) compatibility +//! - Keep-alive and slow requests handling +//! - Client/server [WebSockets](https://actix.rs/docs/websockets/) support +//! - Transparent content compression/decompression (br, gzip, deflate, zstd) +//! - Multipart streams +//! - Static assets +//! - SSL support using OpenSSL or Rustls +//! - Middlewares ([Logger, Session, CORS, etc](middleware)) +//! - Integrates with the [`awc` HTTP client](https://docs.rs/awc/) +//! - Runs on stable Rust 1.54+ //! //! # Crate Features -//! * `cookies` - cookies support (enabled by default) -//! * `macros` - routing and runtime macros (enabled by default) -//! * `compress-brotli` - brotli content encoding compression support (enabled by default) -//! * `compress-gzip` - gzip and deflate content encoding compression support (enabled by default) -//! * `compress-zstd` - zstd content encoding compression support (enabled by default) -//! * `openssl` - HTTPS support via `openssl` crate, supports `HTTP/2` -//! * `rustls` - HTTPS support via `rustls` crate, supports `HTTP/2` -//! * `secure-cookies` - secure cookies support +//! - `cookies` - cookies support (enabled by default) +//! - `macros` - routing and runtime macros (enabled by default) +//! - `compress-brotli` - brotli content encoding compression support (enabled by default) +//! - `compress-gzip` - gzip and deflate content encoding compression support (enabled by default) +//! - `compress-zstd` - zstd content encoding compression support (enabled by default) +//! - `openssl` - HTTPS support via `openssl` crate, supports `HTTP/2` +//! - `rustls` - HTTPS support via `rustls` crate, supports `HTTP/2` +//! - `secure-cookies` - secure cookies support #![deny(rust_2018_idioms, nonstandard_style)] #![warn(future_incompatible)] diff --git a/actix-web/src/rt.rs b/actix-web/src/rt.rs index efe9fdfe6..3b4f21b46 100644 --- a/actix-web/src/rt.rs +++ b/actix-web/src/rt.rs @@ -1,9 +1,10 @@ -//! A selection of re-exports from [`actix-rt`] and [`tokio`]. +//! A selection of re-exports from [`tokio`] and [`actix-rt`]. //! -//! [`actix-rt`]: https://docs.rs/actix_rt -//! [`tokio`]: https://docs.rs/tokio +//! Actix Web runs on [Tokio], providing full[^compat] compatibility with its huge ecosystem of +//! crates. Each of the server's workers uses a single-threaded runtime. Read more about the +//! architecture in [`actix-rt`]'s docs. //! -//! # Running Actix Web Macro-less +//! # Running Actix Web Without Macros //! ```no_run //! use actix_web::{middleware, rt, web, App, HttpRequest, HttpServer}; //! @@ -12,19 +13,53 @@ //! "Hello world!\r\n" //! } //! -//! # fn main() -> std::io::Result<()> { -//! rt::System::new().block_on( +//! fn main() -> std::io::Result<()> { +//! rt::System::new().block_on( +//! HttpServer::new(|| { +//! App::new().service(web::resource("/").route(web::get().to(index))) +//! }) +//! .bind(("127.0.0.1", 8080))? +//! .run() +//! ) +//! } +//! ``` +//! +//! # Running Actix Web Using `#[tokio::main]` +//! If you need to run something alongside Actix Web that uses Tokio's work stealing functionality, +//! you can run Actix Web under `#[tokio::main]`. The [`Server`](crate::dev::Server) object returned +//! from [`HttpServer::run`](crate::HttpServer::run) can also be [`spawn`]ed, if preferred. +//! +//! Note that `actix` actor support (and therefore WebSocket support through `actix-web-actors`) +//! still require `#[actix_web::main]` since they require a [`System`] to be set up. +//! +//! ```no_run +//! use actix_web::{get, middleware, rt, web, App, HttpRequest, HttpServer}; +//! +//! #[get("/")] +//! async fn index(req: HttpRequest) -> &'static str { +//! println!("REQ: {:?}", req); +//! "Hello world!\r\n" +//! } +//! +//! #[tokio::main] +//! async fn main() -> std::io::Result<()> { //! HttpServer::new(|| { -//! App::new() -//! .wrap(middleware::Logger::default()) -//! .service(web::resource("/").route(web::get().to(index))) +//! App::new().service(index) //! }) //! .bind(("127.0.0.1", 8080))? -//! .workers(1) //! .run() -//! ) -//! # } +//! .await +//! } //! ``` +//! +//! [^compat]: Crates that use Tokio's [`block_in_place`] will not work with Actix Web. Fortunately, +//! the vast majority of Tokio-based crates do not use it. +//! +//! [`actix-rt`]: https://docs.rs/actix_rt +//! [`tokio`]: https://docs.rs/tokio +//! [Tokio]: https://docs.rs/tokio +//! [`spawn`]: https://docs.rs/tokio/1/tokio/fn.spawn.html +//! [`block_in_place`]: https://docs.rs/tokio/1/tokio/task/fn.block_in_place.html // In particular: // - Omit the `Arbiter` types because they have limited value here. From 3f2db9e75ccd18f5936b948aa482af02ce02f39f Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 12:25:13 +0000 Subject: [PATCH 08/27] fix doc tests --- actix-web/Cargo.toml | 1 + actix-web/src/rt.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index 9ab7756f3..17b2f2356 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -116,6 +116,7 @@ serde = { version = "1.0", features = ["derive"] } static_assertions = "1" tls-openssl = { package = "openssl", version = "0.10.9" } tls-rustls = { package = "rustls", version = "0.20.0" } +tokio = { version = "1.13.1", features = ["rt-multi-thread", "macros"] } zstd = "0.10" [[test]] diff --git a/actix-web/src/rt.rs b/actix-web/src/rt.rs index 3b4f21b46..929eadfd8 100644 --- a/actix-web/src/rt.rs +++ b/actix-web/src/rt.rs @@ -55,7 +55,7 @@ //! [^compat]: Crates that use Tokio's [`block_in_place`] will not work with Actix Web. Fortunately, //! the vast majority of Tokio-based crates do not use it. //! -//! [`actix-rt`]: https://docs.rs/actix_rt +//! [`actix-rt`]: https://docs.rs/actix-rt //! [`tokio`]: https://docs.rs/tokio //! [Tokio]: https://docs.rs/tokio //! [`spawn`]: https://docs.rs/tokio/1/tokio/fn.spawn.html From 98faa61afe437a5e79d728adfa7d3b4b6ecdf7d6 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 13:37:01 +0000 Subject: [PATCH 09/27] fix impl assertions --- actix-http/src/body/body_stream.rs | 8 ++++---- actix-http/src/body/boxed.rs | 4 ++-- actix-http/src/body/sized_stream.rs | 8 ++++---- awc/src/any_body.rs | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/actix-http/src/body/body_stream.rs b/actix-http/src/body/body_stream.rs index cf4f488b2..5a12c1e40 100644 --- a/actix-http/src/body/body_stream.rs +++ b/actix-http/src/body/body_stream.rs @@ -80,7 +80,7 @@ mod tests { use futures_core::ready; use futures_util::{stream, FutureExt as _}; use pin_project_lite::pin_project; - use static_assertions::{assert_impl_all, assert_not_impl_all}; + use static_assertions::{assert_impl_all, assert_not_impl_any}; use super::*; use crate::body::to_bytes; @@ -91,10 +91,10 @@ mod tests { assert_impl_all!(BodyStream>>: MessageBody); assert_impl_all!(BodyStream>>: MessageBody); - assert_not_impl_all!(BodyStream>: MessageBody); - assert_not_impl_all!(BodyStream>: MessageBody); + assert_not_impl_any!(BodyStream>: MessageBody); + assert_not_impl_any!(BodyStream>: MessageBody); // crate::Error is not Clone - assert_not_impl_all!(BodyStream>>: MessageBody); + assert_not_impl_any!(BodyStream>>: MessageBody); #[actix_rt::test] async fn skips_empty_chunks() { diff --git a/actix-http/src/body/boxed.rs b/actix-http/src/body/boxed.rs index cac6b7eb9..c22310c25 100644 --- a/actix-http/src/body/boxed.rs +++ b/actix-http/src/body/boxed.rs @@ -105,14 +105,14 @@ impl MessageBody for BoxBody { #[cfg(test)] mod tests { - use static_assertions::{assert_impl_all, assert_not_impl_all}; + use static_assertions::{assert_impl_all, assert_not_impl_any}; use super::*; use crate::body::to_bytes; assert_impl_all!(BoxBody: MessageBody, fmt::Debug, Unpin); - assert_not_impl_all!(BoxBody: Send, Sync, Unpin); + assert_not_impl_any!(BoxBody: Send, Sync, Unpin); #[actix_rt::test] async fn nested_boxed_body() { diff --git a/actix-http/src/body/sized_stream.rs b/actix-http/src/body/sized_stream.rs index 9c1727246..e5e27b287 100644 --- a/actix-http/src/body/sized_stream.rs +++ b/actix-http/src/body/sized_stream.rs @@ -76,7 +76,7 @@ mod tests { use actix_rt::pin; use actix_utils::future::poll_fn; use futures_util::stream; - use static_assertions::{assert_impl_all, assert_not_impl_all}; + use static_assertions::{assert_impl_all, assert_not_impl_any}; use super::*; use crate::body::to_bytes; @@ -87,10 +87,10 @@ mod tests { assert_impl_all!(SizedStream>>: MessageBody); assert_impl_all!(SizedStream>>: MessageBody); - assert_not_impl_all!(SizedStream>: MessageBody); - assert_not_impl_all!(SizedStream>: MessageBody); + assert_not_impl_any!(SizedStream>: MessageBody); + assert_not_impl_any!(SizedStream>: MessageBody); // crate::Error is not Clone - assert_not_impl_all!(SizedStream>>: MessageBody); + assert_not_impl_any!(SizedStream>>: MessageBody); #[actix_rt::test] async fn skips_empty_chunks() { diff --git a/awc/src/any_body.rs b/awc/src/any_body.rs index d09a943ab..83007ae2d 100644 --- a/awc/src/any_body.rs +++ b/awc/src/any_body.rs @@ -160,7 +160,7 @@ impl fmt::Debug for AnyBody { mod tests { use std::marker::PhantomPinned; - use static_assertions::{assert_impl_all, assert_not_impl_all}; + use static_assertions::{assert_impl_all, assert_not_impl_any}; use super::*; @@ -187,6 +187,6 @@ mod tests { assert_impl_all!(AnyBody: MessageBody, fmt::Debug, Unpin); assert_impl_all!(AnyBody: MessageBody); - assert_not_impl_all!(AnyBody: Send, Sync, Unpin); - assert_not_impl_all!(AnyBody: Send, Sync, Unpin); + assert_not_impl_any!(AnyBody: Send, Sync, Unpin); + assert_not_impl_any!(AnyBody: Send, Sync, Unpin); } From ff4b2d251f7527ca8b0221821691947ab7f14dae Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 14:32:57 +0000 Subject: [PATCH 10/27] fix impl assertions --- actix-http/src/body/boxed.rs | 5 ++--- awc/src/any_body.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/actix-http/src/body/boxed.rs b/actix-http/src/body/boxed.rs index c22310c25..5fcc42f56 100644 --- a/actix-http/src/body/boxed.rs +++ b/actix-http/src/body/boxed.rs @@ -110,9 +110,8 @@ mod tests { use super::*; use crate::body::to_bytes; - assert_impl_all!(BoxBody: MessageBody, fmt::Debug, Unpin); - - assert_not_impl_any!(BoxBody: Send, Sync, Unpin); + assert_impl_all!(BoxBody: fmt::Debug, MessageBody, Unpin); + assert_not_impl_any!(BoxBody: Send, Sync); #[actix_rt::test] async fn nested_boxed_body() { diff --git a/awc/src/any_body.rs b/awc/src/any_body.rs index 83007ae2d..d9c259d8f 100644 --- a/awc/src/any_body.rs +++ b/awc/src/any_body.rs @@ -181,12 +181,12 @@ mod tests { } } - assert_impl_all!(AnyBody<()>: MessageBody, fmt::Debug, Send, Sync, Unpin); - assert_impl_all!(AnyBody>: MessageBody, fmt::Debug, Send, Sync, Unpin); - assert_impl_all!(AnyBody: MessageBody, fmt::Debug, Send, Sync, Unpin); - assert_impl_all!(AnyBody: MessageBody, fmt::Debug, Unpin); - assert_impl_all!(AnyBody: MessageBody); + assert_impl_all!(AnyBody<()>: Send, Sync, Unpin, fmt::Debug, MessageBody); + assert_impl_all!(AnyBody>: Send, Sync, Unpin, fmt::Debug, MessageBody); + assert_impl_all!(AnyBody: Send, Sync, Unpin, fmt::Debug, MessageBody); + assert_impl_all!(AnyBody: Unpin, fmt::Debug, MessageBody); + assert_impl_all!(AnyBody: Send, Sync, MessageBody); - assert_not_impl_any!(AnyBody: Send, Sync, Unpin); - assert_not_impl_any!(AnyBody: Send, Sync, Unpin); + assert_not_impl_any!(AnyBody: Send, Sync); + assert_not_impl_any!(AnyBody: Unpin); } From 092dbba5b96d2ab194f6fe6fd8ff509edd73a213 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 15:24:35 +0000 Subject: [PATCH 11/27] update migration guide --- actix-web/MIGRATION-4.0.md | 31 +++++++++++++++++++---- actix-web/src/middleware/authors-guide.md | 13 ++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 actix-web/src/middleware/authors-guide.md diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index f6c2f9bc6..2f8341e1b 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -23,8 +23,7 @@ The MSRV of Actix Web has been raised from 1.42 to 1.54. ## Server Settings -Until actix-web v4, actix-server used the total number of available logical cores as the default number of worker threads. The new default number of worker threads for actix-server is the number of [physical CPU cores available](https://github.com/actix/actix-net/commit/3a3d654cea5e55b169f6fd05693b765799733b1b#diff-96893e8cb2125e6eefc96105a8462c4fd834943ef5129ffbead1a114133ebb78). For more information about this change, refer to [this analysis](https://github.com/actix/actix-web/issues/957). - +Until actix-web v4, actix-server used the total number of available logical cores as the default number of worker threads. The new default number of worker threads for actix-server is the number of [physical CPU cores available](https://github.com/actix/actix-net/commit/3a3d654cea5e55b169f6fd05693b765799733b1b#diff-96893e8cb2125e6eefc96105a8462c4fd834943ef5129ffbead1a114133ebb78). For more information about this change, refer to [this analysis](https://github.com/actix/actix-web/issues/957). ## Module Structure @@ -136,10 +135,32 @@ TODO TODO -## HttpResponse no longer implements Future +## Returning `HttpResponse` synchronously. + +The implementation of `Future` for `HttpResponse` was removed because it was largely useless for all but the simplest handlers like `web::to(|| HttpResponse::Ok().finish())`. It also caused false positives on the `async_yields_async` clippy lint in reasonable scenarios. The compiler errors will looks something like: + +``` +web::to(|| HttpResponse::Ok().finish()) +^^^^^^^ the trait `Handler<_>` is not implemented for `[closure@...]` +``` + +This form should be replaced with the a more explicit async fn: + +```diff +- web::to(|| HttpResponse::Ok().finish()) ++ web::to(|| async { HttpResponse::Ok().finish() }) +``` + +Or, for these extremely simple cases, utilise an `HttpResponseBuilder`: + +```diff +- web::to(|| HttpResponse::Ok().finish()) ++ web::to(HttpResponse::Ok) +``` -TODO ## `#[actix_web::main]` and `#[tokio::main]` -TODO +Actix Web now works seamlessly with the primary way of starting a multi-threaded Tokio runtime, `#[tokio::main]`. Therefore, it is no longer necessary to spawn a thread when you need to run something alongside Actix Web that uses of Tokio's multi-threaded mode; you can simply await the server within this context or, if preferred, use `tokio::spawn` just like any other async task. + +For now, `actix` actor support (and therefore WebSocket support via `actix-web-actors`) still requires `#[actix_web::main]` so that a `System` context is created. Designs are being created for an alternative WebSocket interface that does not require actors that should land sometime in the v4.x cycle. diff --git a/actix-web/src/middleware/authors-guide.md b/actix-web/src/middleware/authors-guide.md new file mode 100644 index 000000000..344523a1a --- /dev/null +++ b/actix-web/src/middleware/authors-guide.md @@ -0,0 +1,13 @@ +# Middleware Author's Guide + +## What Is A Middleware? + +## Middleware Traits + +## Understanding Body Types + +## Best Practices + +## Error Propagation + +## When To (Not) Use Middleware From e0f02c1d9e764140b93d5eeaa853a667293907b9 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 8 Feb 2022 16:53:09 +0000 Subject: [PATCH 12/27] update migration guide --- actix-web/MIGRATION-4.0.md | 132 +++++++++++++++--- actix-web/src/response/customize_responder.rs | 2 +- actix-web/src/response/responder.rs | 9 ++ 3 files changed, 122 insertions(+), 21 deletions(-) diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index 2f8341e1b..acbb3bc37 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -9,9 +9,9 @@ Headings marked with :warning: are **breaking behavioral changes** and will prob ## Table of Contents: - [MSRV](#msrv) -- [Server Settings](#server-settings) - [Module Structure](#module-structure) - [`NormalizePath` Middleware :warning:](#normalizepath-middleware-warning) +- [Server Settings :warning:](#server-settings-warning) - [`FromRequest` Trait](#fromrequest-trait) - [Compression Feature Flags](#compression-feature-flags) - [`web::Path`](#webpath) @@ -21,10 +21,6 @@ Headings marked with :warning: are **breaking behavioral changes** and will prob The MSRV of Actix Web has been raised from 1.42 to 1.54. -## Server Settings - -Until actix-web v4, actix-server used the total number of available logical cores as the default number of worker threads. The new default number of worker threads for actix-server is the number of [physical CPU cores available](https://github.com/actix/actix-net/commit/3a3d654cea5e55b169f6fd05693b765799733b1b#diff-96893e8cb2125e6eefc96105a8462c4fd834943ef5129ffbead1a114133ebb78). For more information about this change, refer to [this analysis](https://github.com/actix/actix-web/issues/957). - ## Module Structure Lots of modules has been organized in this release. If a compile error refers to "item XYZ not found in module..." or "module XYZ not found", refer to the [documentation on docs.rs](https://docs.rs/actix-web) to to search for items' new locations. @@ -45,6 +41,12 @@ The default `NormalizePath` behavior now strips trailing slashes by default. Thi Alternatively, explicitly require trailing slashes: `NormalizePath::new(TrailingSlash::Always)`. +## Server Settings :warning: + +Until Actix Web v4, the underlying `actix-server` crate used the number of available **logical** cores as the default number of worker threads. The new default is the number of [physical CPU cores available](https://github.com/actix/actix-net/commit/3a3d654c). For more information about this change, refer to [this analysis](https://github.com/actix/actix-web/issues/957). + +If you notice performance regressions, please open a new issue detailing your observations. + ## `FromRequest` Trait The associated type `Config` of `FromRequest` was removed. If you have custom extractors, you can just remove this implementation and refer to config types directly, if required. @@ -59,14 +61,12 @@ Consequently, the `FromRequest::configure` method was also removed. Config for e ## Compression Feature Flags -Feature flag `compress` has been split into its supported algorithm (brotli, gzip, zstd). By default, all compression algorithms are enabled. The new flags are: +Feature flag `compress` has been split into its supported algorithm (brotli, gzip, zstd). By default, all compression algorithms are enabled. If you want to select specific compression codecs, the new flags are: - `compress-brotli` - `compress-gzip` - `compress-zstd` -If you have set in your `Cargo.toml` dedicated `actix-web` features and you still want to have compression enabled. - ## `web::Path` The inner field for `web::Path` was made private because It was causing too many issues when used with inner tuple types due to its `Deref` impl. @@ -90,7 +90,7 @@ Actix Web's sister crate `awc` is no longer re-exported through the `client` mod + use awc::Client; ``` -## Integration Testing Utils Moved to `actix-test` +## Integration Testing Utils Moved To `actix-test` Actix Web's `test` module used to contain `TestServer`. Since this required the `awc` client and it was removed as a re-export (see above), it was moved to its own crate [`actix-test`](https://docs.rs/actix-test). @@ -101,7 +101,22 @@ Actix Web's `test` module used to contain `TestServer`. Since this required the ## Header APIs -TODO +Header related APIs have been standardized across all `actix-*` crates. The terminology now better matches the underlying `HeaderMap` naming conventions. Most of the the old methods have only been deprecated with notes that will guide how to update. + +In short, "insert" always indicates that existing any existing headers with the same name are overridden and "append" indicates adding with no removal. + +For request and response builder APIs, the new methods provide a unified interface for adding key-value pairs _and_ typed headers, which can often be more expressive. + +```diff +- .set_header("Api-Key", "1234") ++ .insert_header(("Api-Key", "1234")) + +- .header("Api-Key", "1234") ++ .append_header(("Api-Key", "1234")) + +- .set(ContentType::json()) ++ .insert_header(ContentType::json()) +``` ## Body Types / Removal of Body+ResponseBody types / Addition of EitherBody @@ -117,25 +132,103 @@ TODO: Also write the Middleware author's guide. ## `Responder` Trait -TODO +The `Responder` trait's interface has changed. Errors should be handled and converted to responses within the `respond_to` method. It's also no longer async so the associated `type Future` has been removed; there was no compelling use case found for it. These changes simplify the interface and implementation a lot. -## `App::data` deprecation +Now that more emphasis is placed on expressive body types, as explained in the [body types migration section](#body-types--removal-of-bodyresponsebody-types--addition-of-eitherbody), this trait has introduced an associated `type Body`. The simplest migration will be to use `BoxBody` + `.map_into_boxed_body()` but if there is a more expressive type for your responder then try to use that instead. -TODO +```diff + impl Responder for &'static str { +- type Error = Error; +- type Future = Ready>; ++ type Body = &'static str; -## It's probably not necessary to import `actix-rt` or `actix-service` any more +- fn respond_to(self, req: &HttpRequest) -> Self::Future { ++ fn respond_to(self, req: &HttpRequest) -> HttpResponse { + let res = HttpResponse::build(StatusCode::OK) + .content_type("text/plain; charset=utf-8") + .body(self); -TODO +- ok(res) ++ res + } + } +``` -## Server must be awaited in order to run :warning: +## `App::data` deprecation :warning: -TODO +The `App::data` method is deprecated. Replace instances of this with `App::app_data`. Exposing both methods was a footgun and lead to lots of confusion when trying to extract the data in handlers. Now, when using the `Data` wrapper, the type you put in to `app_data` is the same type you extract in handler arguments. + +You may need to review the [guidance on shared mutable state](https://docs.rs/actix-web/4/actix_web/struct.App.html#shared-mutable-state) in order to migrate this correctly. + +```diff + use actix_web::web::Data; + + #[get("/")] + async fn handler(my_state: Data) -> { todo!() } + + HttpServer::new(|| { +- App::new() +- .data(MyState::default()) +- .service(hander) + ++ let my_state: Data = Data::new(MyState::default()); ++ ++ App::new() ++ .app_data(my_state) ++ .service(hander) + }) +``` + +## Direct Dependency On `actix-rt` And `actix-service` + +Improvements to module management and re-exports have resulted in not needing direct dependencies on these underlying crates for the vast majority of cases. In particular, all traits necessary for creating middleware are re-exported through the `dev` modules and `#[actix_web::test]` now exists for async test definitions. Relying on the these re-exports will ease transition to future versions of Actix Web. + +```diff +- use actix_service::{Service, Transform}; ++ use actix_web::dev::{Service, Transform}; +``` + +```diff +- #[actix_rt::test] ++ #[actix_web::test] + async fn test_thing() { +``` + +## Server Must Be Polled :warning: + +In order to _start_ serving requests, the `Server` object returned from `run` **must** be `poll`ed, `await`ed, or `spawn`ed. This was done to prevent unexpected behavior and ensure that things like signal handlers are able to function correctly when enabled. + +For example, in this contrived example where the server is started and then the main thread is sent to sleep, the server will no longer be able to serve requests with v4.0: + +```rust +#[actix_web::main] +async fn main() { + HttpServer::new(|| App::new().default_service(web::to(HttpResponse::Conflict))) + .bind(("127.0.0.1", 8080)) + .unwrap() + .run(); + + thread::sleep(Duration::from_secs(1000)); +} +``` ## Guards API -TODO +Implementors of routing guards will need to use the modified interface of the `Guard` trait. The API provided is more flexible than before. See [guard module docs](https://docs.rs/actix-web/4/actix_web/guard/struct.GuardContext.html) for more details. -## Returning `HttpResponse` synchronously. +```diff + struct MethodGuard(HttpMethod); + + impl Guard for MethodGuard { +- fn check(&self, request: &RequestHead) -> bool { ++ fn check(&self, ctx: &GuardContext<'_>) -> bool { +- request.method == self.0 ++ ctx.head().method == self.0 + } + } +``` + +## Returning `HttpResponse` synchronously The implementation of `Future` for `HttpResponse` was removed because it was largely useless for all but the simplest handlers like `web::to(|| HttpResponse::Ok().finish())`. It also caused false positives on the `async_yields_async` clippy lint in reasonable scenarios. The compiler errors will looks something like: @@ -158,7 +251,6 @@ Or, for these extremely simple cases, utilise an `HttpResponseBuilder`: + web::to(HttpResponse::Ok) ``` - ## `#[actix_web::main]` and `#[tokio::main]` Actix Web now works seamlessly with the primary way of starting a multi-threaded Tokio runtime, `#[tokio::main]`. Therefore, it is no longer necessary to spawn a thread when you need to run something alongside Actix Web that uses of Tokio's multi-threaded mode; you can simply await the server within this context or, if preferred, use `tokio::spawn` just like any other async task. diff --git a/actix-web/src/response/customize_responder.rs b/actix-web/src/response/customize_responder.rs index 8cb146dda..f6f4b9236 100644 --- a/actix-web/src/response/customize_responder.rs +++ b/actix-web/src/response/customize_responder.rs @@ -7,7 +7,7 @@ use crate::{HttpRequest, HttpResponse, Responder}; /// Allows overriding status code and headers for a [`Responder`]. /// -/// Created by the [`Responder::customize`] method. +/// Created by calling the [`customize`](Responder::customize) method on a [`Responder`] type. pub struct CustomizeResponder { inner: CustomizeResponderInner, error: Option, diff --git a/actix-web/src/response/responder.rs b/actix-web/src/response/responder.rs index cb71369cf..c88faec89 100644 --- a/actix-web/src/response/responder.rs +++ b/actix-web/src/response/responder.rs @@ -47,6 +47,15 @@ pub trait Responder { CustomizeResponder::new(self) } + #[doc(hidden)] + #[deprecated(since = "4.0.0", note = "Prefer `.customize().with_status(header)`.")] + fn with_status(self, status: StatusCode) -> CustomizeResponder + where + Self: Sized, + { + self.customize().with_status(status) + } + #[doc(hidden)] #[deprecated(since = "4.0.0", note = "Prefer `.customize().insert_header(header)`.")] fn with_header(self, header: impl TryIntoHeaderPair) -> CustomizeResponder From a9f445875a79b23d44beaeb0a6adb4f3d0092fd3 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 9 Feb 2022 12:31:06 +0000 Subject: [PATCH 13/27] update migration guide --- actix-web/MIGRATION-4.0.md | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index acbb3bc37..e71387c94 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -15,7 +15,20 @@ Headings marked with :warning: are **breaking behavioral changes** and will prob - [`FromRequest` Trait](#fromrequest-trait) - [Compression Feature Flags](#compression-feature-flags) - [`web::Path`](#webpath) -- [Rustls](#rustls-crate-upgrade) +- [Rustls Crate Upgrade](#rustls-crate-upgrade) +- [Removed `awc` Client Re-export](#removed-awc-client-re-export) +- [Integration Testing Utils Moved To `actix-test`](#integration-testing-utils-moved-to-actix-test) +- [Header APIs](#header-apis) +- [Body Types / Removal of Body+ResponseBody types / Addition of EitherBody](#body-types--removal-of-bodyresponsebody-types--addition-of-eitherbody) +- [Middleware Trait APIs](#middleware-trait-apis) +- [`Responder` Trait](#responder-trait) +- [`App::data` Deprecation :warning:](#appdata-deprecation-warning) +- [Direct Dependency On `actix-rt` And `actix-service`](#direct-dependency-on-actix-rt-and-actix-service) +- [Server Must Be Polled :warning:](#server-must-be-polled-warning) +- [Guards API](#guards-api) +- [Returning `HttpResponse` synchronously](#returning-httpresponse-synchronously) +- [`#[actix_web::main]` and `#[tokio::main]`](#actixwebmain-and-tokiomain) +- [`web::block`](#webblock) ## MSRV @@ -126,6 +139,8 @@ In particular, folks seem to be struggling with the `ErrorHandlers` middleware b ## Middleware Trait APIs +> This section builds upon guidance from the [response body types](#body-types--removal-of-bodyresponsebody-types--addition-of-eitherbody) section. + TODO TODO: Also write the Middleware author's guide. @@ -154,7 +169,7 @@ Now that more emphasis is placed on expressive body types, as explained in the [ } ``` -## `App::data` deprecation :warning: +## `App::data` Deprecation :warning: The `App::data` method is deprecated. Replace instances of this with `App::app_data`. Exposing both methods was a footgun and lead to lots of confusion when trying to extract the data in handlers. Now, when using the `Data` wrapper, the type you put in to `app_data` is the same type you extract in handler arguments. @@ -218,7 +233,7 @@ Implementors of routing guards will need to use the modified interface of the `G ```diff struct MethodGuard(HttpMethod); - + impl Guard for MethodGuard { - fn check(&self, request: &RequestHead) -> bool { + fn check(&self, ctx: &GuardContext<'_>) -> bool { @@ -256,3 +271,15 @@ Or, for these extremely simple cases, utilise an `HttpResponseBuilder`: Actix Web now works seamlessly with the primary way of starting a multi-threaded Tokio runtime, `#[tokio::main]`. Therefore, it is no longer necessary to spawn a thread when you need to run something alongside Actix Web that uses of Tokio's multi-threaded mode; you can simply await the server within this context or, if preferred, use `tokio::spawn` just like any other async task. For now, `actix` actor support (and therefore WebSocket support via `actix-web-actors`) still requires `#[actix_web::main]` so that a `System` context is created. Designs are being created for an alternative WebSocket interface that does not require actors that should land sometime in the v4.x cycle. + +## `web::block` + +The `web::block` helper has changed return type from roughly `async fn(fn() -> Result) Result>` to `async fn(fn() -> T) Result`. That's to say that the blocking function can now return things that are not `Result`s and it does not wrap error types anymore. If you still need to return `Result`s then you'll likely want to use double `?` after the `.await`. + +```diff +- let n: u32 = web::block(|| Ok(123)).await?; ++ let n: u32 = web::block(|| 123).await?; + +- let n: u32 = web::block(|| Ok(123)).await?; ++ let n: u32 = web::block(|| Ok(123)).await??; +``` From 1b706b3069d47e7b52366aeb91e10d922aa68bc0 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 9 Feb 2022 16:12:39 +0000 Subject: [PATCH 14/27] update body type migration guide --- actix-http/src/body/either.rs | 16 ++++++++++++- actix-http/src/body/message_body.rs | 2 +- actix-web/MIGRATION-4.0.md | 37 ++++++++++++++++++++++++----- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/actix-http/src/body/either.rs b/actix-http/src/body/either.rs index add1eab7c..92bd89984 100644 --- a/actix-http/src/body/either.rs +++ b/actix-http/src/body/either.rs @@ -10,6 +10,17 @@ use super::{BodySize, BoxBody, MessageBody}; use crate::Error; pin_project! { + /// An "either" type specialized for body types. + /// + /// It is common, in middleware especially, to conditionally return an inner service's unknown/ + /// generic body `B` type or return early with a new response. This type's "right" variant + /// defaults to `BoxBody` since error responses are the common case. + /// + /// For example, middleware will often have `type Response = ServiceResponse>`. + /// This means that the inner service's response body type maps to the `Left` variant and the + /// middleware's own error responses use the default `Right` variant of `BoxBody`. Of course, + /// there's no reason it couldn't use `EitherBody` instead if its alternative + /// responses have a known type. #[project = EitherBodyProj] #[derive(Debug, Clone)] pub enum EitherBody { @@ -22,7 +33,10 @@ pin_project! { } impl EitherBody { - /// Creates new `EitherBody` using left variant and boxed right variant. + /// Creates new `EitherBody` left variant with a boxed right variant. + /// + /// If the expected `R` type will be inferred and is not `BoxBody` then use the + /// [`left`](Self::left) constructor instead. #[inline] pub fn new(body: L) -> Self { Self::Left { body } diff --git a/actix-http/src/body/message_body.rs b/actix-http/src/body/message_body.rs index 86ff09fbe..9090e34d5 100644 --- a/actix-http/src/body/message_body.rs +++ b/actix-http/src/body/message_body.rs @@ -19,7 +19,7 @@ use super::{BodySize, BoxBody}; /// It is not usually necessary to create custom body types, this trait is already [implemented for /// a large number of sensible body types](#foreign-impls) including: /// - Empty body: `()` -/// - Text-based: `String`, `&'static str`, `ByteString`. +/// - Text-based: `String`, `&'static str`, [`ByteString`](https://docs.rs/bytestring/1). /// - Byte-based: `Bytes`, `BytesMut`, `Vec`, `&'static [u8]`; /// - Streams: [`BodyStream`](super::BodyStream), [`SizedStream`](super::SizedStream) /// diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index e71387c94..d478456fa 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -19,7 +19,7 @@ Headings marked with :warning: are **breaking behavioral changes** and will prob - [Removed `awc` Client Re-export](#removed-awc-client-re-export) - [Integration Testing Utils Moved To `actix-test`](#integration-testing-utils-moved-to-actix-test) - [Header APIs](#header-apis) -- [Body Types / Removal of Body+ResponseBody types / Addition of EitherBody](#body-types--removal-of-bodyresponsebody-types--addition-of-eitherbody) +- [Response Body Types](#response-body-types) - [Middleware Trait APIs](#middleware-trait-apis) - [`Responder` Trait](#responder-trait) - [`App::data` Deprecation :warning:](#appdata-deprecation-warning) @@ -131,15 +131,40 @@ For request and response builder APIs, the new methods provide a unified interfa + .insert_header(ContentType::json()) ``` -## Body Types / Removal of Body+ResponseBody types / Addition of EitherBody +## Response Body Types -TODO +There have been a lot of changes to response body types. The general theme is that they are now more expressive and their purposes are more obvious. -In particular, folks seem to be struggling with the `ErrorHandlers` middleware because of this change and the obscured nature of `EitherBody` within its types. +All items in the [`body` module](https://docs.rs/actix-web/4/actix_web/body) have much better documentation now. + +### `ResponseBody` + +`ResponseBody` is gone. Its purpose was confusing and has been replaced by better components. + +### `Body` + +`Body` is also gone. In combination with `ResponseBody`, the API it provided was sub-optimal and did not encourage expressive types. Here are the equivalents in the new system (check docs): + +- `Body::None` => `body::None::new()` +- `Body::Empty` => `()` / `web::Bytes::new()` +- `Body::Bytes` => `web::Bytes::from(...)` +- `Body::Message` => `.boxed()` / `BoxBody` + +### `BoxBody` + +`BoxBody` is a new type erased body type. It's used for all error response bodies use this. Creating a boxed body is best done by calling [`.boxed()`](https://docs.rs/actix-web/4/actix_web/body/trait.MessageBody.html#method.boxed) on a `MessageBody` type. + +### `EitherBody` + +`EitherBody` is a new "either" type that is particularly useful in middleware that can bail early, returning their own response plus body type. + +### Error Handlers + +TODO In particular, folks seem to be struggling with the `ErrorHandlers` middleware because of this change and the obscured nature of `EitherBody` within its types. ## Middleware Trait APIs -> This section builds upon guidance from the [response body types](#body-types--removal-of-bodyresponsebody-types--addition-of-eitherbody) section. +This section builds upon guidance from the [response body types](#response-body-types) section. TODO @@ -149,7 +174,7 @@ TODO: Also write the Middleware author's guide. The `Responder` trait's interface has changed. Errors should be handled and converted to responses within the `respond_to` method. It's also no longer async so the associated `type Future` has been removed; there was no compelling use case found for it. These changes simplify the interface and implementation a lot. -Now that more emphasis is placed on expressive body types, as explained in the [body types migration section](#body-types--removal-of-bodyresponsebody-types--addition-of-eitherbody), this trait has introduced an associated `type Body`. The simplest migration will be to use `BoxBody` + `.map_into_boxed_body()` but if there is a more expressive type for your responder then try to use that instead. +Now that more emphasis is placed on expressive body types, as explained in the [body types migration section](#response-body-types), this trait has introduced an associated `type Body`. The simplest migration will be to use `BoxBody` + `.map_into_boxed_body()` but if there is a more expressive type for your responder then try to use that instead. ```diff impl Responder for &'static str { From 4c59a34513ebd05e0aa0bd09e167dfc02b81b6d0 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Thu, 10 Feb 2022 05:29:00 -0500 Subject: [PATCH 15/27] Remove clone implementation for `Path` (#2639) --- actix-web/src/types/path.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/actix-web/src/types/path.rs b/actix-web/src/types/path.rs index 869269d09..0fcac2c19 100644 --- a/actix-web/src/types/path.rs +++ b/actix-web/src/types/path.rs @@ -53,9 +53,7 @@ use crate::{ /// format!("Welcome {}!", info.name) /// } /// ``` -#[derive( - Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, AsRef, Display, From, -)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deref, DerefMut, AsRef, Display, From)] pub struct Path(T); impl Path { From 3486edabcfb646eb31b2a2ae8db8e703a53318a6 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 15 Feb 2022 00:54:12 +0000 Subject: [PATCH 16/27] update migrations guide re tokio v1 --- actix-web/MIGRATION-4.0.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index d478456fa..01aa642bd 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -2,13 +2,14 @@ It is assumed that migration is happening _from_ v3.x. If migration from older version of Actix Web, see the other historical migration notes in this folder. -This is not an exhaustive list of changes. Smaller or less impactful code changes are outlined, with links to the PRs that introduced them, are shown in [CHANGES.md](./CHANGES.md). If you think any of the changes not mentioned here deserve to be, submit an issue or PR. +This is not an exhaustive list of changes. Smaller or less impactful code changes are outlined, with links to the PRs that introduced them, in [CHANGES.md](./CHANGES.md). If you think any of the changes not mentioned here deserve to be, submit an issue or PR. -Headings marked with :warning: are **breaking behavioral changes** and will probably not surface as compile-time errors. Automated tests _might_ detect their effects on your app. +Headings marked with :warning: are **breaking behavioral changes** that will probably not surface as compile-time errors though automated tests _might_ detect their effects on your app. ## Table of Contents: - [MSRV](#msrv) +- [Tokio v1 Ecosystem](#tokio-v1-ecosystem) - [Module Structure](#module-structure) - [`NormalizePath` Middleware :warning:](#normalizepath-middleware-warning) - [Server Settings :warning:](#server-settings-warning) @@ -34,6 +35,17 @@ Headings marked with :warning: are **breaking behavioral changes** and will prob The MSRV of Actix Web has been raised from 1.42 to 1.54. +## Tokio v1 Ecosystem + +Actix Web v4 is now underpinned by the the Tokio v1 ecosystem of crates. If you have dependencies that might utilize Tokio directly, it is worth checking to see if an update is available. The following command will assist in finding such dependencies: + +```sh +cargo tree -i tokio + +# if multiple tokio versions are depended on, show the older ones with: +cargo tree -i tokio:0.2.25 +``` + ## Module Structure Lots of modules has been organized in this release. If a compile error refers to "item XYZ not found in module..." or "module XYZ not found", refer to the [documentation on docs.rs](https://docs.rs/actix-web) to to search for items' new locations. From de62e8b025a6f16ee54f7c5e73c85f44619071f6 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 15 Feb 2022 14:40:26 +0000 Subject: [PATCH 17/27] add nextest to post-merge ci --- .github/workflows/ci-post-merge.yml | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/ci-post-merge.yml b/.github/workflows/ci-post-merge.yml index 4ae925452..d37b2c107 100644 --- a/.github/workflows/ci-post-merge.yml +++ b/.github/workflows/ci-post-merge.yml @@ -152,3 +152,34 @@ jobs: # - name: Upload to Codecov # uses: codecov/codecov-action@v1 # with: { file: cobertura.xml } + + nextest: + name: nextest + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Generate Cargo.lock + uses: actions-rs/cargo@v1 + with: { command: generate-lockfile } + - name: Cache Dependencies + uses: Swatinem/rust-cache@v1.3.0 + + - name: Install cargo-nextest + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-nextest + + - name: Test with cargo-nextest + uses: actions-rs/cargo@v1 + with: + command: nextest + args: run From a808a26d8c55073866a3fb9fe339bf4456a5b82f Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 15 Feb 2022 20:49:10 +0000 Subject: [PATCH 18/27] bump actix-codec to 0.5 --- actix-http-test/Cargo.toml | 4 ++-- actix-http/Cargo.toml | 8 ++++---- actix-http/src/lib.rs | 2 ++ actix-test/Cargo.toml | 2 +- actix-web-actors/Cargo.toml | 2 +- actix-web/Cargo.toml | 2 +- awc/Cargo.toml | 6 +++--- docs/graphs/web-focus.dot | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/actix-http-test/Cargo.toml b/actix-http-test/Cargo.toml index e9986ef81..94e332177 100644 --- a/actix-http-test/Cargo.toml +++ b/actix-http-test/Cargo.toml @@ -30,8 +30,8 @@ openssl = ["tls-openssl", "awc/openssl"] [dependencies] actix-service = "2.0.0" -actix-codec = "0.4.1" -actix-tls = "3.0.0" +actix-codec = "0.5" +actix-tls = "3" actix-utils = "3.0.0" actix-rt = "2.2" actix-server = "2" diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index ba8f5fa1d..88eb6c3d2 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -20,7 +20,7 @@ edition = "2018" [package.metadata.docs.rs] # features that docs.rs will build with -features = ["openssl", "rustls", "compress-brotli", "compress-gzip", "compress-zstd"] +features = ["http2", "openssl", "rustls", "compress-brotli", "compress-gzip", "compress-zstd"] [lib] name = "actix_http" @@ -57,7 +57,7 @@ __compress = [] [dependencies] actix-service = "2" -actix-codec = "0.4.1" +actix-codec = "0.5" actix-utils = "3" actix-rt = { version = "2.2", default-features = false } @@ -89,7 +89,7 @@ rand = { version = "0.8", optional = true } sha-1 = { version = "0.10", optional = true } # openssl/rustls -actix-tls = { version = "3.0.0", default-features = false, optional = true } +actix-tls = { version = "3", default-features = false, optional = true } # compress-* brotli = { version = "3.3.3", optional = true } @@ -99,7 +99,7 @@ zstd = { version = "0.10", optional = true } [dev-dependencies] actix-http-test = { version = "3.0.0-beta.12", features = ["openssl"] } actix-server = "2" -actix-tls = { version = "3.0.0", features = ["openssl"] } +actix-tls = { version = "3", features = ["openssl"] } actix-web = "4.0.0-rc.3" async-stream = "0.3" diff --git a/actix-http/src/lib.rs b/actix-http/src/lib.rs index dbff89612..360cb86fc 100644 --- a/actix-http/src/lib.rs +++ b/actix-http/src/lib.rs @@ -3,6 +3,7 @@ //! ## Crate Features //! | Feature | Functionality | //! | ------------------- | ------------------------------------------- | +//! | `http2` | HTTP/2 support via [h2]. | //! | `openssl` | TLS support via [OpenSSL]. | //! | `rustls` | TLS support via [rustls]. | //! | `compress-brotli` | Payload compression support: Brotli. | @@ -10,6 +11,7 @@ //! | `compress-zstd` | Payload compression support: Zstd. | //! | `trust-dns` | Use [trust-dns] as the client DNS resolver. | //! +//! [h2]: https://crates.io/crates/h2 //! [OpenSSL]: https://crates.io/crates/openssl //! [rustls]: https://crates.io/crates/rustls //! [trust-dns]: https://crates.io/crates/trust-dns diff --git a/actix-test/Cargo.toml b/actix-test/Cargo.toml index 0f8aff074..26923258c 100644 --- a/actix-test/Cargo.toml +++ b/actix-test/Cargo.toml @@ -28,7 +28,7 @@ rustls = ["tls-rustls", "actix-http/rustls", "awc/rustls"] openssl = ["tls-openssl", "actix-http/openssl", "awc/openssl"] [dependencies] -actix-codec = "0.4.1" +actix-codec = "0.5" actix-http = "3.0.0-rc.2" actix-http-test = "3.0.0-beta.12" actix-rt = "2.1" diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index 0499e19e4..0f4bca534 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -15,7 +15,7 @@ path = "src/lib.rs" [dependencies] actix = { version = "0.12.0", default-features = false } -actix-codec = "0.4.1" +actix-codec = "0.5" actix-http = "3.0.0-rc.2" actix-web = { version = "4.0.0-rc.3", default-features = false } diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index 17b2f2356..f9ea36737 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -63,7 +63,7 @@ __compress = [] experimental-io-uring = ["actix-server/io-uring"] [dependencies] -actix-codec = "0.4.1" +actix-codec = "0.5" actix-macros = { version = "0.2.3", optional = true } actix-rt = { version = "2.6", default-features = false } actix-server = "2" diff --git a/awc/Cargo.toml b/awc/Cargo.toml index e9cc5d656..57a2b8c8b 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -58,11 +58,11 @@ __compress = [] dangerous-h2c = [] [dependencies] -actix-codec = "0.4.1" +actix-codec = "0.5" actix-service = "2.0.0" actix-http = { version = "3.0.0-rc.2", features = ["http2", "ws"] } actix-rt = { version = "2.1", default-features = false } -actix-tls = { version = "3.0.0", features = ["connect", "uri"] } +actix-tls = { version = "3", features = ["connect", "uri"] } actix-utils = "3.0.0" ahash = "0.7" @@ -97,7 +97,7 @@ actix-http = { version = "3.0.0-rc.2", features = ["openssl"] } actix-http-test = { version = "3.0.0-beta.12", features = ["openssl"] } actix-server = "2" actix-test = { version = "0.1.0-beta.12", features = ["openssl", "rustls"] } -actix-tls = { version = "3.0.0", features = ["openssl", "rustls"] } +actix-tls = { version = "3", features = ["openssl", "rustls"] } actix-utils = "3.0.0" actix-web = { version = "4.0.0-rc.3", features = ["openssl"] } diff --git a/docs/graphs/web-focus.dot b/docs/graphs/web-focus.dot index 16b2d415e..a8c800b48 100644 --- a/docs/graphs/web-focus.dot +++ b/docs/graphs/web-focus.dot @@ -34,7 +34,7 @@ digraph { "utils" -> { "service" "rt" "codec" } "tracing" -> { "service" } "tls" -> { "service" "codec" "utils" } - "server" -> { "service" "rt" "codec" "utils" } + "server" -> { "service" "rt" "utils" } "rt" -> { "macros" } { rank=same; "utils" "codec" }; From 594e3a6ef134d125bf8781eb88d33b41e6b38c60 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 16 Feb 2022 03:07:12 +0000 Subject: [PATCH 19/27] prepare actix-http release 3.0.0-rc.3 --- actix-files/Cargo.toml | 2 +- actix-http-test/Cargo.toml | 2 +- actix-http/CHANGES.md | 4 ++++ actix-http/Cargo.toml | 2 +- actix-http/README.md | 4 ++-- actix-multipart/Cargo.toml | 2 +- actix-test/Cargo.toml | 2 +- actix-web-actors/Cargo.toml | 2 +- actix-web/Cargo.toml | 2 +- awc/Cargo.toml | 4 ++-- 10 files changed, 15 insertions(+), 11 deletions(-) diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index 08bd2f359..2b0af10e7 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -22,7 +22,7 @@ path = "src/lib.rs" experimental-io-uring = ["actix-web/experimental-io-uring", "tokio-uring"] [dependencies] -actix-http = "3.0.0-rc.2" +actix-http = "3.0.0-rc.3" actix-service = "2" actix-utils = "3" actix-web = { version = "4.0.0-rc.3", default-features = false } diff --git a/actix-http-test/Cargo.toml b/actix-http-test/Cargo.toml index 94e332177..591acdc45 100644 --- a/actix-http-test/Cargo.toml +++ b/actix-http-test/Cargo.toml @@ -52,4 +52,4 @@ tokio = { version = "1.8.4", features = ["sync"] } [dev-dependencies] actix-web = { version = "4.0.0-rc.3", default-features = false, features = ["cookies"] } -actix-http = "3.0.0-rc.2" +actix-http = "3.0.0-rc.3" diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index e9191b0fe..c8581c0b5 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -3,6 +3,10 @@ ## Unreleased - 2021-xx-xx +## 3.0.0-rc.3 - 2022-02-16 +- No significant changes since `3.0.0-rc.2`. + + ## 3.0.0-rc.2 - 2022-02-08 ### Added - Implement `From>` for `Response>`. [#2625] diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 88eb6c3d2..6f2e2dbcf 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-http" -version = "3.0.0-rc.2" +version = "3.0.0-rc.3" authors = [ "Nikolay Kim ", "Rob Ede ", diff --git a/actix-http/README.md b/actix-http/README.md index d06db8422..c1aae63e1 100644 --- a/actix-http/README.md +++ b/actix-http/README.md @@ -3,11 +3,11 @@ > HTTP primitives for the Actix ecosystem. [![crates.io](https://img.shields.io/crates/v/actix-http?label=latest)](https://crates.io/crates/actix-http) -[![Documentation](https://docs.rs/actix-http/badge.svg?version=3.0.0-rc.2)](https://docs.rs/actix-http/3.0.0-rc.2) +[![Documentation](https://docs.rs/actix-http/badge.svg?version=3.0.0-rc.3)](https://docs.rs/actix-http/3.0.0-rc.3) [![Version](https://img.shields.io/badge/rustc-1.54+-ab6000.svg)](https://blog.rust-lang.org/2021/05/06/Rust-1.54.0.html) ![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-http.svg)
-[![dependency status](https://deps.rs/crate/actix-http/3.0.0-rc.2/status.svg)](https://deps.rs/crate/actix-http/3.0.0-rc.2) +[![dependency status](https://deps.rs/crate/actix-http/3.0.0-rc.3/status.svg)](https://deps.rs/crate/actix-http/3.0.0-rc.3) [![Download](https://img.shields.io/crates/d/actix-http.svg)](https://crates.io/crates/actix-http) [![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x) diff --git a/actix-multipart/Cargo.toml b/actix-multipart/Cargo.toml index 414c28862..91cc96904 100644 --- a/actix-multipart/Cargo.toml +++ b/actix-multipart/Cargo.toml @@ -28,7 +28,7 @@ twoway = "0.2" [dev-dependencies] actix-rt = "2.2" -actix-http = "3.0.0-rc.2" +actix-http = "3.0.0-rc.3" futures-util = { version = "0.3.7", default-features = false, features = ["alloc"] } tokio = { version = "1.8.4", features = ["sync"] } tokio-stream = "0.1" diff --git a/actix-test/Cargo.toml b/actix-test/Cargo.toml index 26923258c..3ba41b135 100644 --- a/actix-test/Cargo.toml +++ b/actix-test/Cargo.toml @@ -29,7 +29,7 @@ openssl = ["tls-openssl", "actix-http/openssl", "awc/openssl"] [dependencies] actix-codec = "0.5" -actix-http = "3.0.0-rc.2" +actix-http = "3.0.0-rc.3" actix-http-test = "3.0.0-beta.12" actix-rt = "2.1" actix-service = "2.0.0" diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index 0f4bca534..dd6791d60 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -16,7 +16,7 @@ path = "src/lib.rs" [dependencies] actix = { version = "0.12.0", default-features = false } actix-codec = "0.5" -actix-http = "3.0.0-rc.2" +actix-http = "3.0.0-rc.3" actix-web = { version = "4.0.0-rc.3", default-features = false } bytes = "1" diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index f9ea36737..8f952a917 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -71,7 +71,7 @@ actix-service = "2" actix-utils = "3" actix-tls = { version = "3", default-features = false, optional = true } -actix-http = { version = "3.0.0-rc.2", features = ["http2", "ws"] } +actix-http = { version = "3.0.0-rc.3", features = ["http2", "ws"] } actix-router = "0.5.0-rc.3" actix-web-codegen = { version = "0.5.0-rc.2", optional = true } diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 57a2b8c8b..3d3b3c921 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -60,7 +60,7 @@ dangerous-h2c = [] [dependencies] actix-codec = "0.5" actix-service = "2.0.0" -actix-http = { version = "3.0.0-rc.2", features = ["http2", "ws"] } +actix-http = { version = "3.0.0-rc.3", features = ["http2", "ws"] } actix-rt = { version = "2.1", default-features = false } actix-tls = { version = "3", features = ["connect", "uri"] } actix-utils = "3.0.0" @@ -93,7 +93,7 @@ tls-rustls = { package = "rustls", version = "0.20.0", optional = true, features trust-dns-resolver = { version = "0.20.0", optional = true } [dev-dependencies] -actix-http = { version = "3.0.0-rc.2", features = ["openssl"] } +actix-http = { version = "3.0.0-rc.3", features = ["openssl"] } actix-http-test = { version = "3.0.0-beta.12", features = ["openssl"] } actix-server = "2" actix-test = { version = "0.1.0-beta.12", features = ["openssl", "rustls"] } From a0c4bf8d1be8ab10efe7a7ba12456ff32d4ab0c9 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 16 Feb 2022 03:10:01 +0000 Subject: [PATCH 20/27] prepare awc release 3.0.0-beta.21 --- actix-http-test/Cargo.toml | 2 +- actix-test/Cargo.toml | 2 +- actix-web-actors/Cargo.toml | 2 +- actix-web/Cargo.toml | 2 +- awc/CHANGES.md | 4 ++++ awc/Cargo.toml | 2 +- awc/README.md | 4 ++-- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/actix-http-test/Cargo.toml b/actix-http-test/Cargo.toml index 591acdc45..0daefcd38 100644 --- a/actix-http-test/Cargo.toml +++ b/actix-http-test/Cargo.toml @@ -35,7 +35,7 @@ actix-tls = "3" actix-utils = "3.0.0" actix-rt = "2.2" actix-server = "2" -awc = { version = "3.0.0-beta.20", default-features = false } +awc = { version = "3.0.0-beta.21", default-features = false } base64 = "0.13" bytes = "1" diff --git a/actix-test/Cargo.toml b/actix-test/Cargo.toml index 3ba41b135..5fb51282e 100644 --- a/actix-test/Cargo.toml +++ b/actix-test/Cargo.toml @@ -35,7 +35,7 @@ actix-rt = "2.1" actix-service = "2.0.0" actix-utils = "3.0.0" actix-web = { version = "4.0.0-rc.3", default-features = false, features = ["cookies"] } -awc = { version = "3.0.0-beta.20", default-features = false, features = ["cookies"] } +awc = { version = "3.0.0-beta.21", default-features = false, features = ["cookies"] } futures-core = { version = "0.3.7", default-features = false, features = ["std"] } futures-util = { version = "0.3.7", default-features = false, features = [] } diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index dd6791d60..5634ec201 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -28,7 +28,7 @@ tokio = { version = "1.8.4", features = ["sync"] } [dev-dependencies] actix-rt = "2.2" actix-test = "0.1.0-beta.12" -awc = { version = "3.0.0-beta.20", default-features = false } +awc = { version = "3.0.0-beta.21", default-features = false } env_logger = "0.9" futures-util = { version = "0.3.7", default-features = false } diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index 8f952a917..d0d78431a 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -101,7 +101,7 @@ url = "2.1" [dev-dependencies] actix-files = "0.6.0-beta.16" actix-test = { version = "0.1.0-beta.12", features = ["openssl", "rustls"] } -awc = { version = "3.0.0-beta.20", features = ["openssl"] } +awc = { version = "3.0.0-beta.21", features = ["openssl"] } brotli = "3.3.3" const-str = "0.3" diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 05e524fad..3fd59512a 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -3,6 +3,10 @@ ## Unreleased - 2021-xx-xx +## 3.0.0-beta.21 - 2022-02-16 +- No significant changes since `3.0.0-beta.20`. + + ## 3.0.0-beta.20 - 2022-01-31 - No significant changes since `3.0.0-beta.19`. diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 3d3b3c921..960ff0689 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "awc" -version = "3.0.0-beta.20" +version = "3.0.0-beta.21" authors = [ "Nikolay Kim ", "fakeshadow <24548779@qq.com>", diff --git a/awc/README.md b/awc/README.md index 2546ceeec..4e97b1789 100644 --- a/awc/README.md +++ b/awc/README.md @@ -3,9 +3,9 @@ > Async HTTP and WebSocket client library. [![crates.io](https://img.shields.io/crates/v/awc?label=latest)](https://crates.io/crates/awc) -[![Documentation](https://docs.rs/awc/badge.svg?version=3.0.0-beta.20)](https://docs.rs/awc/3.0.0-beta.20) +[![Documentation](https://docs.rs/awc/badge.svg?version=3.0.0-beta.21)](https://docs.rs/awc/3.0.0-beta.21) ![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/awc) -[![Dependency Status](https://deps.rs/crate/awc/3.0.0-beta.20/status.svg)](https://deps.rs/crate/awc/3.0.0-beta.20) +[![Dependency Status](https://deps.rs/crate/awc/3.0.0-beta.21/status.svg)](https://deps.rs/crate/awc/3.0.0-beta.21) [![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x) ## Documentation & Resources From f5895d5effbc04d86c0054022ef2d93006a83042 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 16 Feb 2022 03:11:22 +0000 Subject: [PATCH 21/27] prepare actix-web-actors release 4.0.0-beta.12 --- actix-web-actors/CHANGES.md | 4 ++++ actix-web-actors/Cargo.toml | 2 +- actix-web-actors/README.md | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/actix-web-actors/CHANGES.md b/actix-web-actors/CHANGES.md index a8ff2701d..124fe23b1 100644 --- a/actix-web-actors/CHANGES.md +++ b/actix-web-actors/CHANGES.md @@ -3,6 +3,10 @@ ## Unreleased - 2021-xx-xx +## 4.0.0-beta.12 - 2022-02-16 +- No significant changes since `4.0.0-beta.11`. + + ## 4.0.0-beta.11 - 2022-01-31 - No significant changes since `4.0.0-beta.10`. diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index 5634ec201..de90d3cb0 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web-actors" -version = "4.0.0-beta.11" +version = "4.0.0-beta.12" authors = ["Nikolay Kim "] description = "Actix actors support for Actix Web" keywords = ["actix", "http", "web", "framework", "async"] diff --git a/actix-web-actors/README.md b/actix-web-actors/README.md index 4a491c29a..0964cb04e 100644 --- a/actix-web-actors/README.md +++ b/actix-web-actors/README.md @@ -3,11 +3,11 @@ > Actix actors support for Actix Web. [![crates.io](https://img.shields.io/crates/v/actix-web-actors?label=latest)](https://crates.io/crates/actix-web-actors) -[![Documentation](https://docs.rs/actix-web-actors/badge.svg?version=4.0.0-beta.11)](https://docs.rs/actix-web-actors/4.0.0-beta.11) +[![Documentation](https://docs.rs/actix-web-actors/badge.svg?version=4.0.0-beta.12)](https://docs.rs/actix-web-actors/4.0.0-beta.12) [![Version](https://img.shields.io/badge/rustc-1.54+-ab6000.svg)](https://blog.rust-lang.org/2021/05/06/Rust-1.54.0.html) ![License](https://img.shields.io/crates/l/actix-web-actors.svg)
-[![dependency status](https://deps.rs/crate/actix-web-actors/4.0.0-beta.11/status.svg)](https://deps.rs/crate/actix-web-actors/4.0.0-beta.11) +[![dependency status](https://deps.rs/crate/actix-web-actors/4.0.0-beta.12/status.svg)](https://deps.rs/crate/actix-web-actors/4.0.0-beta.12) [![Download](https://img.shields.io/crates/d/actix-web-actors.svg)](https://crates.io/crates/actix-web-actors) [![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x) From 38e015432bd2b37509545b09adb5c040bd4f0595 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 16 Feb 2022 03:13:22 +0000 Subject: [PATCH 22/27] prepare actix-http-test release 3.0.0-beta.13 --- actix-http-test/CHANGES.md | 4 ++++ actix-http-test/Cargo.toml | 2 +- actix-http-test/README.md | 4 ++-- actix-http/Cargo.toml | 2 +- actix-test/Cargo.toml | 2 +- awc/Cargo.toml | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/actix-http-test/CHANGES.md b/actix-http-test/CHANGES.md index a909b1d6a..3b98e0972 100644 --- a/actix-http-test/CHANGES.md +++ b/actix-http-test/CHANGES.md @@ -3,6 +3,10 @@ ## Unreleased - 2021-xx-xx +## 3.0.0-beta.13 - 2022-02-16 +- No significant changes since `3.0.0-beta.12`. + + ## 3.0.0-beta.12 - 2022-01-31 - No significant changes since `3.0.0-beta.11`. diff --git a/actix-http-test/Cargo.toml b/actix-http-test/Cargo.toml index 0daefcd38..2fb4a4f77 100644 --- a/actix-http-test/Cargo.toml +++ b/actix-http-test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-http-test" -version = "3.0.0-beta.12" +version = "3.0.0-beta.13" authors = ["Nikolay Kim "] description = "Various helpers for Actix applications to use during testing" keywords = ["http", "web", "framework", "async", "futures"] diff --git a/actix-http-test/README.md b/actix-http-test/README.md index bf9dddfa2..d11ae69b2 100644 --- a/actix-http-test/README.md +++ b/actix-http-test/README.md @@ -3,11 +3,11 @@ > Various helpers for Actix applications to use during testing. [![crates.io](https://img.shields.io/crates/v/actix-http-test?label=latest)](https://crates.io/crates/actix-http-test) -[![Documentation](https://docs.rs/actix-http-test/badge.svg?version=3.0.0-beta.12)](https://docs.rs/actix-http-test/3.0.0-beta.12) +[![Documentation](https://docs.rs/actix-http-test/badge.svg?version=3.0.0-beta.13)](https://docs.rs/actix-http-test/3.0.0-beta.13) [![Version](https://img.shields.io/badge/rustc-1.54+-ab6000.svg)](https://blog.rust-lang.org/2021/05/06/Rust-1.54.0.html) ![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-http-test)
-[![Dependency Status](https://deps.rs/crate/actix-http-test/3.0.0-beta.12/status.svg)](https://deps.rs/crate/actix-http-test/3.0.0-beta.12) +[![Dependency Status](https://deps.rs/crate/actix-http-test/3.0.0-beta.13/status.svg)](https://deps.rs/crate/actix-http-test/3.0.0-beta.13) [![Download](https://img.shields.io/crates/d/actix-http-test.svg)](https://crates.io/crates/actix-http-test) [![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x) diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 6f2e2dbcf..30ac4ce3a 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -97,7 +97,7 @@ flate2 = { version = "1.0.13", optional = true } zstd = { version = "0.10", optional = true } [dev-dependencies] -actix-http-test = { version = "3.0.0-beta.12", features = ["openssl"] } +actix-http-test = { version = "3.0.0-beta.13", features = ["openssl"] } actix-server = "2" actix-tls = { version = "3", features = ["openssl"] } actix-web = "4.0.0-rc.3" diff --git a/actix-test/Cargo.toml b/actix-test/Cargo.toml index 5fb51282e..92ecf86be 100644 --- a/actix-test/Cargo.toml +++ b/actix-test/Cargo.toml @@ -30,7 +30,7 @@ openssl = ["tls-openssl", "actix-http/openssl", "awc/openssl"] [dependencies] actix-codec = "0.5" actix-http = "3.0.0-rc.3" -actix-http-test = "3.0.0-beta.12" +actix-http-test = "3.0.0-beta.13" actix-rt = "2.1" actix-service = "2.0.0" actix-utils = "3.0.0" diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 960ff0689..31f6b9840 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -94,7 +94,7 @@ trust-dns-resolver = { version = "0.20.0", optional = true } [dev-dependencies] actix-http = { version = "3.0.0-rc.3", features = ["openssl"] } -actix-http-test = { version = "3.0.0-beta.12", features = ["openssl"] } +actix-http-test = { version = "3.0.0-beta.13", features = ["openssl"] } actix-server = "2" actix-test = { version = "0.1.0-beta.12", features = ["openssl", "rustls"] } actix-tls = { version = "3", features = ["openssl", "rustls"] } From 51e573b8882f44784a4eedad964ffbe046ef80cf Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 16 Feb 2022 03:13:41 +0000 Subject: [PATCH 23/27] prepare actix-test release 0.1.0-beta.13 --- actix-files/Cargo.toml | 2 +- actix-test/CHANGES.md | 4 ++++ actix-test/Cargo.toml | 2 +- actix-web-actors/Cargo.toml | 2 +- actix-web-codegen/Cargo.toml | 2 +- actix-web/Cargo.toml | 2 +- awc/Cargo.toml | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index 2b0af10e7..a006df953 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -43,6 +43,6 @@ tokio-uring = { version = "0.2", optional = true, features = ["bytes"] } [dev-dependencies] actix-rt = "2.2" -actix-test = "0.1.0-beta.12" +actix-test = "0.1.0-beta.13" actix-web = "4.0.0-rc.3" tempfile = "3.2" diff --git a/actix-test/CHANGES.md b/actix-test/CHANGES.md index 0c8fc996b..13e75c01a 100644 --- a/actix-test/CHANGES.md +++ b/actix-test/CHANGES.md @@ -3,6 +3,10 @@ ## Unreleased - 2021-xx-xx +## 0.1.0-beta.13 - 2022-02-16 +- No significant changes since `0.1.0-beta.12`. + + ## 0.1.0-beta.12 - 2022-01-31 - Rename `TestServerConfig::{client_timeout => client_request_timeout}`. [#2611] diff --git a/actix-test/Cargo.toml b/actix-test/Cargo.toml index 92ecf86be..21aeec1da 100644 --- a/actix-test/Cargo.toml +++ b/actix-test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-test" -version = "0.1.0-beta.12" +version = "0.1.0-beta.13" authors = [ "Nikolay Kim ", "Rob Ede ", diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index de90d3cb0..121c86eb7 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -27,7 +27,7 @@ tokio = { version = "1.8.4", features = ["sync"] } [dev-dependencies] actix-rt = "2.2" -actix-test = "0.1.0-beta.12" +actix-test = "0.1.0-beta.13" awc = { version = "3.0.0-beta.21", default-features = false } env_logger = "0.9" diff --git a/actix-web-codegen/Cargo.toml b/actix-web-codegen/Cargo.toml index d5492243e..e3ff61509 100644 --- a/actix-web-codegen/Cargo.toml +++ b/actix-web-codegen/Cargo.toml @@ -23,7 +23,7 @@ syn = { version = "1", features = ["full", "parsing"] } [dev-dependencies] actix-macros = "0.2.3" actix-rt = "2.2" -actix-test = "0.1.0-beta.12" +actix-test = "0.1.0-beta.13" actix-utils = "3.0.0" actix-web = "4.0.0-rc.3" diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index d0d78431a..938412090 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -100,7 +100,7 @@ url = "2.1" [dev-dependencies] actix-files = "0.6.0-beta.16" -actix-test = { version = "0.1.0-beta.12", features = ["openssl", "rustls"] } +actix-test = { version = "0.1.0-beta.13", features = ["openssl", "rustls"] } awc = { version = "3.0.0-beta.21", features = ["openssl"] } brotli = "3.3.3" diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 31f6b9840..7076897b1 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -96,7 +96,7 @@ trust-dns-resolver = { version = "0.20.0", optional = true } actix-http = { version = "3.0.0-rc.3", features = ["openssl"] } actix-http-test = { version = "3.0.0-beta.13", features = ["openssl"] } actix-server = "2" -actix-test = { version = "0.1.0-beta.12", features = ["openssl", "rustls"] } +actix-test = { version = "0.1.0-beta.13", features = ["openssl", "rustls"] } actix-tls = { version = "3", features = ["openssl", "rustls"] } actix-utils = "3.0.0" actix-web = { version = "4.0.0-rc.3", features = ["openssl"] } From 52f7d96358e6c2e6f02953e1096cfd6fa0a3f542 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Thu, 17 Feb 2022 19:13:03 +0000 Subject: [PATCH 24/27] tweak migration document --- actix-web/MIGRATION-4.0.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index 01aa642bd..b013f12b2 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -48,7 +48,7 @@ cargo tree -i tokio:0.2.25 ## Module Structure -Lots of modules has been organized in this release. If a compile error refers to "item XYZ not found in module..." or "module XYZ not found", refer to the [documentation on docs.rs](https://docs.rs/actix-web) to to search for items' new locations. +Lots of modules has been organized in this release. If a compile error refers to "item XYZ not found in module..." or "module XYZ not found", refer to the [documentation on docs.rs](https://docs.rs/actix-web) to search for items' new locations. ## `NormalizePath` Middleware :warning: @@ -289,7 +289,14 @@ web::to(|| HttpResponse::Ok().finish()) ^^^^^^^ the trait `Handler<_>` is not implemented for `[closure@...]` ``` -This form should be replaced with the a more explicit async fn: +This form should be replaced with explicit async functions and closures: + +```diff +- fn handler() -> HttpResponse { ++ async fn handler() -> HttpResponse { + HttpResponse::Ok().finish() + } +``` ```diff - web::to(|| HttpResponse::Ok().finish()) From f843776f361bce3fd7e0f653e6add738faddc793 Mon Sep 17 00:00:00 2001 From: Xavier Lange Date: Thu, 17 Feb 2022 22:34:12 -0500 Subject: [PATCH 25/27] Fix links in README (#2653) --- actix-web/README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/actix-web/README.md b/actix-web/README.md index 4adeb3910..188c0df28 100644 --- a/actix-web/README.md +++ b/actix-web/README.md @@ -77,14 +77,18 @@ async fn main() -> std::io::Result<()> { - [Application State](https://github.com/actix/examples/tree/master/basics/state/) - [JSON Handling](https://github.com/actix/examples/tree/master/json/json/) - [Multipart Streams](https://github.com/actix/examples/tree/master/forms/multipart/) -- [Diesel Integration](https://github.com/actix/examples/tree/master/database_interactions/diesel/) -- [r2d2 Integration](https://github.com/actix/examples/tree/master/database_interactions/r2d2/) -- [Simple WebSocket](https://github.com/actix/examples/tree/master/websockets/websocket/) -- [Tera Templates](https://github.com/actix/examples/tree/master/template_engines/tera/) -- [Askama Templates](https://github.com/actix/examples/tree/master/template_engines/askama/) -- [HTTPS using Rustls](https://github.com/actix/examples/tree/master/security/rustls/) -- [HTTPS using OpenSSL](https://github.com/actix/examples/tree/master/security/openssl/) +- [Diesel Integration](https://github.com/actix/examples/tree/master/databases/diesel/) +- [MongoDB Integration](https://github.com/actix/examples/tree/master/databases/mongodb/) +- [Postgres Integration](https://github.com/actix/examples/tree/master/databases/postgres/) +- [Rbatis Integration](https://github.com/actix/examples/tree/master/databases/rbatis/) +- [Redis Integration](https://github.com/actix/examples/tree/master/databases/redis/) +- [SQLite Integration](https://github.com/actix/examples/tree/master/databases/sqlite/) +- [Simple WebSocket](https://github.com/actix/examples/tree/master/websockets/) - [WebSocket Chat](https://github.com/actix/examples/tree/master/websockets/chat/) +- [Tera Templates](https://github.com/actix/examples/tree/master/templating/tera/) +- [Askama Templates](https://github.com/actix/examples/tree/master/templating/askama/) +- [HTTPS using Rustls](https://github.com/actix/examples/tree/master/https-tls/rustls/) +- [HTTPS using OpenSSL](https://github.com/actix/examples/tree/master/https-tls/openssl/) You may consider checking out [this directory](https://github.com/actix/examples/tree/master/) for more examples. From b291e298822ed60234f060e3ec41fee2526b66c2 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 18 Feb 2022 03:41:10 +0000 Subject: [PATCH 26/27] fix links --- actix-files/README.md | 4 ++-- actix-web/MIGRATION-4.0.md | 2 +- actix-web/README.md | 37 +++++++++++++++----------------- actix-web/examples/on-connect.rs | 2 +- awc/README.md | 2 +- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/actix-files/README.md b/actix-files/README.md index 669efc0ab..8ac80860e 100644 --- a/actix-files/README.md +++ b/actix-files/README.md @@ -13,6 +13,6 @@ ## Documentation & Resources -- [API Documentation](https://docs.rs/actix-files/) -- [Example Project](https://github.com/actix/examples/tree/master/basics/static_index) +- [API Documentation](https://docs.rs/actix-files) +- [Example Project](https://github.com/actix/examples/tree/master/basics/static-files) - Minimum Supported Rust Version (MSRV): 1.54 diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index b013f12b2..e33aee4a3 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -104,7 +104,7 @@ The inner field for `web::Path` was made private because It was causing too many ## Rustls Crate Upgrade -Required version of `rustls` dependency was bumped to the latest version 0.20. As a result, the new server config builder has changed. [See the updated example project →.](https://github.com/actix/examples/tree/HEAD/security/rustls/) +Required version of `rustls` dependency was bumped to the latest version 0.20. As a result, the new server config builder has changed. [See the updated example project →.](https://github.com/actix/examples/tree/master/https-tls/rustls/) ## Removed `awc` Client Re-export diff --git a/actix-web/README.md b/actix-web/README.md index 188c0df28..e66224524 100644 --- a/actix-web/README.md +++ b/actix-web/README.md @@ -71,26 +71,24 @@ async fn main() -> std::io::Result<()> { } ``` -### More examples +### More Examples -- [Basic Setup](https://github.com/actix/examples/tree/master/basics/basics/) -- [Application State](https://github.com/actix/examples/tree/master/basics/state/) -- [JSON Handling](https://github.com/actix/examples/tree/master/json/json/) -- [Multipart Streams](https://github.com/actix/examples/tree/master/forms/multipart/) -- [Diesel Integration](https://github.com/actix/examples/tree/master/databases/diesel/) -- [MongoDB Integration](https://github.com/actix/examples/tree/master/databases/mongodb/) -- [Postgres Integration](https://github.com/actix/examples/tree/master/databases/postgres/) -- [Rbatis Integration](https://github.com/actix/examples/tree/master/databases/rbatis/) -- [Redis Integration](https://github.com/actix/examples/tree/master/databases/redis/) -- [SQLite Integration](https://github.com/actix/examples/tree/master/databases/sqlite/) -- [Simple WebSocket](https://github.com/actix/examples/tree/master/websockets/) -- [WebSocket Chat](https://github.com/actix/examples/tree/master/websockets/chat/) -- [Tera Templates](https://github.com/actix/examples/tree/master/templating/tera/) -- [Askama Templates](https://github.com/actix/examples/tree/master/templating/askama/) -- [HTTPS using Rustls](https://github.com/actix/examples/tree/master/https-tls/rustls/) -- [HTTPS using OpenSSL](https://github.com/actix/examples/tree/master/https-tls/openssl/) +- [Hello World](https://github.com/actix/examples/tree/master/basics/hello-world) +- [Basic Setup](https://github.com/actix/examples/tree/master/basics/basics) +- [Application State](https://github.com/actix/examples/tree/master/basics/state) +- [JSON Handling](https://github.com/actix/examples/tree/master/json/json) +- [Multipart Streams](https://github.com/actix/examples/tree/master/forms/multipart) +- [Diesel Integration](https://github.com/actix/examples/tree/master/databases/diesel) +- [SQLite Integration](https://github.com/actix/examples/tree/master/databases/sqlite) +- [Postgres Integration](https://github.com/actix/examples/tree/master/databases/postgres) +- [Tera Templates](https://github.com/actix/examples/tree/master/templating/tera) +- [Askama Templates](https://github.com/actix/examples/tree/master/templating/askama) +- [HTTPS using Rustls](https://github.com/actix/examples/tree/master/https-tls/rustls) +- [HTTPS using OpenSSL](https://github.com/actix/examples/tree/master/https-tls/openssl) +- [Simple WebSocket](https://github.com/actix/examples/tree/master/websockets) +- [WebSocket Chat](https://github.com/actix/examples/tree/master/websockets/chat) -You may consider checking out [this directory](https://github.com/actix/examples/tree/master/) for more examples. +You may consider checking out [this directory](https://github.com/actix/examples/tree/master) for more examples. ## Benchmarks @@ -105,5 +103,4 @@ This project is licensed under either of the following licenses, at your option: ## Code of Conduct -Contribution to the actix-web repo is organized under the terms of the Contributor Covenant. -The Actix team promises to intervene to uphold that code of conduct. +Contribution to the actix-web repo is organized under the terms of the Contributor Covenant. The Actix team promises to intervene to uphold that code of conduct. diff --git a/actix-web/examples/on-connect.rs b/actix-web/examples/on-connect.rs index d76e9ce56..24c6f8418 100644 --- a/actix-web/examples/on-connect.rs +++ b/actix-web/examples/on-connect.rs @@ -2,7 +2,7 @@ //! properties and pass them to a handler through request-local data. //! //! For an example of extracting a client TLS certificate, see: -//! +//! use std::{any::Any, io, net::SocketAddr}; diff --git a/awc/README.md b/awc/README.md index 4e97b1789..417647e62 100644 --- a/awc/README.md +++ b/awc/README.md @@ -11,7 +11,7 @@ ## Documentation & Resources - [API Documentation](https://docs.rs/awc) -- [Example Project](https://github.com/actix/examples/tree/HEAD/security/awc_https) +- [Example Project](https://github.com/actix/examples/tree/master/https-tls/awc-https) - Minimum Supported Rust Version (MSRV): 1.54 ## Example From f94065398138a74c317373e59ab9e0937322b89c Mon Sep 17 00:00:00 2001 From: Luca Palmieri Date: Sat, 19 Feb 2022 17:05:54 +0000 Subject: [PATCH 27/27] Edits to the migration notes (#2654) --- actix-web/MIGRATION-4.0.md | 64 +++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index e33aee4a3..b5109e3f2 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -1,10 +1,12 @@ # Migrating to 4.0.0 -It is assumed that migration is happening _from_ v3.x. If migration from older version of Actix Web, see the other historical migration notes in this folder. +This guide walks you through the process of migrating from v3.x.y to v4.x.y. +If you are migrating to v4.x.y from an older version of Actix Web (v2.x.y or earlier), check out the other historical migration notes in this folder. -This is not an exhaustive list of changes. Smaller or less impactful code changes are outlined, with links to the PRs that introduced them, in [CHANGES.md](./CHANGES.md). If you think any of the changes not mentioned here deserve to be, submit an issue or PR. +This document is not designed to be exhaustive - it focuses on the most significant changes coming in v4. +You can find an exhaustive changelog in [CHANGES.md](./CHANGES.md), complete of PR links. If you think that some of the changes that we omitted deserve to be called out in this document, please open an issue or submit a PR. -Headings marked with :warning: are **breaking behavioral changes** that will probably not surface as compile-time errors though automated tests _might_ detect their effects on your app. +Headings marked with :warning: are **breaking behavioral changes**. They will probably not surface as compile-time errors though automated tests _might_ detect their effects on your app. ## Table of Contents: @@ -37,22 +39,29 @@ The MSRV of Actix Web has been raised from 1.42 to 1.54. ## Tokio v1 Ecosystem -Actix Web v4 is now underpinned by the the Tokio v1 ecosystem of crates. If you have dependencies that might utilize Tokio directly, it is worth checking to see if an update is available. The following command will assist in finding such dependencies: +Actix Web v4 is now underpinned by `tokio`'s v1 ecosystem. +`cargo` supports having multiple versions of the same crate within the same dependency tree, but `tokio` v1 does not interoperate transparently with its previous versions (v0.2, v0.1). Some of your dependencies might rely on `tokio`, either directly or indirectly - if they are using an older version of `tokio`, check if an update is available. +The following command can help you to identify these dependencies: ```sh +# Find all crates in your dependency tree that depend on `tokio` +# It also reports the different versions of `tokio` in your dependency tree. cargo tree -i tokio -# if multiple tokio versions are depended on, show the older ones with: +# if you depend on multiple versions of tokio, use this command to +# list the dependencies relying on a specific version of tokio: cargo tree -i tokio:0.2.25 ``` ## Module Structure -Lots of modules has been organized in this release. If a compile error refers to "item XYZ not found in module..." or "module XYZ not found", refer to the [documentation on docs.rs](https://docs.rs/actix-web) to search for items' new locations. +Lots of modules have been re-organized in this release. If a compile error refers to "item XYZ not found in module..." or "module XYZ not found", check the [documentation on docs.rs](https://docs.rs/actix-web) to search for items' new locations. ## `NormalizePath` Middleware :warning: -The default `NormalizePath` behavior now strips trailing slashes by default. This was previously documented to be the case in v3 but the behavior now matches. The effect is that routes defined with trailing slashes will become inaccessible when using `NormalizePath::default()`. As such, calling `NormalizePath::default()` will log a warning. It is advised that the `new` or `trim` methods be used instead. +The default `NormalizePath` behavior now strips trailing slashes by default. +This was the _documented_ behaviour in Actix Web v3, but the _actual_ behaviour differed - the discrepancy has now been fixed. +As a consequence of this change, routes defined with trailing slashes will become inaccessible when using `NormalizePath::default()`. Calling `NormalizePath::default()` will log a warning. We suggest to use `new` or `trim`. ```diff - #[get("/test/")] @@ -86,7 +95,7 @@ Consequently, the `FromRequest::configure` method was also removed. Config for e ## Compression Feature Flags -Feature flag `compress` has been split into its supported algorithm (brotli, gzip, zstd). By default, all compression algorithms are enabled. If you want to select specific compression codecs, the new flags are: +The `compress` feature flag has been split into more granular feature flags, one for each supported algorithm (brotli, gzip, zstd). By default, all compression algorithms are enabled. If you want to select specific compression codecs, the new flags are: - `compress-brotli` - `compress-gzip` @@ -94,7 +103,8 @@ Feature flag `compress` has been split into its supported algorithm (brotli, gzi ## `web::Path` -The inner field for `web::Path` was made private because It was causing too many issues when used with inner tuple types due to its `Deref` impl. +The inner field for `web::Path` is now private. +It was causing too many issues when used with inner tuple types due to its `Deref` implementation. ```diff - async fn handler(web::Path((foo, bar)): web::Path<(String, String)>) { @@ -104,11 +114,11 @@ The inner field for `web::Path` was made private because It was causing too many ## Rustls Crate Upgrade -Required version of `rustls` dependency was bumped to the latest version 0.20. As a result, the new server config builder has changed. [See the updated example project →.](https://github.com/actix/examples/tree/master/https-tls/rustls/) +Actix Web now depends on version 0.20 of `rustls`. As a result, the server config builder has changed. [See the updated example project.](https://github.com/actix/examples/tree/master/https-tls/rustls/) ## Removed `awc` Client Re-export -Actix Web's sister crate `awc` is no longer re-exported through the `client` module. This allows `awc` its own release cadence and prevents its own breaking changes from being blocked due to a re-export. +Actix Web's sister crate `awc` is no longer re-exported through the `client` module. This allows `awc` to have its own release cadence - its breaking changes are no longer blocked by Actix Web's (more conservative) release schedule. ```diff - use actix_web::client::Client; @@ -117,18 +127,20 @@ Actix Web's sister crate `awc` is no longer re-exported through the `client` mod ## Integration Testing Utils Moved To `actix-test` -Actix Web's `test` module used to contain `TestServer`. Since this required the `awc` client and it was removed as a re-export (see above), it was moved to its own crate [`actix-test`](https://docs.rs/actix-test). +`TestServer` has been moved to its own crate, [`actix-test`](https://docs.rs/actix-test). ```diff - use use actix_web::test::start; + use use actix_test::start; ``` +`TestServer` previously lived in `actix_web::test`, but it depends on `awc` which is no longer part of Actix Web's public API (see above). + ## Header APIs -Header related APIs have been standardized across all `actix-*` crates. The terminology now better matches the underlying `HeaderMap` naming conventions. Most of the the old methods have only been deprecated with notes that will guide how to update. +Header related APIs have been standardized across all `actix-*` crates. The terminology now better matches the underlying `HeaderMap` naming conventions. -In short, "insert" always indicates that existing any existing headers with the same name are overridden and "append" indicates adding with no removal. +In short, "insert" always indicates that any existing headers with the same name are overridden, while "append" is used for adding with no removal (e.g. multi-valued headers). For request and response builder APIs, the new methods provide a unified interface for adding key-value pairs _and_ typed headers, which can often be more expressive. @@ -143,11 +155,13 @@ For request and response builder APIs, the new methods provide a unified interfa + .insert_header(ContentType::json()) ``` +We chose to deprecate most of the old methods instead of removing them immediately - the warning notes will guide you on how to update. + ## Response Body Types -There have been a lot of changes to response body types. The general theme is that they are now more expressive and their purposes are more obvious. +There have been a lot of changes to response body types. They are now more expressive and their purpose should be more intuitive. -All items in the [`body` module](https://docs.rs/actix-web/4/actix_web/body) have much better documentation now. +We have boosted the quality and completeness of the documentation for all items in the [`body` module](https://docs.rs/actix-web/4/actix_web/body). ### `ResponseBody` @@ -164,11 +178,12 @@ All items in the [`body` module](https://docs.rs/actix-web/4/actix_web/body) hav ### `BoxBody` -`BoxBody` is a new type erased body type. It's used for all error response bodies use this. Creating a boxed body is best done by calling [`.boxed()`](https://docs.rs/actix-web/4/actix_web/body/trait.MessageBody.html#method.boxed) on a `MessageBody` type. +`BoxBody` is a new type-erased body type. It's used for all error response bodies. +Creating a boxed body is best done by calling [`.boxed()`](https://docs.rs/actix-web/4/actix_web/body/trait.MessageBody.html#method.boxed) on a `MessageBody` type. ### `EitherBody` -`EitherBody` is a new "either" type that is particularly useful in middleware that can bail early, returning their own response plus body type. +`EitherBody` is a new "either" type that is particularly useful in middlewares that can bail early, returning their own response plus body type. ### Error Handlers @@ -208,7 +223,7 @@ Now that more emphasis is placed on expressive body types, as explained in the [ ## `App::data` Deprecation :warning: -The `App::data` method is deprecated. Replace instances of this with `App::app_data`. Exposing both methods was a footgun and lead to lots of confusion when trying to extract the data in handlers. Now, when using the `Data` wrapper, the type you put in to `app_data` is the same type you extract in handler arguments. +The `App::data` method is deprecated. Replace instances of this with `App::app_data`. Exposing both methods led to lots of confusion when trying to extract the data in handlers. Now, when using the `Data` wrapper, the type you put in to `app_data` is the same type you extract in handler arguments. You may need to review the [guidance on shared mutable state](https://docs.rs/actix-web/4/actix_web/struct.App.html#shared-mutable-state) in order to migrate this correctly. @@ -233,7 +248,12 @@ You may need to review the [guidance on shared mutable state](https://docs.rs/ac ## Direct Dependency On `actix-rt` And `actix-service` -Improvements to module management and re-exports have resulted in not needing direct dependencies on these underlying crates for the vast majority of cases. In particular, all traits necessary for creating middleware are re-exported through the `dev` modules and `#[actix_web::test]` now exists for async test definitions. Relying on the these re-exports will ease transition to future versions of Actix Web. +Improvements to module management and re-exports have resulted in not needing direct dependencies on these underlying crates for the vast majority of cases. In particular: + +- all traits necessary for creating middlewares are now re-exported through the `dev` modules; +- `#[actix_web::test]` now exists for async test definitions. + +Relying on these re-exports will ease the transition to future versions of Actix Web. ```diff - use actix_service::{Service, Transform}; @@ -266,7 +286,7 @@ async fn main() { ## Guards API -Implementors of routing guards will need to use the modified interface of the `Guard` trait. The API provided is more flexible than before. See [guard module docs](https://docs.rs/actix-web/4/actix_web/guard/struct.GuardContext.html) for more details. +Implementors of routing guards will need to use the modified interface of the `Guard` trait. The API is more flexible than before. See [guard module docs](https://docs.rs/actix-web/4/actix_web/guard/struct.GuardContext.html) for more details. ```diff struct MethodGuard(HttpMethod); @@ -312,7 +332,7 @@ Or, for these extremely simple cases, utilise an `HttpResponseBuilder`: ## `#[actix_web::main]` and `#[tokio::main]` -Actix Web now works seamlessly with the primary way of starting a multi-threaded Tokio runtime, `#[tokio::main]`. Therefore, it is no longer necessary to spawn a thread when you need to run something alongside Actix Web that uses of Tokio's multi-threaded mode; you can simply await the server within this context or, if preferred, use `tokio::spawn` just like any other async task. +Actix Web now works seamlessly with the primary way of starting a multi-threaded Tokio runtime, `#[tokio::main]`. Therefore, it is no longer necessary to spawn a thread when you need to run something alongside Actix Web that uses Tokio's multi-threaded mode; you can simply await the server within this context or, if preferred, use `tokio::spawn` just like any other async task. For now, `actix` actor support (and therefore WebSocket support via `actix-web-actors`) still requires `#[actix_web::main]` so that a `System` context is created. Designs are being created for an alternative WebSocket interface that does not require actors that should land sometime in the v4.x cycle.