Merge branch 'master' into fix/content-type-required

This commit is contained in:
Rob Ede 2023-11-19 11:03:09 +00:00 committed by GitHub
commit f7849d5e99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 120 additions and 35 deletions

View File

@ -5,7 +5,7 @@ on:
branches: [master] branches: [master]
permissions: permissions:
contents: read # to fetch code (actions/checkout) contents: read
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}

View File

@ -45,7 +45,7 @@ jobs:
toolchain: ${{ matrix.version.version }} toolchain: ${{ matrix.version.version }}
- name: Install cargo-hack - name: Install cargo-hack
uses: taiki-e/install-action@v2.20.2 uses: taiki-e/install-action@v2.21.11
with: with:
tool: cargo-hack tool: cargo-hack
@ -85,7 +85,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1.5.0 uses: actions-rust-lang/setup-rust-toolchain@v1.5.0
- name: Install cargo-hack - name: Install cargo-hack
uses: taiki-e/install-action@v2.20.2 uses: taiki-e/install-action@v2.21.11
with: with:
tool: cargo-hack tool: cargo-hack
@ -106,7 +106,7 @@ jobs:
uses: actions-rust-lang/setup-rust-toolchain@v1.5.0 uses: actions-rust-lang/setup-rust-toolchain@v1.5.0
- name: Install nextest - name: Install nextest
uses: taiki-e/install-action@v2.20.2 uses: taiki-e/install-action@v2.21.11
with: with:
tool: nextest tool: nextest

View File

@ -50,7 +50,7 @@ jobs:
toolchain: ${{ matrix.version.version }} toolchain: ${{ matrix.version.version }}
- name: Install cargo-hack - name: Install cargo-hack
uses: taiki-e/install-action@v2.20.2 uses: taiki-e/install-action@v2.21.11
with: with:
tool: cargo-hack tool: cargo-hack

View File

@ -23,7 +23,7 @@ jobs:
components: llvm-tools-preview components: llvm-tools-preview
- name: Install cargo-llvm-cov - name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2.20.2 uses: taiki-e/install-action@v2.21.11
with: with:
tool: cargo-llvm-cov tool: cargo-llvm-cov

View File

@ -22,25 +22,31 @@ jobs:
toolchain: nightly toolchain: nightly
components: rustfmt components: rustfmt
- run: cargo fmt --all -- --check - name: Check with rustfmt
run: cargo fmt --all -- --check
clippy: clippy:
permissions: permissions:
contents: read
checks: write # to add clippy checks to PR diffs checks: write # to add clippy checks to PR diffs
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1.5.0 - name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1.5.0
with: with:
components: clippy components: clippy
- uses: giraffate/clippy-action@v1.0.1 - name: Check with Clippy
uses: giraffate/clippy-action@v1.0.1
with: with:
reporter: github-pr-check reporter: github-pr-check
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
clippy_flags: --workspace --all-features --tests --examples --bins -- -Dclippy::todo -Aunknown_lints clippy_flags: >-
--workspace --all-features --tests --examples --bins --
-A unknown_lints -D clippy::todo -D clippy::dbg_macro
lint-docs: lint-docs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -70,7 +76,7 @@ jobs:
with: with:
toolchain: nightly-2023-08-25 toolchain: nightly-2023-08-25
- uses: taiki-e/cache-cargo-install-action@v1.2.2 - uses: taiki-e/cache-cargo-install-action@v1.3.0
with: with:
tool: cargo-public-api tool: cargo-public-api

View File

@ -6,6 +6,7 @@ on:
permissions: permissions:
contents: read contents: read
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true

View File

@ -47,4 +47,5 @@ actix-server = { version = "2.2", optional = true } # ensure matching tokio-urin
actix-rt = "2.7" actix-rt = "2.7"
actix-test = "0.1" actix-test = "0.1"
actix-web = "4" actix-web = "4"
env_logger = "0.10"
tempfile = "3.2" tempfile = "3.2"

View File

@ -0,0 +1,33 @@
use actix_files::Files;
use actix_web::{get, guard, middleware, App, HttpServer, Responder};
const EXAMPLES_DIR: &str = concat![env!("CARGO_MANIFEST_DIR"), "/examples"];
#[get("/")]
async fn index() -> impl Responder {
"Hello world!"
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("starting HTTP server at http://localhost:8080");
HttpServer::new(|| {
App::new()
.service(index)
.service(
Files::new("/assets", EXAMPLES_DIR)
.show_files_listing()
.guard(guard::Header("show-listing", "?1")),
)
.service(Files::new("/assets", EXAMPLES_DIR))
.wrap(middleware::Compress::default())
.wrap(middleware::Logger::default())
})
.bind(("127.0.0.1", 8080))?
.workers(2)
.run()
.await
}

View File

@ -235,7 +235,7 @@ impl Files {
/// request starts being handled by the file service, it will not be able to back-out and try /// request starts being handled by the file service, it will not be able to back-out and try
/// the next service, you will simply get a 404 (or 405) error response. /// the next service, you will simply get a 404 (or 405) error response.
/// ///
/// To allow `POST` requests to retrieve files, see [`Files::use_guards`]. /// To allow `POST` requests to retrieve files, see [`Files::method_guard()`].
/// ///
/// # Examples /// # Examples
/// ``` /// ```

View File

@ -5,7 +5,7 @@ authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Various helpers for Actix applications to use during testing" description = "Various helpers for Actix applications to use during testing"
keywords = ["http", "web", "framework", "async", "futures"] keywords = ["http", "web", "framework", "async", "futures"]
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
categories = [ categories = [
"network-programming", "network-programming",
"asynchronous", "asynchronous",

View File

@ -2,6 +2,10 @@
## Unreleased ## Unreleased
### Changed
- Updated `zstd` dependency to `0.13`.
## 3.4.0 ## 3.4.0
### Added ### Added

View File

@ -8,7 +8,7 @@ authors = [
description = "HTTP primitives for the Actix ecosystem" description = "HTTP primitives for the Actix ecosystem"
keywords = ["actix", "http", "framework", "async", "futures"] keywords = ["actix", "http", "framework", "async", "futures"]
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
categories = [ categories = [
"network-programming", "network-programming",
"asynchronous", "asynchronous",
@ -103,7 +103,7 @@ actix-tls = { version = "3.1", default-features = false, optional = true }
# compress-* # compress-*
brotli = { version = "3.3.3", optional = true } brotli = { version = "3.3.3", optional = true }
flate2 = { version = "1.0.13", optional = true } flate2 = { version = "1.0.13", optional = true }
zstd = { version = "0.12", optional = true } zstd = { version = "0.13", optional = true }
[dev-dependencies] [dev-dependencies]
actix-http-test = { version = "3", features = ["openssl"] } actix-http-test = { version = "3", features = ["openssl"] }

View File

@ -5,7 +5,7 @@ authors = ["Jacob Halsey <jacob@jhalsey.com>"]
description = "Multipart form derive macro for Actix Web" description = "Multipart form derive macro for Actix Web"
keywords = ["http", "web", "framework", "async", "futures"] keywords = ["http", "web", "framework", "async", "futures"]
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
edition = "2021" edition = "2021"

View File

@ -8,7 +8,7 @@ authors = [
description = "Multipart form support for Actix Web" description = "Multipart form support for Actix Web"
keywords = ["http", "web", "framework", "async", "futures"] keywords = ["http", "web", "framework", "async", "futures"]
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
edition = "2021" edition = "2021"

View File

@ -8,7 +8,7 @@ authors = [
] ]
description = "Resource path matching and router" description = "Resource path matching and router"
keywords = ["actix", "router", "routing"] keywords = ["actix", "router", "routing"]
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
edition = "2021" edition = "2021"

View File

@ -8,7 +8,7 @@ authors = [
description = "Integration testing tools for Actix Web applications" description = "Integration testing tools for Actix Web applications"
keywords = ["http", "web", "framework", "async", "futures"] keywords = ["http", "web", "framework", "async", "futures"]
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
categories = [ categories = [
"network-programming", "network-programming",
"asynchronous", "asynchronous",

View File

@ -3,7 +3,7 @@ name = "actix-web-codegen"
version = "4.2.2" version = "4.2.2"
description = "Routing and runtime macros for Actix Web" description = "Routing and runtime macros for Actix Web"
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
authors = [ authors = [
"Nikolay Kim <fafhrd91@gmail.com>", "Nikolay Kim <fafhrd91@gmail.com>",
"Rob Ede <robjtede@icloud.com>", "Rob Ede <robjtede@icloud.com>",

View File

@ -2,9 +2,13 @@
## Unreleased ## Unreleased
### Changed
- Updated `zstd` dependency to `0.13`.
### Fixed ### Fixed
- Fix content type required validation when set to false. [#3162] - Fix validation of `Json` extractor when `JsonConfig::validate_content_type()` is set to false. [#3162]
## 4.4.0 ## 4.4.0

View File

@ -14,7 +14,7 @@ categories = [
"web-programming::websocket" "web-programming::websocket"
] ]
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
edition.workspace = true edition.workspace = true
rust-version.workspace = true rust-version.workspace = true
@ -122,7 +122,7 @@ static_assertions = "1"
tls-openssl = { package = "openssl", version = "0.10.55" } tls-openssl = { package = "openssl", version = "0.10.55" }
tls-rustls = { package = "rustls", version = "0.21" } tls-rustls = { package = "rustls", version = "0.21" }
tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros"] } tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros"] }
zstd = "0.12" zstd = "0.13"
[[test]] [[test]]
name = "test_server" name = "test_server"

View File

@ -5,8 +5,6 @@ mod responder;
#[allow(clippy::module_inception)] #[allow(clippy::module_inception)]
mod response; mod response;
#[cfg(feature = "cookies")]
pub use self::response::CookieIter;
pub use self::{ pub use self::{
builder::HttpResponseBuilder, customize_responder::CustomizeResponder, responder::Responder, builder::HttpResponseBuilder, customize_responder::CustomizeResponder, responder::Responder,
response::HttpResponse, response::HttpResponse,

View File

@ -99,6 +99,12 @@ where
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
/// Create new HTTP server with application factory /// Create new HTTP server with application factory
///
/// # Worker Count
///
/// The `factory` will be instantiated multiple times in most configurations. See
/// [`bind()`](Self::bind()) docs for more on how worker count and bind address resolution
/// causes multiple server factory instantiations.
pub fn new(factory: F) -> Self { pub fn new(factory: F) -> Self {
HttpServer { HttpServer {
factory, factory,
@ -119,7 +125,18 @@ where
/// Sets number of workers to start (per bind address). /// Sets number of workers to start (per bind address).
/// ///
/// By default, the number of available physical CPUs is used as the worker count. /// The default worker count is the determined by [`std::thread::available_parallelism()`]. See
/// its documentation to determine what behavior you should expect when server is run.
///
/// Note that the server factory passed to [`new`](Self::new()) will be instantiated **at least
/// once per worker**. See [`bind()`](Self::bind()) docs for more on how worker count and bind
/// address resolution causes multiple server factory instantiations.
///
/// `num` must be greater than 0.
///
/// # Panics
///
/// Panics if `num` is 0.
pub fn workers(mut self, num: usize) -> Self { pub fn workers(mut self, num: usize) -> Self {
self.builder = self.builder.workers(num); self.builder = self.builder.workers(num);
self self
@ -319,23 +336,41 @@ where
/// Resolves socket address(es) and binds server to created listener(s). /// Resolves socket address(es) and binds server to created listener(s).
/// ///
/// # Hostname Resolution /// # Hostname Resolution
/// When `addr` includes a hostname, it is possible for this method to bind to both the IPv4 and ///
/// IPv6 addresses that result from a DNS lookup. You can test this by passing `localhost:8080` /// When `addrs` includes a hostname, it is possible for this method to bind to both the IPv4
/// and noting that the server binds to `127.0.0.1:8080` _and_ `[::1]:8080`. To bind additional /// and IPv6 addresses that result from a DNS lookup. You can test this by passing
/// addresses, call this method multiple times. /// `localhost:8080` and noting that the server binds to `127.0.0.1:8080` _and_ `[::1]:8080`. To
/// bind additional addresses, call this method multiple times.
/// ///
/// Note that, if a DNS lookup is required, resolving hostnames is a blocking operation. /// Note that, if a DNS lookup is required, resolving hostnames is a blocking operation.
/// ///
/// # Worker Count
///
/// The `factory` will be instantiated multiple times in most scenarios. The number of
/// instantiations is number of [`workers`](Self::workers()) × number of sockets resolved by
/// `addrs`.
///
/// For example, if you've manually set [`workers`](Self::workers()) to 2, and use `127.0.0.1`
/// as the bind `addrs`, then `factory` will be instantiated twice. However, using `localhost`
/// as the bind `addrs` can often resolve to both `127.0.0.1` (IPv4) _and_ `::1` (IPv6), causing
/// the `factory` to be instantiated 4 times (2 workers × 2 bind addresses).
///
/// Using a bind address of `0.0.0.0`, which signals to use all interfaces, may also multiple
/// the number of instantiations in a similar way.
///
/// # Typical Usage /// # Typical Usage
///
/// In general, use `127.0.0.1:<port>` when testing locally and `0.0.0.0:<port>` when deploying /// In general, use `127.0.0.1:<port>` when testing locally and `0.0.0.0:<port>` when deploying
/// (with or without a reverse proxy or load balancer) so that the server is accessible. /// (with or without a reverse proxy or load balancer) so that the server is accessible.
/// ///
/// # Errors /// # Errors
///
/// Returns an `io::Error` if: /// Returns an `io::Error` if:
/// - `addrs` cannot be resolved into one or more socket addresses; /// - `addrs` cannot be resolved into one or more socket addresses;
/// - all the resolved socket addresses are already bound. /// - all the resolved socket addresses are already bound.
/// ///
/// # Example /// # Example
///
/// ``` /// ```
/// # use actix_web::{App, HttpServer}; /// # use actix_web::{App, HttpServer};
/// # fn inner() -> std::io::Result<()> { /// # fn inner() -> std::io::Result<()> {
@ -356,6 +391,8 @@ where
/// Resolves socket address(es) and binds server to created listener(s) for plaintext HTTP/1.x /// Resolves socket address(es) and binds server to created listener(s) for plaintext HTTP/1.x
/// or HTTP/2 connections. /// or HTTP/2 connections.
///
/// See [`bind()`](Self::bind()) for more details on `addrs` argument.
#[cfg(feature = "http2")] #[cfg(feature = "http2")]
pub fn bind_auto_h2c<A: net::ToSocketAddrs>(mut self, addrs: A) -> io::Result<Self> { pub fn bind_auto_h2c<A: net::ToSocketAddrs>(mut self, addrs: A) -> io::Result<Self> {
let sockets = bind_addrs(addrs, self.backlog)?; let sockets = bind_addrs(addrs, self.backlog)?;
@ -370,7 +407,7 @@ where
/// Resolves socket address(es) and binds server to created listener(s) for TLS connections /// Resolves socket address(es) and binds server to created listener(s) for TLS connections
/// using Rustls v0.20. /// using Rustls v0.20.
/// ///
/// See [`bind()`](Self::bind) for more details on `addrs` argument. /// See [`bind()`](Self::bind()) for more details on `addrs` argument.
/// ///
/// ALPN protocols "h2" and "http/1.1" are added to any configured ones. /// ALPN protocols "h2" and "http/1.1" are added to any configured ones.
#[cfg(feature = "rustls-0_20")] #[cfg(feature = "rustls-0_20")]
@ -389,7 +426,7 @@ where
/// Resolves socket address(es) and binds server to created listener(s) for TLS connections /// Resolves socket address(es) and binds server to created listener(s) for TLS connections
/// using Rustls v0.21. /// using Rustls v0.21.
/// ///
/// See [`bind()`](Self::bind) for more details on `addrs` argument. /// See [`bind()`](Self::bind()) for more details on `addrs` argument.
/// ///
/// ALPN protocols "h2" and "http/1.1" are added to any configured ones. /// ALPN protocols "h2" and "http/1.1" are added to any configured ones.
#[cfg(feature = "rustls-0_21")] #[cfg(feature = "rustls-0_21")]
@ -408,7 +445,7 @@ where
/// Resolves socket address(es) and binds server to created listener(s) for TLS connections /// Resolves socket address(es) and binds server to created listener(s) for TLS connections
/// using OpenSSL. /// using OpenSSL.
/// ///
/// See [`bind()`](Self::bind) for more details on `addrs` argument. /// See [`bind()`](Self::bind()) for more details on `addrs` argument.
/// ///
/// ALPN protocols "h2" and "http/1.1" are added to any configured ones. /// ALPN protocols "h2" and "http/1.1" are added to any configured ones.
#[cfg(feature = "openssl")] #[cfg(feature = "openssl")]

View File

@ -3,6 +3,7 @@
## Unreleased ## Unreleased
- Update `trust-dns-resolver` dependency to `0.23`. - Update `trust-dns-resolver` dependency to `0.23`.
- Updated `zstd` dependency to `0.13`.
## 3.2.0 ## 3.2.0

View File

@ -11,7 +11,7 @@ categories = [
"web-programming::websocket", "web-programming::websocket",
] ]
homepage = "https://actix.rs" homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-web.git" repository = "https://github.com/actix/actix-web"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
edition = "2021" edition = "2021"
@ -111,7 +111,7 @@ static_assertions = "1.1"
rcgen = "0.11" rcgen = "0.11"
rustls-pemfile = "1" rustls-pemfile = "1"
tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros"] } tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros"] }
zstd = "0.12" zstd = "0.13"
[[example]] [[example]]
name = "client" name = "client"