From 5b6cb681b9481f5db2cb56ff3789fcff11750985 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 2 Feb 2022 03:09:33 +0000 Subject: [PATCH] update 4.0 migration guide --- actix-web/MIGRATION-4.0.md | 57 +++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/actix-web/MIGRATION-4.0.md b/actix-web/MIGRATION-4.0.md index e1448387..e2517015 100644 --- a/actix-web/MIGRATION-4.0.md +++ b/actix-web/MIGRATION-4.0.md @@ -1,32 +1,53 @@ # 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 historical migration notes](./MIGRATION-3.0.md). +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. -## Rustls Upgrade +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. -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/) +## Table of Contents: -### `NormalizePath` middleware +- [MSRV](#MSRV) +- [Module Structure](#Module-Structure) + +## MSRV + +The MSRV of Actix Web has been raised from 1.42 to 1.54. + +## 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. + +## :warning: `NormalizePath` middleware 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. -#### Migration Diff +### Recommended Migration ```diff - #[get("/test/")]` + #[get("/test")]` + async fn handler() { -- .wrap(NormalizePath::default())` -+ .wrap(NormalizePath::trim())` + App::new() +- .wrap(NormalizePath::default())` ++ .wrap(NormalizePath::trim())` ``` Alternatively, explicitly require trailing slashes: `NormalizePath::new(TrailingSlash::Always)`. -### `FromRequest` trait +## `FromRequest` Trait -The associated type `Config` of `FromRequest` was removed. +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. -### Compression Feature Flags +### Recommended Migration + +```diff + impl FromRequest for MyExtractor { +- `type Config = ();` + } +``` + +## 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: @@ -35,3 +56,19 @@ Feature flag `compress` has been split into its supported algorithm (brotli, gzi - `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. + +### Recommended Migration + +```diff +- async fn handler(web::Path((foo, bar)): web::Path<(String, String)>) { ++ async fn handler(params: web::Path<(String, String)>) { ++ let (foo, bar) = params.into_inner(); +``` + +## 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/)