mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-17 06:56:51 +02:00
Compare commits
15 Commits
http-v3.0.
...
http-test-
Author | SHA1 | Date | |
---|---|---|---|
|
51e573b888 | ||
|
38e015432b | ||
|
f5895d5eff | ||
|
a0c4bf8d1b | ||
|
594e3a6ef1 | ||
|
a808a26d8c | ||
|
de62e8b025 | ||
|
3486edabcf | ||
|
4c59a34513 | ||
|
1b706b3069 | ||
|
a9f445875a | ||
|
e0f02c1d9e | ||
|
092dbba5b9 | ||
|
ff4b2d251f | ||
|
98faa61afe |
31
.github/workflows/ci-post-merge.yml
vendored
31
.github/workflows/ci-post-merge.yml
vendored
@@ -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
|
||||
|
@@ -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 }
|
||||
@@ -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"
|
||||
|
@@ -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`.
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-http-test"
|
||||
version = "3.0.0-beta.12"
|
||||
version = "3.0.0-beta.13"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Various helpers for Actix applications to use during testing"
|
||||
keywords = ["http", "web", "framework", "async", "futures"]
|
||||
@@ -30,12 +30,12 @@ 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"
|
||||
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"
|
||||
@@ -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"
|
||||
|
@@ -3,11 +3,11 @@
|
||||
> Various helpers for Actix applications to use during testing.
|
||||
|
||||
[](https://crates.io/crates/actix-http-test)
|
||||
[](https://docs.rs/actix-http-test/3.0.0-beta.12)
|
||||
[](https://docs.rs/actix-http-test/3.0.0-beta.13)
|
||||
[](https://blog.rust-lang.org/2021/05/06/Rust-1.54.0.html)
|
||||

|
||||
<br>
|
||||
[](https://deps.rs/crate/actix-http-test/3.0.0-beta.12)
|
||||
[](https://deps.rs/crate/actix-http-test/3.0.0-beta.13)
|
||||
[](https://crates.io/crates/actix-http-test)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
|
@@ -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<Vec<u8>>` for `Response<Vec<u8>>`. [#2625]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-http"
|
||||
version = "3.0.0-rc.2"
|
||||
version = "3.0.0-rc.3"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
@@ -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 }
|
||||
@@ -97,9 +97,9 @@ 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.0.0", features = ["openssl"] }
|
||||
actix-tls = { version = "3", features = ["openssl"] }
|
||||
actix-web = "4.0.0-rc.3"
|
||||
|
||||
async-stream = "0.3"
|
||||
|
@@ -3,11 +3,11 @@
|
||||
> HTTP primitives for the Actix ecosystem.
|
||||
|
||||
[](https://crates.io/crates/actix-http)
|
||||
[](https://docs.rs/actix-http/3.0.0-rc.2)
|
||||
[](https://docs.rs/actix-http/3.0.0-rc.3)
|
||||
[](https://blog.rust-lang.org/2021/05/06/Rust-1.54.0.html)
|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-http/3.0.0-rc.2)
|
||||
[](https://deps.rs/crate/actix-http/3.0.0-rc.3)
|
||||
[](https://crates.io/crates/actix-http)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
|
@@ -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<stream::Empty<Result<Bytes, Infallible>>>: MessageBody);
|
||||
assert_impl_all!(BodyStream<stream::Repeat<Result<Bytes, Infallible>>>: MessageBody);
|
||||
|
||||
assert_not_impl_all!(BodyStream<stream::Empty<Bytes>>: MessageBody);
|
||||
assert_not_impl_all!(BodyStream<stream::Repeat<Bytes>>: MessageBody);
|
||||
assert_not_impl_any!(BodyStream<stream::Empty<Bytes>>: MessageBody);
|
||||
assert_not_impl_any!(BodyStream<stream::Repeat<Bytes>>: MessageBody);
|
||||
// crate::Error is not Clone
|
||||
assert_not_impl_all!(BodyStream<stream::Repeat<Result<Bytes, crate::Error>>>: MessageBody);
|
||||
assert_not_impl_any!(BodyStream<stream::Repeat<Result<Bytes, crate::Error>>>: MessageBody);
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn skips_empty_chunks() {
|
||||
|
@@ -105,14 +105,13 @@ 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_impl_all!(BoxBody: fmt::Debug, MessageBody, Unpin);
|
||||
assert_not_impl_any!(BoxBody: Send, Sync);
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn nested_boxed_body() {
|
||||
|
@@ -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<EitherBody<B>>`.
|
||||
/// 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<B, String>` instead if its alternative
|
||||
/// responses have a known type.
|
||||
#[project = EitherBodyProj]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum EitherBody<L, R = BoxBody> {
|
||||
@@ -22,7 +33,10 @@ pin_project! {
|
||||
}
|
||||
|
||||
impl<L> EitherBody<L, BoxBody> {
|
||||
/// 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 }
|
||||
|
@@ -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<u8>`, `&'static [u8]`;
|
||||
/// - Streams: [`BodyStream`](super::BodyStream), [`SizedStream`](super::SizedStream)
|
||||
///
|
||||
|
@@ -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<stream::Empty<Result<Bytes, Infallible>>>: MessageBody);
|
||||
assert_impl_all!(SizedStream<stream::Repeat<Result<Bytes, Infallible>>>: MessageBody);
|
||||
|
||||
assert_not_impl_all!(SizedStream<stream::Empty<Bytes>>: MessageBody);
|
||||
assert_not_impl_all!(SizedStream<stream::Repeat<Bytes>>: MessageBody);
|
||||
assert_not_impl_any!(SizedStream<stream::Empty<Bytes>>: MessageBody);
|
||||
assert_not_impl_any!(SizedStream<stream::Repeat<Bytes>>: MessageBody);
|
||||
// crate::Error is not Clone
|
||||
assert_not_impl_all!(SizedStream<stream::Repeat<Result<Bytes, crate::Error>>>: MessageBody);
|
||||
assert_not_impl_any!(SizedStream<stream::Repeat<Result<Bytes, crate::Error>>>: MessageBody);
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn skips_empty_chunks() {
|
||||
|
@@ -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
|
||||
|
@@ -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"
|
||||
|
@@ -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]
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-test"
|
||||
version = "0.1.0-beta.12"
|
||||
version = "0.1.0-beta.13"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
@@ -28,14 +28,14 @@ rustls = ["tls-rustls", "actix-http/rustls", "awc/rustls"]
|
||||
openssl = ["tls-openssl", "actix-http/openssl", "awc/openssl"]
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.4.1"
|
||||
actix-http = "3.0.0-rc.2"
|
||||
actix-http-test = "3.0.0-beta.12"
|
||||
actix-codec = "0.5"
|
||||
actix-http = "3.0.0-rc.3"
|
||||
actix-http-test = "3.0.0-beta.13"
|
||||
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 = [] }
|
||||
|
@@ -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`.
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-web-actors"
|
||||
version = "4.0.0-beta.11"
|
||||
version = "4.0.0-beta.12"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Actix actors support for Actix Web"
|
||||
keywords = ["actix", "http", "web", "framework", "async"]
|
||||
@@ -15,8 +15,8 @@ path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix = { version = "0.12.0", default-features = false }
|
||||
actix-codec = "0.4.1"
|
||||
actix-http = "3.0.0-rc.2"
|
||||
actix-codec = "0.5"
|
||||
actix-http = "3.0.0-rc.3"
|
||||
actix-web = { version = "4.0.0-rc.3", default-features = false }
|
||||
|
||||
bytes = "1"
|
||||
@@ -27,8 +27,8 @@ 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 }
|
||||
actix-test = "0.1.0-beta.13"
|
||||
awc = { version = "3.0.0-beta.21", default-features = false }
|
||||
|
||||
env_logger = "0.9"
|
||||
futures-util = { version = "0.3.7", default-features = false }
|
||||
|
@@ -3,11 +3,11 @@
|
||||
> Actix actors support for Actix Web.
|
||||
|
||||
[](https://crates.io/crates/actix-web-actors)
|
||||
[](https://docs.rs/actix-web-actors/4.0.0-beta.11)
|
||||
[](https://docs.rs/actix-web-actors/4.0.0-beta.12)
|
||||
[](https://blog.rust-lang.org/2021/05/06/Rust-1.54.0.html)
|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-web-actors/4.0.0-beta.11)
|
||||
[](https://deps.rs/crate/actix-web-actors/4.0.0-beta.12)
|
||||
[](https://crates.io/crates/actix-web-actors)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
|
@@ -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"
|
||||
|
||||
|
@@ -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"
|
||||
@@ -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 }
|
||||
|
||||
@@ -100,8 +100,8 @@ 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"] }
|
||||
actix-test = { version = "0.1.0-beta.13", features = ["openssl", "rustls"] }
|
||||
awc = { version = "3.0.0-beta.21", features = ["openssl"] }
|
||||
|
||||
brotli = "3.3.3"
|
||||
const-str = "0.3"
|
||||
|
@@ -2,29 +2,49 @@
|
||||
|
||||
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)
|
||||
- [Server Settings](#server-settings)
|
||||
- [Tokio v1 Ecosystem](#tokio-v1-ecosystem)
|
||||
- [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)
|
||||
- [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)
|
||||
- [Response Body Types](#response-body-types)
|
||||
- [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
|
||||
|
||||
The MSRV of Actix Web has been raised from 1.42 to 1.54.
|
||||
|
||||
## Server Settings
|
||||
## Tokio v1 Ecosystem
|
||||
|
||||
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).
|
||||
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
|
||||
|
||||
@@ -46,6 +66,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.
|
||||
@@ -60,14 +86,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.
|
||||
@@ -91,7 +115,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).
|
||||
|
||||
@@ -102,44 +126,197 @@ 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.
|
||||
|
||||
## Body Types / Removal of Body+ResponseBody types / Addition of EitherBody
|
||||
In short, "insert" always indicates that existing any existing headers with the same name are overridden and "append" indicates adding with no removal.
|
||||
|
||||
TODO
|
||||
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.
|
||||
|
||||
In particular, folks seem to be struggling with the `ErrorHandlers` middleware because of this change and the obscured nature of `EitherBody` within its types.
|
||||
```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())
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
||||
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](#response-body-types) section.
|
||||
|
||||
TODO
|
||||
|
||||
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](#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.
|
||||
|
||||
TODO
|
||||
```diff
|
||||
impl Responder for &'static str {
|
||||
- type Error = Error;
|
||||
- type Future = Ready<Result<HttpResponse, Error>>;
|
||||
+ 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<Self::Body> {
|
||||
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<MyState>) -> { todo!() }
|
||||
|
||||
HttpServer::new(|| {
|
||||
- App::new()
|
||||
- .data(MyState::default())
|
||||
- .service(hander)
|
||||
|
||||
+ let my_state: Data<MyState> = 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.
|
||||
|
||||
## HttpResponse no longer implements Future
|
||||
```diff
|
||||
struct MethodGuard(HttpMethod);
|
||||
|
||||
TODO
|
||||
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:
|
||||
|
||||
```
|
||||
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)
|
||||
```
|
||||
|
||||
## `#[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.
|
||||
|
||||
## `web::block`
|
||||
|
||||
The `web::block` helper has changed return type from roughly `async fn(fn() -> Result<T, E>) Result<T, BlockingError<E>>` to `async fn(fn() -> T) Result<T, BlockingError>`. 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??;
|
||||
```
|
||||
|
13
actix-web/src/middleware/authors-guide.md
Normal file
13
actix-web/src/middleware/authors-guide.md
Normal file
@@ -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
|
@@ -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<R> {
|
||||
inner: CustomizeResponderInner<R>,
|
||||
error: Option<HttpError>,
|
||||
|
@@ -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<Self>
|
||||
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<Self>
|
||||
|
@@ -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>(T);
|
||||
|
||||
impl<T> Path<T> {
|
||||
|
@@ -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`.
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "awc"
|
||||
version = "3.0.0-beta.20"
|
||||
version = "3.0.0-beta.21"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"fakeshadow <24548779@qq.com>",
|
||||
@@ -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-http = { version = "3.0.0-rc.3", 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"
|
||||
@@ -93,11 +93,11 @@ 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-test = { version = "3.0.0-beta.12", features = ["openssl"] }
|
||||
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-tls = { version = "3.0.0", 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"] }
|
||||
|
||||
|
@@ -3,9 +3,9 @@
|
||||
> Async HTTP and WebSocket client library.
|
||||
|
||||
[](https://crates.io/crates/awc)
|
||||
[](https://docs.rs/awc/3.0.0-beta.20)
|
||||
[](https://docs.rs/awc/3.0.0-beta.21)
|
||||

|
||||
[](https://deps.rs/crate/awc/3.0.0-beta.20)
|
||||
[](https://deps.rs/crate/awc/3.0.0-beta.21)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
## Documentation & Resources
|
||||
|
@@ -160,7 +160,7 @@ impl<S: fmt::Debug> fmt::Debug for AnyBody<S> {
|
||||
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::*;
|
||||
|
||||
@@ -181,12 +181,12 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert_impl_all!(AnyBody<()>: MessageBody, fmt::Debug, Send, Sync, Unpin);
|
||||
assert_impl_all!(AnyBody<AnyBody<()>>: MessageBody, fmt::Debug, Send, Sync, Unpin);
|
||||
assert_impl_all!(AnyBody<Bytes>: MessageBody, fmt::Debug, Send, Sync, Unpin);
|
||||
assert_impl_all!(AnyBody: MessageBody, fmt::Debug, Unpin);
|
||||
assert_impl_all!(AnyBody<PinType>: MessageBody);
|
||||
assert_impl_all!(AnyBody<()>: Send, Sync, Unpin, fmt::Debug, MessageBody);
|
||||
assert_impl_all!(AnyBody<AnyBody<()>>: Send, Sync, Unpin, fmt::Debug, MessageBody);
|
||||
assert_impl_all!(AnyBody<Bytes>: Send, Sync, Unpin, fmt::Debug, MessageBody);
|
||||
assert_impl_all!(AnyBody: Unpin, fmt::Debug, MessageBody);
|
||||
assert_impl_all!(AnyBody<PinType>: Send, Sync, MessageBody);
|
||||
|
||||
assert_not_impl_all!(AnyBody: Send, Sync, Unpin);
|
||||
assert_not_impl_all!(AnyBody<PinType>: Send, Sync, Unpin);
|
||||
assert_not_impl_any!(AnyBody: Send, Sync);
|
||||
assert_not_impl_any!(AnyBody<PinType>: Unpin);
|
||||
}
|
||||
|
@@ -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" };
|
||||
|
Reference in New Issue
Block a user