diff --git a/.cspell.yml b/.cspell.yml index 95a3e2f90..f275e0a24 100644 --- a/.cspell.yml +++ b/.cspell.yml @@ -1,3 +1,8 @@ version: "0.2" words: - actix + - addrs + - httparse + - msrv + - rustup + - zstd diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c7ecf5eaa..3aeae6b1b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,11 @@ version: 2 updates: - - package-ecosystem: cargo - directory: / - schedule: - interval: weekly - package-ecosystem: github-actions directory: / schedule: interval: weekly + - package-ecosystem: cargo + directory: / + schedule: + interval: weekly + versioning-strategy: lockfile-only diff --git a/.github/workflows/ci-post-merge.yml b/.github/workflows/ci-post-merge.yml index 5ae95d5d2..c6f56e67a 100644 --- a/.github/workflows/ci-post-merge.yml +++ b/.github/workflows/ci-post-merge.yml @@ -44,12 +44,12 @@ jobs: echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV - name: Install Rust (${{ matrix.version.name }}) - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: toolchain: ${{ matrix.version.version }} - name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean - uses: taiki-e/install-action@v2.49.45 + uses: taiki-e/install-action@v2.50.10 with: tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean @@ -80,10 +80,10 @@ jobs: uses: rui314/setup-mold@v1 - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 - name: Install just, cargo-hack - uses: taiki-e/install-action@v2.49.45 + uses: taiki-e/install-action@v2.50.10 with: tool: just,cargo-hack diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1556d6b3..a1adf6b41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,12 +59,12 @@ jobs: uses: rui314/setup-mold@v1 - name: Install Rust (${{ matrix.version.name }}) - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: toolchain: ${{ matrix.version.version }} - name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean - uses: taiki-e/install-action@v2.49.45 + uses: taiki-e/install-action@v2.50.10 with: tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean @@ -92,7 +92,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: toolchain: nightly @@ -108,12 +108,12 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust (nightly) - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: toolchain: nightly - name: Install just - uses: taiki-e/install-action@v2.49.45 + uses: taiki-e/install-action@v2.50.10 with: tool: just diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 496a22e2a..6500c0adb 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -18,13 +18,13 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust (nightly) - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: toolchain: nightly components: llvm-tools - name: Install just, cargo-llvm-cov, cargo-nextest - uses: taiki-e/install-action@v2.49.45 + uses: taiki-e/install-action@v2.50.10 with: tool: just,cargo-llvm-cov,cargo-nextest @@ -32,7 +32,7 @@ jobs: run: just test-coverage-codecov - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5.4.0 + uses: codecov/codecov-action@v5.4.2 with: files: codecov.json fail_ci_if_error: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 28fd44494..dfddd25cd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust (nightly) - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: toolchain: nightly components: rustfmt @@ -36,7 +36,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: components: clippy @@ -55,7 +55,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust (nightly) - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: toolchain: nightly components: rust-docs @@ -72,12 +72,12 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust (${{ vars.RUST_VERSION_EXTERNAL_TYPES }}) - uses: actions-rust-lang/setup-rust-toolchain@v1.11.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.12.0 with: toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }} - name: Install just - uses: taiki-e/install-action@v2.49.45 + uses: taiki-e/install-action@v2.50.10 with: tool: just diff --git a/Cargo.lock b/Cargo.lock index 2caac3e90..29df16251 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,7 +109,7 @@ dependencies = [ "openssl", "percent-encoding", "pin-project-lite", - "rand 0.9.0", + "rand 0.9.1", "rcgen", "regex", "rustls 0.23.25", @@ -185,7 +185,7 @@ dependencies = [ "memchr", "mime", "multer", - "rand 0.9.0", + "rand 0.9.1", "serde", "serde_json", "serde_plain", @@ -251,9 +251,9 @@ dependencies = [ [[package]] name = "actix-server" -version = "2.5.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6398974fd4284f4768af07965701efbbb5fdc0616bff20cade1bb14b77675e24" +checksum = "a65064ea4a457eaf07f2fba30b4c695bf43b721790e9530d26cb6f9019ff7502" dependencies = [ "actix-rt", "actix-service", @@ -383,7 +383,7 @@ dependencies = [ "once_cell", "openssl", "pin-project-lite", - "rand 0.9.0", + "rand 0.9.1", "rcgen", "regex", "regex-lite", @@ -397,6 +397,7 @@ dependencies = [ "static_assertions", "time", "tokio", + "tokio-util", "tracing", "url", "zstd", @@ -650,7 +651,7 @@ dependencies = [ "openssl", "percent-encoding", "pin-project-lite", - "rand 0.9.0", + "rand 0.9.1", "rcgen", "rustls 0.20.9", "rustls 0.21.12", @@ -762,9 +763,9 @@ dependencies = [ [[package]] name = "brotli" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd" +checksum = "cf19e729cdbd51af9a397fb9ef8ac8378007b797f8273cfbfdf45dcaa316167b" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -773,9 +774,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "4.0.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74fa05ad7d803d413eb8380983b092cbbaf9a85f151b871360e7b00cd7060b37" +checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -1211,9 +1212,9 @@ dependencies = [ [[package]] name = "divan" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "009c56317fe2bd3b5eebe3aa888828c62ed1b085d26c1ef2079a60369795765e" +checksum = "a405457ec78b8fe08b0e32b4a3570ab5dff6dd16eb9e76a5ee0a9d9cbd898933" dependencies = [ "cfg-if", "clap", @@ -1225,9 +1226,9 @@ dependencies = [ [[package]] name = "divan-macros" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4de9827ae754db91aedec0277381f5a2d8e2f801564c8d774acfe1ab1b045e" +checksum = "9556bc800956545d6420a640173e5ba7dfa82f38d3ea5a167eb555bc69ac3323" dependencies = [ "proc-macro2", "quote", @@ -2361,9 +2362,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -2396,13 +2397,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.3", - "zerocopy", ] [[package]] @@ -3103,9 +3103,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.44.2" +version = "1.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" +checksum = "2513ca694ef9ede0fb23fe71a4ee4107cb102b9dc1930f6d0fd77aae068ae165" dependencies = [ "backtrace", "bytes", @@ -3211,9 +3211,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.14" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" dependencies = [ "bytes", "futures-core", diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 7324cba5a..1e1d464c8 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -2,6 +2,8 @@ ## Unreleased +- Update `brotli` dependency to `8`. + ## 3.10.0 ### Added diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 0e5c4b234..f3b8c5cbe 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -139,7 +139,7 @@ sha1 = { version = "0.10", optional = true } actix-tls = { version = "3.4", default-features = false, optional = true } # compress-* -brotli = { version = "7", optional = true } +brotli = { version = "8", optional = true } flate2 = { version = "1.0.13", optional = true } zstd = { version = "0.13", optional = true } diff --git a/actix-http/examples/streaming-error.rs b/actix-http/examples/streaming-error.rs index 39f214fa1..8d494b64e 100644 --- a/actix-http/examples/streaming-error.rs +++ b/actix-http/examples/streaming-error.rs @@ -31,7 +31,7 @@ async fn main() -> io::Result<()> { actix_rt::time::sleep(Duration::from_secs(1)).await; - yield Err(io::Error::new(io::ErrorKind::Other, "abc")); + yield Err(io::Error::other("abc")); }))) }) .tcp() diff --git a/actix-http/src/body/utils.rs b/actix-http/src/body/utils.rs index b8bfa96cf..a234222aa 100644 --- a/actix-http/src/body/utils.rs +++ b/actix-http/src/body/utils.rs @@ -190,7 +190,7 @@ mod tests { #[actix_rt::test] async fn to_body_limit_error() { - let err_stream = stream::once(async { Err(io::Error::new(io::ErrorKind::Other, "")) }); + let err_stream = stream::once(async { Err(io::Error::other("")) }); let body = SizedStream::new(8, err_stream); // not too big, but propagates error from body stream assert!(to_bytes_limited(body, 10).await.unwrap().is_err()); diff --git a/actix-http/src/encoding/decoder.rs b/actix-http/src/encoding/decoder.rs index cda534d60..1247c0a55 100644 --- a/actix-http/src/encoding/decoder.rs +++ b/actix-http/src/encoding/decoder.rs @@ -100,10 +100,7 @@ where loop { if let Some(ref mut fut) = this.fut { let (chunk, decoder) = ready!(Pin::new(fut).poll(cx)).map_err(|_| { - PayloadError::Io(io::Error::new( - io::ErrorKind::Other, - "Blocking task was cancelled unexpectedly", - )) + PayloadError::Io(io::Error::other("Blocking task was cancelled unexpectedly")) })??; *this.decoder = Some(decoder); diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index 735dca679..0da95c462 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -183,8 +183,7 @@ where if let Some(ref mut fut) = this.fut { let mut encoder = ready!(Pin::new(fut).poll(cx)) .map_err(|_| { - EncoderError::Io(io::Error::new( - io::ErrorKind::Other, + EncoderError::Io(io::Error::other( "Blocking task was cancelled unexpectedly", )) })? diff --git a/actix-http/src/error.rs b/actix-http/src/error.rs index 8ef2698a2..e4d640518 100644 --- a/actix-http/src/error.rs +++ b/actix-http/src/error.rs @@ -415,7 +415,7 @@ mod tests { #[test] fn test_as_response() { - let orig = io::Error::new(io::ErrorKind::Other, "other"); + let orig = io::Error::other("other"); let err: Error = ParseError::Io(orig).into(); assert_eq!( format!("{}", err), @@ -425,14 +425,14 @@ mod tests { #[test] fn test_error_display() { - let orig = io::Error::new(io::ErrorKind::Other, "other"); + let orig = io::Error::other("other"); let err = Error::new_io().with_cause(orig); assert_eq!("connection error: other", err.to_string()); } #[test] fn test_error_http_response() { - let orig = io::Error::new(io::ErrorKind::Other, "other"); + let orig = io::Error::other("other"); let err = Error::new_io().with_cause(orig); let resp: Response = err.into(); assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR); @@ -440,7 +440,7 @@ mod tests { #[test] fn test_payload_error() { - let err: PayloadError = io::Error::new(io::ErrorKind::Other, "ParseError").into(); + let err: PayloadError = io::Error::other("ParseError").into(); assert!(err.to_string().contains("ParseError")); let err = PayloadError::Incomplete(None); @@ -475,7 +475,7 @@ mod tests { #[test] fn test_from() { - from_and_cause!(io::Error::new(io::ErrorKind::Other, "other") => ParseError::Io(..)); + from_and_cause!(io::Error::other("other") => ParseError::Io(..)); from!(httparse::Error::HeaderName => ParseError::Header); from!(httparse::Error::HeaderName => ParseError::Header); from!(httparse::Error::HeaderValue => ParseError::Header); diff --git a/actix-http/src/h1/encoder.rs b/actix-http/src/h1/encoder.rs index 77e34bcdc..81af7868b 100644 --- a/actix-http/src/h1/encoder.rs +++ b/actix-http/src/h1/encoder.rs @@ -310,10 +310,10 @@ impl MessageType for RequestHeadType { Version::HTTP_11 => "HTTP/1.1", Version::HTTP_2 => "HTTP/2.0", Version::HTTP_3 => "HTTP/3.0", - _ => return Err(io::Error::new(io::ErrorKind::Other, "unsupported version")), + _ => return Err(io::Error::other("Unsupported version")), } ) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err)) + .map_err(io::Error::other) } } @@ -433,7 +433,7 @@ impl TransferEncoding { buf.extend_from_slice(b"0\r\n\r\n"); } else { writeln!(helpers::MutWriter(buf), "{:X}\r", msg.len()) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; + .map_err(io::Error::other)?; buf.reserve(msg.len() + 2); buf.extend_from_slice(msg); diff --git a/actix-web-actors/src/ws.rs b/actix-web-actors/src/ws.rs index 0002f87e2..22618c9b3 100644 --- a/actix-web-actors/src/ws.rs +++ b/actix-web-actors/src/ws.rs @@ -776,10 +776,7 @@ where } Poll::Pending => break, Poll::Ready(Some(Err(err))) => { - return Poll::Ready(Some(Err(ProtocolError::Io(io::Error::new( - io::ErrorKind::Other, - format!("{err}"), - ))))); + return Poll::Ready(Some(Err(ProtocolError::Io(io::Error::other(err))))); } } } @@ -795,11 +792,10 @@ where } Some(frm) => { let msg = match frm { - Frame::Text(data) => { - Message::Text(ByteString::try_from(data).map_err(|err| { - ProtocolError::Io(io::Error::new(io::ErrorKind::Other, err)) - })?) - } + Frame::Text(data) => Message::Text( + ByteString::try_from(data) + .map_err(|err| ProtocolError::Io(io::Error::other(err)))?, + ), Frame::Binary(data) => Message::Binary(data), Frame::Ping(s) => Message::Ping(s), Frame::Pong(s) => Message::Pong(s), diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 0542b7277..57dea639c 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -2,7 +2,10 @@ ## Unreleased +- Add `HttpServer::shutdown_signal()` method. +- Mark `HttpServer` as `#[must_use]`. - Re-export `mime` dependency. +- Update `brotli` dependency to `8`. ## 4.10.2 diff --git a/actix-web/Cargo.toml b/actix-web/Cargo.toml index 29c6970e6..afa4eadbc 100644 --- a/actix-web/Cargo.toml +++ b/actix-web/Cargo.toml @@ -132,7 +132,7 @@ compat-routing-macros-force-pub = ["actix-web-codegen?/compat-routing-macros-for actix-codec = "0.5" actix-macros = { version = "0.2.3", optional = true } actix-rt = { version = "2.6", default-features = false } -actix-server = "2" +actix-server = "2.6" actix-service = "2" actix-utils = "3" actix-tls = { version = "3.4", default-features = false, optional = true } @@ -173,7 +173,7 @@ actix-files = "0.6" actix-test = { version = "0.1", features = ["openssl", "rustls-0_23"] } awc = { version = "3", features = ["openssl"] } -brotli = "7" +brotli = "8" const-str = "0.5" core_affinity = "0.8" criterion = { version = "0.5", features = ["html_reports"] } @@ -188,6 +188,7 @@ static_assertions = "1" tls-openssl = { package = "openssl", version = "0.10.55" } tls-rustls = { package = "rustls", version = "0.23" } tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros"] } +tokio-util = "0.7" zstd = "0.13" [lints] diff --git a/actix-web/src/server.rs b/actix-web/src/server.rs index 1ea4de4ca..d56bbe84c 100644 --- a/actix-web/src/server.rs +++ b/actix-web/src/server.rs @@ -1,6 +1,8 @@ use std::{ any::Any, - cmp, fmt, io, + cmp, fmt, + future::Future, + io, marker::PhantomData, net, sync::{Arc, Mutex}, @@ -64,6 +66,7 @@ struct Config { /// .await /// } /// ``` +#[must_use] pub struct HttpServer where F: Fn() -> I + Send + Clone + 'static, @@ -312,6 +315,37 @@ where self } + /// Specify shutdown signal from a future. + /// + /// Using this method will prevent OS signal handlers being set up. + /// + /// Typically, a `CancellationToken` will be used, but any future _can_ be. + /// + /// # Examples + /// + /// ```no_run + /// use actix_web::{App, HttpServer}; + /// use tokio_util::sync::CancellationToken; + /// + /// # #[actix_web::main] + /// # async fn main() -> std::io::Result<()> { + /// let stop_signal = CancellationToken::new(); + /// + /// HttpServer::new(move || App::new()) + /// .shutdown_signal(stop_signal.cancelled_owned()) + /// .bind(("127.0.0.1", 8080))? + /// .run() + /// .await + /// # } + /// ``` + pub fn shutdown_signal(mut self, shutdown_signal: Fut) -> Self + where + Fut: Future + Send + 'static, + { + self.builder = self.builder.shutdown_signal(shutdown_signal); + self + } + /// Sets timeout for graceful worker shutdown of workers. /// /// After receiving a stop signal, workers have this much time to finish serving requests. @@ -1073,10 +1107,7 @@ fn bind_addrs(addrs: impl net::ToSocketAddrs, backlog: u32) -> io::Result