1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-22 01:21:10 +00:00

update 4.0 migration guide

This commit is contained in:
Rob Ede 2022-02-02 03:42:07 +00:00
parent 391d8a744a
commit 075df88a07
No known key found for this signature in database
GPG key ID: 97C636207D3EF933
3 changed files with 70 additions and 13 deletions

3
.prettierrc.json Normal file
View file

@ -0,0 +1,3 @@
{
"proseWrap": "never"
}

View file

@ -292,7 +292,6 @@
### Changed
- Adjusted default JSON payload limit to 2MB (from 32kb) and included size and limits in the `JsonPayloadError::Overflow` error variant. [#2162]
[#2162]: (https://github.com/actix/actix-web/pull/2162)
- `ServiceResponse::error_response` now uses body type of `Body`. [#2201]
- `ServiceResponse::checked_expr` now returns a `Result`. [#2201]
- Update `language-tags` to `0.3`.
@ -300,12 +299,13 @@
- `ServiceResponse::map_body` closure receives and returns `B` instead of `ResponseBody<B>` types. [#2201]
- All error trait bounds in server service builders have changed from `Into<Error>` to `Into<Response<AnyBody>>`. [#2253]
- All error trait bounds in message body and stream impls changed from `Into<Error>` to `Into<Box<dyn std::error::Error>>`. [#2253]
- `HttpServer::{listen_rustls(), bind_rustls()}` now honor the ALPN protocols in the configuation parameter. [#2226]
- `HttpServer::{listen_rustls(), bind_rustls()}` now honor the ALPN protocols in the configuration parameter. [#2226]
- `middleware::normalize` now will not try to normalize URIs with no valid path [#2246]
### Removed
- `HttpResponse::take_body` and old `HttpResponse::into_body` method that casted body type. [#2201]
[#2162]: https://github.com/actix/actix-web/pull/2162
[#2200]: https://github.com/actix/actix-web/pull/2200
[#2201]: https://github.com/actix/actix-web/pull/2201
[#2253]: https://github.com/actix/actix-web/pull/2253
@ -314,7 +314,7 @@
## 4.0.0-beta.6 - 2021-04-17
### Added
- `HttpResponse` and `HttpResponseBuilder` structs. [#2065]
- `HttpResponse` and `HttpResponseBuilder` types. [#2065]
### Changed
- Most error types are now marked `#[non_exhaustive]`. [#2148]
@ -329,13 +329,13 @@
- `Header` extractor for extracting common HTTP headers in handlers. [#2094]
- Added `TestServer::client_headers` method. [#2097]
### Fixed
- Double ampersand in Logger format is escaped correctly. [#2067]
### Changed
- `CustomResponder` would return error as `HttpResponse` when `CustomResponder::with_header` failed
instead of skipping. (Only the first error is kept when multiple error occur) [#2093]
### Fixed
- Double ampersand in Logger format is escaped correctly. [#2067]
### Removed
- The `client` mod was removed. Clients should now use `awc` directly.
[871ca5e4](https://github.com/actix/actix-web/commit/871ca5e4ae2bdc22d1ea02701c2992fa8d04aed7)
@ -422,7 +422,7 @@
- Added the underlying parse error to `test::read_body_json`'s panic message. [#1812]
### Removed
- Public modules `middleware::{normalize, err_handlers}`. All necessary middleware structs are now
- Public modules `middleware::{normalize, err_handlers}`. All necessary middleware types are now
exposed directly by the `middleware` module.
- Remove `actix-threadpool` as dependency. `actix_threadpool::BlockingError` error type can be imported
from `actix_web::error` module. [#1878]

View file

@ -2,6 +2,8 @@
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.
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.
## Table of Contents:
@ -26,8 +28,6 @@ Lots of modules has been organized in this release. If a compile error refers to
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.
### Recommended Migration
```diff
- #[get("/test/")]`
+ #[get("/test")]`
@ -44,8 +44,6 @@ Alternatively, explicitly require trailing slashes: `NormalizePath::new(Trailing
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.
### Recommended Migration
```diff
impl FromRequest for MyExtractor {
- `type Config = ();`
@ -66,8 +64,6 @@ If you have set in your `Cargo.toml` dedicated `actix-web` features and you stil
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)>) {
@ -77,3 +73,61 @@ 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 &rarr;.](https://github.com/actix/examples/tree/HEAD/security/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.
```diff
- use actix_web::client::Client;
+ use awc::Client;
```
## 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).
```diff
- use use actix_web::test::start;
+ use use actix_test::start;
```
## Header APIs
TODO
## Body Types / Removal of Body+ResponseBody types / Addition of EitherBody
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
TODO
TODO: Also write the Middleware author's guide.
## `Responder` Trait
TODO
## `App::data` deprecation
TODO
## It's probably not necessary to import `actix-rt` or `actix-service` any more
TODO
## Server must be awaited in order to run :warning:
TODO
## Guards API
TODO
## HttpResponse no longer implements Future
TODO