mirror of https://github.com/fafhrd91/actix-web
Compare commits
61 Commits
6881b7b96d
...
b9a9f87559
| Author | SHA1 | Date |
|---|---|---|
|
|
b9a9f87559 | |
|
|
895969923c | |
|
|
024addfc40 | |
|
|
06ad9309b8 | |
|
|
9f9855d1a2 | |
|
|
4c62e88edb | |
|
|
2d84d20ebd | |
|
|
2b8db90c4d | |
|
|
9c70a886b4 | |
|
|
4058f30cb0 | |
|
|
73f6f5ca42 | |
|
|
883a89bfc8 | |
|
|
1556b10379 | |
|
|
41f99b0ddd | |
|
|
917b5f2048 | |
|
|
28843c4ed3 | |
|
|
f192357f09 | |
|
|
d9c676715b | |
|
|
16eba96674 | |
|
|
c7710036de | |
|
|
ff50dd03a6 | |
|
|
24489d4c6d | |
|
|
30b82062a1 | |
|
|
fe6c0a3b2b | |
|
|
37a8b9caa8 | |
|
|
37ff707b52 | |
|
|
a3e428f7fb | |
|
|
f3b64b0f73 | |
|
|
dfb4aa3baf | |
|
|
7ff7768dc4 | |
|
|
2b52a60bc2 | |
|
|
7296f6ffdb | |
|
|
d1706dcdd6 | |
|
|
23fed2298e | |
|
|
360baa3130 | |
|
|
c8a7271d21 | |
|
|
0a9f6c1955 | |
|
|
2f64cdb60a | |
|
|
dcad1d9b89 | |
|
|
d501102610 | |
|
|
013a8ec6b6 | |
|
|
c809ee8440 | |
|
|
585552f70f | |
|
|
57b5937db3 | |
|
|
3506512ed9 | |
|
|
a449695661 | |
|
|
aebab17c1e | |
|
|
ae08dcf6dc | |
|
|
ee7621594c | |
|
|
0548b127c3 | |
|
|
7821ba9c1b | |
|
|
3b99f86e89 | |
|
|
2bb774a529 | |
|
|
a79dc9dc79 | |
|
|
c4be19942b | |
|
|
acd7c58097 | |
|
|
176ea5da77 | |
|
|
91fa813f0e | |
|
|
819ee93e9b | |
|
|
041322ef9c | |
|
|
0d87cc53a1 |
|
|
@ -16,7 +16,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install Rust
|
||||
run: |
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ jobs:
|
|||
runs-on: ${{ matrix.target.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install nasm
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
|
|
@ -49,7 +49,7 @@ jobs:
|
|||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
||||
uses: taiki-e/install-action@f79fe7514db78f0a7bdba3cb6dd9c1baa7d046d9 # v2.62.56
|
||||
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
|
||||
with:
|
||||
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Free Disk Space
|
||||
run: ./scripts/free-disk-space.sh
|
||||
|
|
@ -83,7 +83,7 @@ jobs:
|
|||
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||
|
||||
- name: Install just, cargo-hack
|
||||
uses: taiki-e/install-action@f79fe7514db78f0a7bdba3cb6dd9c1baa7d046d9 # v2.62.56
|
||||
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
|
||||
with:
|
||||
tool: just,cargo-hack
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ jobs:
|
|||
runs-on: ${{ matrix.target.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install nasm
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
|
|
@ -64,7 +64,7 @@ jobs:
|
|||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
||||
uses: taiki-e/install-action@f79fe7514db78f0a7bdba3cb6dd9c1baa7d046d9 # v2.62.56
|
||||
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
|
||||
with:
|
||||
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
||||
|
||||
|
|
@ -87,13 +87,13 @@ jobs:
|
|||
|
||||
- name: deny check
|
||||
if: matrix.version.name == 'stable' && matrix.target.os == 'ubuntu-latest'
|
||||
uses: EmbarkStudios/cargo-deny-action@f2ba7abc2abebaf185c833c3961145a3c275caad # v2.0.13
|
||||
uses: EmbarkStudios/cargo-deny-action@76cd80eb775d7bbbd2d80292136d74d39e1b4918 # v2.0.14
|
||||
|
||||
io-uring:
|
||||
name: io-uring tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||
|
|
@ -109,7 +109,7 @@ jobs:
|
|||
name: doc tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||
|
|
@ -117,7 +117,7 @@ jobs:
|
|||
toolchain: nightly
|
||||
|
||||
- name: Install just
|
||||
uses: taiki-e/install-action@f79fe7514db78f0a7bdba3cb6dd9c1baa7d046d9 # v2.62.56
|
||||
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
|
||||
with:
|
||||
tool: just
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ jobs:
|
|||
coverage:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||
|
|
@ -24,7 +24,7 @@ jobs:
|
|||
components: llvm-tools
|
||||
|
||||
- name: Install just, cargo-llvm-cov, cargo-nextest
|
||||
uses: taiki-e/install-action@f79fe7514db78f0a7bdba3cb6dd9c1baa7d046d9 # v2.62.56
|
||||
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
|
||||
with:
|
||||
tool: just,cargo-llvm-cov,cargo-nextest
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ jobs:
|
|||
fmt:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||
|
|
@ -33,7 +33,7 @@ jobs:
|
|||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||
|
|
@ -52,7 +52,7 @@ jobs:
|
|||
lint-docs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||
|
|
@ -69,7 +69,7 @@ jobs:
|
|||
if: false # rustdoc mismatch currently
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
|
||||
- name: Install Rust (${{ vars.RUST_VERSION_EXTERNAL_TYPES }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||
|
|
@ -77,7 +77,7 @@ jobs:
|
|||
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
||||
|
||||
- name: Install just
|
||||
uses: taiki-e/install-action@f79fe7514db78f0a7bdba3cb6dd9c1baa7d046d9 # v2.62.56
|
||||
uses: taiki-e/install-action@28a9d316db64b78a951f3f8587a5d08cc97ad8eb # v2.65.6
|
||||
with:
|
||||
tool: just
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -19,7 +19,7 @@ homepage = "https://actix.rs"
|
|||
repository = "https://github.com/actix/actix-web"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.75"
|
||||
rust-version = "1.82"
|
||||
|
||||
[profile.dev]
|
||||
# Disabling debug info speeds up builds a bunch and we don't rely on it for debugging that much.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 0.6.9
|
||||
|
||||
- Correct `derive_more` dependency feature requirements.
|
||||
|
||||
## 0.6.8
|
||||
|
||||
- Add `Files::with_permanent_redirect()` method.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "actix-files"
|
||||
version = "0.6.8"
|
||||
version = "0.6.9"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
||||
description = "Static file serving for Actix Web"
|
||||
keywords = ["actix", "http", "async", "futures"]
|
||||
|
|
@ -24,7 +24,7 @@ actix-web = { version = "4", default-features = false }
|
|||
|
||||
bitflags = "2"
|
||||
bytes = "1"
|
||||
derive_more = { version = "2", features = ["display", "error", "from"] }
|
||||
derive_more = { version = "2", features = ["deref", "deref_mut", "display", "error", "from"] }
|
||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
http-range = "0.1.4"
|
||||
log = "0.4"
|
||||
|
|
@ -37,7 +37,7 @@ v_htmlescape = "0.15.5"
|
|||
# experimental-io-uring
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
tokio-uring = { version = "0.5", optional = true, features = ["bytes"] }
|
||||
actix-server = { version = "2.4", optional = true } # ensure matching tokio-uring versions
|
||||
actix-server = { version = "2.4", optional = true } # ensure matching tokio-uring versions
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2.7"
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@
|
|||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-files)
|
||||
[](https://docs.rs/actix-files/0.6.8)
|
||||
[](https://docs.rs/actix-files/0.6.9)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-files/0.6.8)
|
||||
[](https://deps.rs/crate/actix-files/0.6.9)
|
||||
[](https://crates.io/crates/actix-files)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
|
|
|
|||
|
|
@ -294,16 +294,11 @@ mod tests {
|
|||
|
||||
let res = HttpRange::parse(header, size);
|
||||
|
||||
if res.is_err() {
|
||||
if let Err(err) = res {
|
||||
if expected.is_empty() {
|
||||
continue;
|
||||
} else {
|
||||
panic!(
|
||||
"parse({}, {}) returned error {:?}",
|
||||
header,
|
||||
size,
|
||||
res.unwrap_err()
|
||||
);
|
||||
panic!("parse({header}, {size}) returned error {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.72.
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 3.2.0
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 3.11.2
|
||||
|
||||
- Properly wake Payload receivers when feeding errors or EOF.
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ memchr = "2.4"
|
|||
once_cell = "1.21"
|
||||
rcgen = "0.13"
|
||||
regex = "1.3"
|
||||
rustls-pemfile = "2"
|
||||
rustls-pki-types = "1.13.1"
|
||||
rustversion = "1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
|
|
|||
|
|
@ -45,25 +45,14 @@ async fn main() -> io::Result<()> {
|
|||
fn rustls_config() -> rustls::ServerConfig {
|
||||
let rcgen::CertifiedKey { cert, key_pair } =
|
||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||
let cert_file = cert.pem();
|
||||
let key_file = key_pair.serialize_pem();
|
||||
|
||||
let cert_file = &mut io::BufReader::new(cert_file.as_bytes());
|
||||
let key_file = &mut io::BufReader::new(key_file.as_bytes());
|
||||
|
||||
let cert_chain = rustls_pemfile::certs(cert_file)
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
let mut keys = rustls_pemfile::pkcs8_private_keys(key_file)
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
let cert_chain = vec![cert.der().clone()];
|
||||
let key_der = rustls_pki_types::PrivateKeyDer::Pkcs8(
|
||||
rustls_pki_types::PrivatePkcs8KeyDer::from(key_pair.serialize_der()),
|
||||
);
|
||||
|
||||
let mut config = rustls::ServerConfig::builder()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(
|
||||
cert_chain,
|
||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
||||
)
|
||||
.with_single_cert(cert_chain, key_der)
|
||||
.unwrap();
|
||||
|
||||
const H1_ALPN: &[u8] = b"http/1.1";
|
||||
|
|
|
|||
|
|
@ -82,29 +82,16 @@ impl Stream for Heartbeat {
|
|||
}
|
||||
|
||||
fn tls_config() -> rustls::ServerConfig {
|
||||
use std::io::BufReader;
|
||||
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
|
||||
let rcgen::CertifiedKey { cert, key_pair } =
|
||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||
let cert_file = cert.pem();
|
||||
let key_file = key_pair.serialize_pem();
|
||||
|
||||
let cert_file = &mut BufReader::new(cert_file.as_bytes());
|
||||
let key_file = &mut BufReader::new(key_file.as_bytes());
|
||||
|
||||
let cert_chain = certs(cert_file).collect::<Result<Vec<_>, _>>().unwrap();
|
||||
let mut keys = pkcs8_private_keys(key_file)
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
let cert_chain = vec![cert.der().clone()];
|
||||
let key_der = rustls_pki_types::PrivateKeyDer::Pkcs8(
|
||||
rustls_pki_types::PrivatePkcs8KeyDer::from(key_pair.serialize_der()),
|
||||
);
|
||||
|
||||
let mut config = rustls::ServerConfig::builder()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(
|
||||
cert_chain,
|
||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
||||
)
|
||||
.with_single_cert(cert_chain, key_der)
|
||||
.unwrap();
|
||||
|
||||
config.alpn_protocols.push(b"http/1.1".to_vec());
|
||||
|
|
|
|||
|
|
@ -176,11 +176,7 @@ impl Inner {
|
|||
/// Register future waiting data from payload.
|
||||
/// Waker would be used in `Inner::wake`
|
||||
fn register(&mut self, cx: &Context<'_>) {
|
||||
if self
|
||||
.task
|
||||
.as_ref()
|
||||
.map_or(true, |w| !cx.waker().will_wake(w))
|
||||
{
|
||||
if self.task.as_ref().is_none_or(|w| !cx.waker().will_wake(w)) {
|
||||
self.task = Some(cx.waker().clone());
|
||||
}
|
||||
}
|
||||
|
|
@ -191,7 +187,7 @@ impl Inner {
|
|||
if self
|
||||
.io_task
|
||||
.as_ref()
|
||||
.map_or(true, |w| !cx.waker().will_wake(w))
|
||||
.is_none_or(|w| !cx.waker().will_wake(w))
|
||||
{
|
||||
self.io_task = Some(cx.waker().clone());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ extern crate tls_rustls_023 as rustls;
|
|||
|
||||
use std::{
|
||||
convert::Infallible,
|
||||
io::{self, BufReader, Write},
|
||||
io::{self, Write},
|
||||
net::{SocketAddr, TcpStream as StdTcpStream},
|
||||
sync::Arc,
|
||||
task::Poll,
|
||||
|
|
@ -27,7 +27,7 @@ use derive_more::{Display, Error};
|
|||
use futures_core::{ready, Stream};
|
||||
use futures_util::stream::once;
|
||||
use rustls::{pki_types::ServerName, ServerConfig as RustlsServerConfig};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
use rustls_pki_types::{PrivateKeyDer, PrivatePkcs8KeyDer};
|
||||
|
||||
async fn load_body<S>(stream: S) -> Result<BytesMut, PayloadError>
|
||||
where
|
||||
|
|
@ -54,23 +54,12 @@ where
|
|||
fn tls_config() -> RustlsServerConfig {
|
||||
let rcgen::CertifiedKey { cert, key_pair } =
|
||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||
let cert_file = cert.pem();
|
||||
let key_file = key_pair.serialize_pem();
|
||||
|
||||
let cert_file = &mut BufReader::new(cert_file.as_bytes());
|
||||
let key_file = &mut BufReader::new(key_file.as_bytes());
|
||||
|
||||
let cert_chain = certs(cert_file).collect::<Result<Vec<_>, _>>().unwrap();
|
||||
let mut keys = pkcs8_private_keys(key_file)
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
let cert_chain = vec![cert.der().clone()];
|
||||
let key_der = PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key_pair.serialize_der()));
|
||||
|
||||
let mut config = RustlsServerConfig::builder()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(
|
||||
cert_chain,
|
||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
||||
)
|
||||
.with_single_cert(cert_chain, key_der)
|
||||
.unwrap();
|
||||
|
||||
config.alpn_protocols.push(HTTP1_1_ALPN_PROTOCOL.to_vec());
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 0.7.0
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.72.
|
||||
|
|
|
|||
|
|
@ -16,19 +16,14 @@ use proc_macro2::Ident;
|
|||
use quote::quote;
|
||||
use syn::{parse_macro_input, Type};
|
||||
|
||||
#[derive(FromMeta)]
|
||||
#[derive(Default, FromMeta)]
|
||||
enum DuplicateField {
|
||||
#[default]
|
||||
Ignore,
|
||||
Deny,
|
||||
Replace,
|
||||
}
|
||||
|
||||
impl Default for DuplicateField {
|
||||
fn default() -> Self {
|
||||
Self::Ignore
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromDeriveInput, Default)]
|
||||
#[darling(attributes(multipart), default)]
|
||||
struct MultipartFormAttrs {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error: Could not parse size limit `2 bytes`: couldn't parse "bytes" into a known SI unit, couldn't parse unit of "bytes"
|
||||
error: Could not parse size limit `2 bytes`: couldn't parse "bytes" into a known SI unit, Failed to parse unit "byt..."
|
||||
--> tests/trybuild/size-limit-parse-fail.rs:6:5
|
||||
|
|
||||
6 | description: Text<String>,
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: Could not parse size limit `2 megabytes`: couldn't parse "megabytes" into a known SI unit, couldn't parse unit of "megabytes"
|
||||
error: Could not parse size limit `2 megabytes`: couldn't parse "megabytes" into a known SI unit, Failed to parse unit "meg..."
|
||||
--> tests/trybuild/size-limit-parse-fail.rs:12:5
|
||||
|
|
||||
12 | description: Text<String>,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 0.7.2
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 0.5.3
|
||||
|
||||
- Add `unicode` crate feature (on-by-default) to switch between `regex` and `regex-lite` as a trade-off between full unicode support and binary size.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 0.1.5
|
||||
|
||||
- Add `TestServerConfig::listen_address()` method.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 4.3.1 <!-- v4.3.1+deprecated -->
|
||||
|
||||
- Reduce memory usage by `take`-ing (rather than `split`-ing) the encoded buffer when yielding bytes in the response stream.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 4.3.0
|
||||
|
||||
- Add `#[scope]` macro.
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
|||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the following other types implement trait `HttpServiceFactory`:
|
||||
Resource<T>
|
||||
actix_web::Scope<T>
|
||||
Vec<T>
|
||||
Redirect
|
||||
(A,)
|
||||
(A, B)
|
||||
(A, B, C)
|
||||
(A, B, C, D)
|
||||
(A, B, C, D, E)
|
||||
(A, B, C, D, E, F)
|
||||
(A, B, C, D, E, F, G)
|
||||
(A, B, C, D, E, F, G, H)
|
||||
(A, B, C, D, E, F, G, H, I)
|
||||
and $N others
|
||||
note: required by a bound in `App::<T>::service`
|
||||
--> $WORKSPACE/actix-web/src/app.rs
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
|||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the following other types implement trait `HttpServiceFactory`:
|
||||
Resource<T>
|
||||
actix_web::Scope<T>
|
||||
Vec<T>
|
||||
Redirect
|
||||
(A,)
|
||||
(A, B)
|
||||
(A, B, C)
|
||||
(A, B, C, D)
|
||||
(A, B, C, D, E)
|
||||
(A, B, C, D, E, F)
|
||||
(A, B, C, D, E, F, G)
|
||||
(A, B, C, D, E, F, G, H)
|
||||
(A, B, C, D, E, F, G, H, I)
|
||||
and $N others
|
||||
note: required by a bound in `App::<T>::service`
|
||||
--> $WORKSPACE/actix-web/src/app.rs
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
|||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the following other types implement trait `HttpServiceFactory`:
|
||||
Resource<T>
|
||||
actix_web::Scope<T>
|
||||
Vec<T>
|
||||
Redirect
|
||||
(A,)
|
||||
(A, B)
|
||||
(A, B, C)
|
||||
(A, B, C, D)
|
||||
(A, B, C, D, E)
|
||||
(A, B, C, D, E, F)
|
||||
(A, B, C, D, E, F, G)
|
||||
(A, B, C, D, E, F, G, H)
|
||||
(A, B, C, D, E, F, G, H, I)
|
||||
and $N others
|
||||
note: required by a bound in `App::<T>::service`
|
||||
--> $WORKSPACE/actix-web/src/app.rs
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
|||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the following other types implement trait `HttpServiceFactory`:
|
||||
Resource<T>
|
||||
actix_web::Scope<T>
|
||||
Vec<T>
|
||||
Redirect
|
||||
(A,)
|
||||
(A, B)
|
||||
(A, B, C)
|
||||
(A, B, C, D)
|
||||
(A, B, C, D, E)
|
||||
(A, B, C, D, E, F)
|
||||
(A, B, C, D, E, F, G)
|
||||
(A, B, C, D, E, F, G, H)
|
||||
(A, B, C, D, E, F, G, H, I)
|
||||
and $N others
|
||||
note: required by a bound in `App::<T>::service`
|
||||
--> $WORKSPACE/actix-web/src/app.rs
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
|||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the following other types implement trait `HttpServiceFactory`:
|
||||
Resource<T>
|
||||
actix_web::Scope<T>
|
||||
Vec<T>
|
||||
Redirect
|
||||
(A,)
|
||||
(A, B)
|
||||
(A, B, C)
|
||||
(A, B, C, D)
|
||||
(A, B, C, D, E)
|
||||
(A, B, C, D, E, F)
|
||||
(A, B, C, D, E, F, G)
|
||||
(A, B, C, D, E, F, G, H)
|
||||
(A, B, C, D, E, F, G, H, I)
|
||||
and $N others
|
||||
note: required by a bound in `App::<T>::service`
|
||||
--> $WORKSPACE/actix-web/src/app.rs
|
||||
|
|
|
|||
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Add `experimental-introspection` feature for retrieving configured route paths and HTTP methods.
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 4.12.1
|
||||
|
||||
- Correct `actix-http` dependency requirement.
|
||||
|
||||
## 4.12.0
|
||||
|
||||
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now sets `Content-Type` to `application/octet-stream` if `Content-Type` does not exist.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "actix-web"
|
||||
version = "4.12.0"
|
||||
version = "4.12.1"
|
||||
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
||||
keywords = ["actix", "http", "web", "framework", "async"]
|
||||
|
|
@ -125,6 +125,9 @@ compat = ["compat-routing-macros-force-pub"]
|
|||
# Opt-out forwards-compatibility for handler visibility inheritance fix.
|
||||
compat-routing-macros-force-pub = ["actix-web-codegen?/compat-routing-macros-force-pub"]
|
||||
|
||||
# Enabling the retrieval of metadata for initialized resources, including path and HTTP method.
|
||||
experimental-introspection = []
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.5"
|
||||
actix-macros = { version = "0.2.3", optional = true }
|
||||
|
|
@ -134,7 +137,7 @@ actix-service = "2"
|
|||
actix-tls = { version = "3.4", default-features = false, optional = true }
|
||||
actix-utils = "3"
|
||||
|
||||
actix-http = "3.11"
|
||||
actix-http = "3.11.2"
|
||||
actix-router = { version = "0.5.3", default-features = false, features = ["http"] }
|
||||
actix-web-codegen = { version = "4.3", optional = true, default-features = false }
|
||||
|
||||
|
|
@ -179,7 +182,7 @@ flate2 = "1.0.13"
|
|||
futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
|
||||
rand = "0.9"
|
||||
rcgen = "0.13"
|
||||
rustls-pemfile = "2"
|
||||
rustls-pki-types = "1.13.1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
static_assertions = "1"
|
||||
tls-openssl = { package = "openssl", version = "0.10.55" }
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web)
|
||||
[](https://docs.rs/actix-web/4.12.0)
|
||||
[](https://docs.rs/actix-web/4.12.1)
|
||||

|
||||

|
||||
[](https://deps.rs/crate/actix-web/4.12.0)
|
||||
[](https://deps.rs/crate/actix-web/4.12.1)
|
||||
<br />
|
||||
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
||||
[](https://codecov.io/gh/actix/actix-web)
|
||||
|
|
@ -78,23 +78,23 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
### More Examples
|
||||
|
||||
- [Hello World](https://github.com/actix/examples/tree/mainasics/hello-world)
|
||||
- [Basic Setup](https://github.com/actix/examples/tree/mainasics/basics)
|
||||
- [Application State](https://github.com/actix/examples/tree/mainasics/state)
|
||||
- [JSON Handling](https://github.com/actix/examples/tree/mainson/json)
|
||||
- [Multipart Streams](https://github.com/actix/examples/tree/mainorms/multipart)
|
||||
- [MongoDB Integration](https://github.com/actix/examples/tree/mainatabases/mongodb)
|
||||
- [Diesel Integration](https://github.com/actix/examples/tree/mainatabases/diesel)
|
||||
- [SQLite Integration](https://github.com/actix/examples/tree/mainatabases/sqlite)
|
||||
- [Postgres Integration](https://github.com/actix/examples/tree/mainatabases/postgres)
|
||||
- [Tera Templates](https://github.com/actix/examples/tree/mainemplating/tera)
|
||||
- [Askama Templates](https://github.com/actix/examples/tree/mainemplating/askama)
|
||||
- [HTTPS using Rustls](https://github.com/actix/examples/tree/mainttps-tls/rustls)
|
||||
- [HTTPS using OpenSSL](https://github.com/actix/examples/tree/mainttps-tls/openssl)
|
||||
- [Simple WebSocket](https://github.com/actix/examples/tree/mainebsockets)
|
||||
- [WebSocket Chat](https://github.com/actix/examples/tree/mainebsockets/chat)
|
||||
- [Hello World](https://github.com/actix/examples/tree/main/basics/hello-world)
|
||||
- [Basic Setup](https://github.com/actix/examples/tree/main/basics/basics)
|
||||
- [Application State](https://github.com/actix/examples/tree/main/basics/state)
|
||||
- [JSON Handling](https://github.com/actix/examples/tree/main/json/json)
|
||||
- [Multipart Streams](https://github.com/actix/examples/tree/main/forms/multipart)
|
||||
- [MongoDB Integration](https://github.com/actix/examples/tree/main/databases/mongodb)
|
||||
- [Diesel Integration](https://github.com/actix/examples/tree/main/databases/diesel)
|
||||
- [SQLite Integration](https://github.com/actix/examples/tree/main/databases/sqlite)
|
||||
- [Postgres Integration](https://github.com/actix/examples/tree/main/databases/postgres)
|
||||
- [Tera Templates](https://github.com/actix/examples/tree/main/templating/tera)
|
||||
- [Askama Templates](https://github.com/actix/examples/tree/main/templating/askama)
|
||||
- [HTTPS using Rustls](https://github.com/actix/examples/tree/main/https-tls/rustls)
|
||||
- [HTTPS using OpenSSL](https://github.com/actix/examples/tree/main/https-tls/openssl)
|
||||
- [Simple WebSocket](https://github.com/actix/examples/tree/main/websockets)
|
||||
- [WebSocket Chat](https://github.com/actix/examples/tree/main/websockets/chat)
|
||||
|
||||
You may consider checking out [this directory](https://github.com/actix/examples/tree/mainfor more examples.
|
||||
You may consider checking out [this directory](https://github.com/actix/examples/tree/main) for more examples.
|
||||
|
||||
## Benchmarks
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,255 @@
|
|||
// Example showcasing the experimental introspection feature.
|
||||
// Run with: `cargo run --features experimental-introspection --example introspection`
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
{
|
||||
use actix_web::{dev::Service, guard, web, App, HttpResponse, HttpServer, Responder};
|
||||
use serde::Deserialize;
|
||||
|
||||
// Initialize logging
|
||||
env_logger::Builder::new()
|
||||
.filter_level(log::LevelFilter::Debug)
|
||||
.init();
|
||||
|
||||
// Custom guard to check if the Content-Type header is present.
|
||||
struct ContentTypeGuard;
|
||||
|
||||
impl guard::Guard for ContentTypeGuard {
|
||||
fn check(&self, req: &guard::GuardContext<'_>) -> bool {
|
||||
req.head()
|
||||
.headers()
|
||||
.contains_key(actix_web::http::header::CONTENT_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
// Data structure for endpoints that receive JSON.
|
||||
#[derive(Deserialize)]
|
||||
struct UserInfo {
|
||||
username: String,
|
||||
age: u8,
|
||||
}
|
||||
|
||||
// GET /introspection for JSON response
|
||||
async fn introspection_handler_json(
|
||||
tree: web::Data<actix_web::introspection::IntrospectionTree>,
|
||||
) -> impl Responder {
|
||||
let report = tree.report_as_json();
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(report)
|
||||
}
|
||||
|
||||
// GET /introspection for plain text response
|
||||
async fn introspection_handler_text(
|
||||
tree: web::Data<actix_web::introspection::IntrospectionTree>,
|
||||
) -> impl Responder {
|
||||
let report = tree.report_as_text();
|
||||
HttpResponse::Ok().content_type("text/plain").body(report)
|
||||
}
|
||||
|
||||
// GET /api/v1/item/{id} and GET /v1/item/{id}
|
||||
#[actix_web::get("/item/{id}")]
|
||||
async fn get_item(path: web::Path<u32>) -> impl Responder {
|
||||
let id = path.into_inner();
|
||||
HttpResponse::Ok().body(format!("Requested item with id: {}", id))
|
||||
}
|
||||
|
||||
// POST /api/v1/info
|
||||
#[actix_web::post("/info")]
|
||||
async fn post_user_info(info: web::Json<UserInfo>) -> impl Responder {
|
||||
HttpResponse::Ok().json(format!(
|
||||
"User {} with age {} received",
|
||||
info.username, info.age
|
||||
))
|
||||
}
|
||||
|
||||
// /api/v1/guarded
|
||||
async fn guarded_handler() -> impl Responder {
|
||||
HttpResponse::Ok().body("Passed the Content-Type guard!")
|
||||
}
|
||||
|
||||
// GET /api/v2/hello
|
||||
async fn hello_v2() -> impl Responder {
|
||||
HttpResponse::Ok().body("Hello from API v2!")
|
||||
}
|
||||
|
||||
// GET /admin/dashboard
|
||||
async fn admin_dashboard() -> impl Responder {
|
||||
HttpResponse::Ok().body("Welcome to the Admin Dashboard!")
|
||||
}
|
||||
|
||||
// GET /admin/settings
|
||||
async fn get_settings() -> impl Responder {
|
||||
HttpResponse::Ok().body("Current settings: ...")
|
||||
}
|
||||
|
||||
// POST /admin/settings
|
||||
async fn update_settings() -> impl Responder {
|
||||
HttpResponse::Ok().body("Settings have been updated!")
|
||||
}
|
||||
|
||||
// GET and POST on /
|
||||
async fn root_index() -> impl Responder {
|
||||
HttpResponse::Ok().body("Welcome to the Root Endpoint!")
|
||||
}
|
||||
|
||||
// Additional endpoints for /extra
|
||||
fn extra_endpoints(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
web::scope("/extra")
|
||||
.route(
|
||||
"/ping",
|
||||
web::get().to(|| async { HttpResponse::Ok().body("pong") }), // GET /extra/ping
|
||||
)
|
||||
.service(
|
||||
web::resource("/multi")
|
||||
.route(web::get().to(|| async {
|
||||
HttpResponse::Ok().body("GET response from /extra/multi")
|
||||
})) // GET /extra/multi
|
||||
.route(web::post().to(|| async {
|
||||
HttpResponse::Ok().body("POST response from /extra/multi")
|
||||
})), // POST /extra/multi
|
||||
)
|
||||
.service(
|
||||
web::scope("{entities_id:\\d+}")
|
||||
.service(
|
||||
web::scope("/secure")
|
||||
.route(
|
||||
"",
|
||||
web::get().to(|| async {
|
||||
HttpResponse::Ok()
|
||||
.body("GET response from /extra/secure")
|
||||
}),
|
||||
) // GET /extra/{entities_id}/secure/
|
||||
.route(
|
||||
"/post",
|
||||
web::post().to(|| async {
|
||||
HttpResponse::Ok()
|
||||
.body("POST response from /extra/secure")
|
||||
}),
|
||||
), // POST /extra/{entities_id}/secure/post
|
||||
)
|
||||
.wrap_fn(|req, srv| {
|
||||
println!(
|
||||
"Request to /extra/secure with id: {}",
|
||||
req.match_info().get("entities_id").unwrap()
|
||||
);
|
||||
let fut = srv.call(req);
|
||||
async move {
|
||||
let res = fut.await?;
|
||||
Ok(res)
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Additional endpoints for /foo
|
||||
fn other_endpoints(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(
|
||||
web::scope("/extra")
|
||||
.route(
|
||||
"/ping",
|
||||
web::post()
|
||||
.to(|| async { HttpResponse::Ok().body("post from /extra/ping") }), // POST /foo/extra/ping
|
||||
)
|
||||
.route(
|
||||
"/ping",
|
||||
web::delete()
|
||||
.to(|| async { HttpResponse::Ok().body("delete from /extra/ping") }), // DELETE /foo/extra/ping
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Create the HTTP server with all the routes and handlers
|
||||
let server = HttpServer::new(|| {
|
||||
App::new()
|
||||
// Get introspection report
|
||||
// curl --location '127.0.0.1:8080/introspection' --header 'Accept: application/json'
|
||||
// curl --location '127.0.0.1:8080/introspection' --header 'Accept: text/plain'
|
||||
.service(
|
||||
web::resource("/introspection")
|
||||
.route(
|
||||
web::get()
|
||||
.guard(guard::Header("accept", "application/json"))
|
||||
.to(introspection_handler_json),
|
||||
)
|
||||
.route(
|
||||
web::get()
|
||||
.guard(guard::Header("accept", "text/plain"))
|
||||
.to(introspection_handler_text),
|
||||
),
|
||||
)
|
||||
// API endpoints under /api
|
||||
.service(
|
||||
web::scope("/api")
|
||||
// Endpoints under /api/v1
|
||||
.service(
|
||||
web::scope("/v1")
|
||||
.service(get_item) // GET /api/v1/item/{id}
|
||||
.service(post_user_info) // POST /api/v1/info
|
||||
.route(
|
||||
"/guarded",
|
||||
web::route().guard(ContentTypeGuard).to(guarded_handler), // /api/v1/guarded
|
||||
),
|
||||
)
|
||||
// Endpoints under /api/v2
|
||||
.service(web::scope("/v2").route("/hello", web::get().to(hello_v2))), // GET /api/v2/hello
|
||||
)
|
||||
// Endpoints under /v1 (outside /api)
|
||||
.service(web::scope("/v1").service(get_item)) // GET /v1/item/{id}
|
||||
// Admin endpoints under /admin
|
||||
.service(
|
||||
web::scope("/admin")
|
||||
.route("/dashboard", web::get().to(admin_dashboard)) // GET /admin/dashboard
|
||||
.service(
|
||||
web::resource("/settings")
|
||||
.route(web::get().to(get_settings)) // GET /admin/settings
|
||||
.route(web::post().to(update_settings)), // POST /admin/settings
|
||||
),
|
||||
)
|
||||
// Root endpoints
|
||||
.service(
|
||||
web::resource("/")
|
||||
.route(web::get().to(root_index)) // GET /
|
||||
.route(web::post().to(root_index)), // POST /
|
||||
)
|
||||
// Endpoints under /bar
|
||||
.service(web::scope("/bar").configure(extra_endpoints)) // /bar/extra/ping, /bar/extra/multi, etc.
|
||||
// Endpoints under /foo
|
||||
.service(web::scope("/foo").configure(other_endpoints)) // /foo/extra/ping with POST and DELETE
|
||||
// Additional endpoints under /extra
|
||||
.configure(extra_endpoints) // /extra/ping, /extra/multi, etc.
|
||||
.configure(other_endpoints)
|
||||
// Endpoint that rejects GET on /not_guard (allows other methods)
|
||||
.route(
|
||||
"/not_guard",
|
||||
web::route()
|
||||
.guard(guard::Not(guard::Get()))
|
||||
.to(HttpResponse::MethodNotAllowed),
|
||||
)
|
||||
// Endpoint that requires GET with header or POST on /all_guard
|
||||
.route(
|
||||
"/all_guard",
|
||||
web::route()
|
||||
.guard(
|
||||
guard::All(guard::Get())
|
||||
.and(guard::Header("content-type", "plain/text"))
|
||||
.and(guard::Any(guard::Post())),
|
||||
)
|
||||
.to(HttpResponse::MethodNotAllowed),
|
||||
)
|
||||
})
|
||||
.workers(5)
|
||||
.bind("127.0.0.1:8080")?;
|
||||
|
||||
server.run().await
|
||||
}
|
||||
#[cfg(not(feature = "experimental-introspection"))]
|
||||
{
|
||||
eprintln!("This example requires the 'experimental-introspection' feature to be enabled.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
// Example showcasing the experimental introspection feature with multiple App instances.
|
||||
// Run with: `cargo run --features experimental-introspection --example introspection_multi_servers`
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
{
|
||||
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
||||
use futures_util::future;
|
||||
|
||||
async fn introspection_handler(
|
||||
tree: web::Data<actix_web::introspection::IntrospectionTree>,
|
||||
) -> impl Responder {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/plain")
|
||||
.body(tree.report_as_text())
|
||||
}
|
||||
|
||||
async fn index() -> impl Responder {
|
||||
HttpResponse::Ok().body("Hello from app")
|
||||
}
|
||||
|
||||
let srv1 = HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(web::resource("/a").route(web::get().to(index)))
|
||||
.service(
|
||||
web::resource("/introspection").route(web::get().to(introspection_handler)),
|
||||
)
|
||||
})
|
||||
.workers(8)
|
||||
.bind("127.0.0.1:8081")?
|
||||
.run();
|
||||
|
||||
let srv2 = HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(web::resource("/b").route(web::get().to(index)))
|
||||
.service(
|
||||
web::resource("/introspection").route(web::get().to(introspection_handler)),
|
||||
)
|
||||
})
|
||||
.workers(3)
|
||||
.bind("127.0.0.1:8082")?
|
||||
.run();
|
||||
|
||||
future::try_join(srv1, srv2).await?;
|
||||
}
|
||||
#[cfg(not(feature = "experimental-introspection"))]
|
||||
{
|
||||
eprintln!("This example requires the 'experimental-introspection' feature to be enabled.");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -30,6 +30,8 @@ pub struct App<T> {
|
|||
data_factories: Vec<FnDataFactory>,
|
||||
external: Vec<ResourceDef>,
|
||||
extensions: Extensions,
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
introspector: Rc<RefCell<crate::introspection::IntrospectionCollector>>,
|
||||
}
|
||||
|
||||
impl App<AppEntry> {
|
||||
|
|
@ -46,6 +48,10 @@ impl App<AppEntry> {
|
|||
factory_ref,
|
||||
external: Vec::new(),
|
||||
extensions: Extensions::new(),
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
introspector: Rc::new(RefCell::new(
|
||||
crate::introspection::IntrospectionCollector::new(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -366,6 +372,8 @@ where
|
|||
factory_ref: self.factory_ref,
|
||||
external: self.external,
|
||||
extensions: self.extensions,
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
introspector: self.introspector,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -429,6 +437,8 @@ where
|
|||
factory_ref: self.factory_ref,
|
||||
external: self.external,
|
||||
extensions: self.extensions,
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
introspector: self.introspector,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -453,6 +463,8 @@ where
|
|||
default: self.default,
|
||||
factory_ref: self.factory_ref,
|
||||
extensions: RefCell::new(Some(self.extensions)),
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
introspector: Rc::clone(&self.introspector),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ where
|
|||
pub(crate) default: Option<Rc<BoxedHttpServiceFactory>>,
|
||||
pub(crate) factory_ref: Rc<RefCell<Option<AppRoutingFactory>>>,
|
||||
pub(crate) external: RefCell<Vec<ResourceDef>>,
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
pub(crate) introspector: Rc<RefCell<crate::introspection::IntrospectionCollector>>,
|
||||
}
|
||||
|
||||
impl<T, B> ServiceFactory<Request> for AppInit<T, B>
|
||||
|
|
@ -72,6 +74,10 @@ where
|
|||
|
||||
// create App config to pass to child services
|
||||
let mut config = AppService::new(config, Rc::clone(&default));
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
{
|
||||
config.introspector = Rc::clone(&self.introspector);
|
||||
}
|
||||
|
||||
// register services
|
||||
mem::take(&mut *self.services.borrow_mut())
|
||||
|
|
@ -80,6 +86,9 @@ where
|
|||
|
||||
let mut rmap = ResourceMap::new(ResourceDef::prefix(""));
|
||||
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
let (config, services, _) = config.into_services();
|
||||
#[cfg(not(feature = "experimental-introspection"))]
|
||||
let (config, services) = config.into_services();
|
||||
|
||||
// complete pipeline creation.
|
||||
|
|
@ -110,6 +119,8 @@ where
|
|||
|
||||
// construct app service and middleware service factory future.
|
||||
let endpoint_fut = self.endpoint.new_service(());
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
let introspector = Rc::clone(&self.introspector);
|
||||
|
||||
// take extensions or create new one as app data container.
|
||||
let mut app_data = self.extensions.borrow_mut().take().unwrap_or_default();
|
||||
|
|
@ -130,6 +141,12 @@ where
|
|||
factory.create(&mut app_data);
|
||||
}
|
||||
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
{
|
||||
let tree = introspector.borrow_mut().finalize();
|
||||
app_data.insert(crate::web::Data::new(tree));
|
||||
}
|
||||
|
||||
Ok(AppInitService {
|
||||
service,
|
||||
app_data: Rc::new(app_data),
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ pub struct AppService {
|
|||
Option<Guards>,
|
||||
Option<Rc<ResourceMap>>,
|
||||
)>,
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
pub current_prefix: String,
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
pub(crate) introspector:
|
||||
std::rc::Rc<std::cell::RefCell<crate::introspection::IntrospectionCollector>>,
|
||||
}
|
||||
|
||||
impl AppService {
|
||||
|
|
@ -40,6 +45,12 @@ impl AppService {
|
|||
default,
|
||||
root: true,
|
||||
services: Vec::new(),
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
current_prefix: "".to_string(),
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
introspector: std::rc::Rc::new(std::cell::RefCell::new(
|
||||
crate::introspection::IntrospectionCollector::new(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +60,24 @@ impl AppService {
|
|||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
pub(crate) fn into_services(
|
||||
self,
|
||||
) -> (
|
||||
AppConfig,
|
||||
Vec<(
|
||||
ResourceDef,
|
||||
BoxedHttpServiceFactory,
|
||||
Option<Guards>,
|
||||
Option<Rc<ResourceMap>>,
|
||||
)>,
|
||||
std::rc::Rc<std::cell::RefCell<crate::introspection::IntrospectionCollector>>,
|
||||
) {
|
||||
(self.config, self.services, self.introspector)
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[cfg(not(feature = "experimental-introspection"))]
|
||||
pub(crate) fn into_services(
|
||||
self,
|
||||
) -> (
|
||||
|
|
@ -71,6 +100,10 @@ impl AppService {
|
|||
default: Rc::clone(&self.default),
|
||||
services: Vec::new(),
|
||||
root: false,
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
current_prefix: self.current_prefix.clone(),
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
introspector: std::rc::Rc::clone(&self.introspector),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,9 +134,70 @@ impl AppService {
|
|||
InitError = (),
|
||||
> + 'static,
|
||||
{
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
{
|
||||
use std::borrow::Borrow;
|
||||
|
||||
// Build the full path for introspection
|
||||
let pat = rdef.pattern().unwrap_or("").to_string();
|
||||
|
||||
let full_path = if self.current_prefix.is_empty() {
|
||||
pat.clone()
|
||||
} else {
|
||||
format!(
|
||||
"{}/{}",
|
||||
self.current_prefix.trim_end_matches('/'),
|
||||
pat.trim_start_matches('/')
|
||||
)
|
||||
};
|
||||
|
||||
// Extract methods and guards for introspection
|
||||
let guard_list: &[Box<dyn Guard>] = guards.borrow().as_ref().map_or(&[], |v| &v[..]);
|
||||
let methods = guard_list
|
||||
.iter()
|
||||
.flat_map(|g| g.details().unwrap_or_default())
|
||||
.flat_map(|d| {
|
||||
if let crate::guard::GuardDetail::HttpMethods(v) = d {
|
||||
v.into_iter()
|
||||
.filter_map(|s| s.parse().ok())
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let guard_names = guard_list
|
||||
.iter()
|
||||
.map(|g| g.name().to_string())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Determine if the registered service is a resource
|
||||
let is_resource = rdef.pattern().is_some();
|
||||
self.introspector.borrow_mut().register_pattern_detail(
|
||||
full_path,
|
||||
methods,
|
||||
guard_names,
|
||||
is_resource,
|
||||
);
|
||||
}
|
||||
|
||||
self.services
|
||||
.push((rdef, boxed::factory(factory.into_factory()), guards, nested));
|
||||
}
|
||||
|
||||
/// Update the current path prefix.
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
pub(crate) fn update_prefix(&mut self, prefix: &str) {
|
||||
self.current_prefix = if self.current_prefix.is_empty() {
|
||||
prefix.to_string()
|
||||
} else {
|
||||
format!(
|
||||
"{}/{}",
|
||||
self.current_prefix.trim_end_matches('/'),
|
||||
prefix.trim_start_matches('/')
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Application connection config.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
//! or handler. This interface is defined by the [`Guard`] trait.
|
||||
//!
|
||||
//! Commonly-used guards are provided in this module as well as a way of creating a guard from a
|
||||
//! closure ([`fn_guard`]). The [`Not`], [`Any`], and [`All`] guards are noteworthy, as they can be
|
||||
//! closure ([`fn_guard`]). The [`Not`], [`Any()`], and [`All()`] guards are noteworthy, as they can be
|
||||
//! used to compose other guards in a more flexible and semantic way than calling `.guard(...)` on
|
||||
//! services multiple times (which might have different combining behavior than you want).
|
||||
//!
|
||||
|
|
@ -66,6 +66,17 @@ pub use self::{
|
|||
host::{Host, HostGuard},
|
||||
};
|
||||
|
||||
/// Enum to encapsulate various introspection details of a Guard.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum GuardDetail {
|
||||
/// Detail associated with HTTP methods.
|
||||
HttpMethods(Vec<String>),
|
||||
/// Detail associated with headers (header, value).
|
||||
Headers(Vec<(String, String)>),
|
||||
/// Generic detail.
|
||||
Generic(String),
|
||||
}
|
||||
|
||||
/// Provides access to request parts that are useful during routing.
|
||||
#[derive(Debug)]
|
||||
pub struct GuardContext<'a> {
|
||||
|
|
@ -124,12 +135,28 @@ impl<'a> GuardContext<'a> {
|
|||
pub trait Guard {
|
||||
/// Returns true if predicate condition is met for a given request.
|
||||
fn check(&self, ctx: &GuardContext<'_>) -> bool;
|
||||
|
||||
/// Returns a nominal representation of the guard.
|
||||
fn name(&self) -> String {
|
||||
std::any::type_name::<Self>().to_string()
|
||||
}
|
||||
|
||||
/// Returns detailed introspection information.
|
||||
fn details(&self) -> Option<Vec<GuardDetail>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Guard for Rc<dyn Guard> {
|
||||
fn check(&self, ctx: &GuardContext<'_>) -> bool {
|
||||
(**self).check(ctx)
|
||||
}
|
||||
fn name(&self) -> String {
|
||||
(**self).name()
|
||||
}
|
||||
fn details(&self) -> Option<Vec<GuardDetail>> {
|
||||
(**self).details()
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a guard using the given function.
|
||||
|
|
@ -195,7 +222,7 @@ pub fn Any<F: Guard + 'static>(guard: F) -> AnyGuard {
|
|||
///
|
||||
/// That is, only one contained guard needs to match in order for the aggregate guard to match.
|
||||
///
|
||||
/// Construct an `AnyGuard` using [`Any`].
|
||||
/// Construct an `AnyGuard` using [`Any()`].
|
||||
pub struct AnyGuard {
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
}
|
||||
|
|
@ -219,6 +246,24 @@ impl Guard for AnyGuard {
|
|||
|
||||
false
|
||||
}
|
||||
fn name(&self) -> String {
|
||||
format!(
|
||||
"AnyGuard({})",
|
||||
self.guards
|
||||
.iter()
|
||||
.map(|g| g.name())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
fn details(&self) -> Option<Vec<GuardDetail>> {
|
||||
Some(
|
||||
self.guards
|
||||
.iter()
|
||||
.flat_map(|g| g.details().unwrap_or_default())
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a guard that matches if all added guards match.
|
||||
|
|
@ -247,7 +292,7 @@ pub fn All<F: Guard + 'static>(guard: F) -> AllGuard {
|
|||
///
|
||||
/// That is, **all** contained guard needs to match in order for the aggregate guard to match.
|
||||
///
|
||||
/// Construct an `AllGuard` using [`All`].
|
||||
/// Construct an `AllGuard` using [`All()`].
|
||||
pub struct AllGuard {
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
}
|
||||
|
|
@ -271,6 +316,24 @@ impl Guard for AllGuard {
|
|||
|
||||
true
|
||||
}
|
||||
fn name(&self) -> String {
|
||||
format!(
|
||||
"AllGuard({})",
|
||||
self.guards
|
||||
.iter()
|
||||
.map(|g| g.name())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
fn details(&self) -> Option<Vec<GuardDetail>> {
|
||||
Some(
|
||||
self.guards
|
||||
.iter()
|
||||
.flat_map(|g| g.details().unwrap_or_default())
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps a guard and inverts the outcome of its `Guard` implementation.
|
||||
|
|
@ -291,6 +354,12 @@ impl<G: Guard> Guard for Not<G> {
|
|||
fn check(&self, ctx: &GuardContext<'_>) -> bool {
|
||||
!self.0.check(ctx)
|
||||
}
|
||||
fn name(&self) -> String {
|
||||
format!("Not({})", self.0.name())
|
||||
}
|
||||
fn details(&self) -> Option<Vec<GuardDetail>> {
|
||||
self.0.details()
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a guard that matches a specified HTTP method.
|
||||
|
|
@ -320,6 +389,12 @@ impl Guard for MethodGuard {
|
|||
|
||||
ctx.head().method == self.0
|
||||
}
|
||||
fn name(&self) -> String {
|
||||
self.0.to_string()
|
||||
}
|
||||
fn details(&self) -> Option<Vec<GuardDetail>> {
|
||||
Some(vec![GuardDetail::HttpMethods(vec![self.0.to_string()])])
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! method_guard {
|
||||
|
|
@ -382,6 +457,15 @@ impl Guard for HeaderGuard {
|
|||
|
||||
false
|
||||
}
|
||||
fn name(&self) -> String {
|
||||
format!("Header({}, {})", self.0, self.1.to_str().unwrap_or(""))
|
||||
}
|
||||
fn details(&self) -> Option<Vec<GuardDetail>> {
|
||||
Some(vec![GuardDetail::Headers(vec![(
|
||||
self.0.to_string(),
|
||||
self.1.to_str().unwrap_or("").to_string(),
|
||||
)])])
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,209 @@
|
|||
use std::{collections::HashMap, fmt::Write as FmtWrite};
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::http::Method;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RouteDetail {
|
||||
methods: Vec<Method>,
|
||||
guards: Vec<String>,
|
||||
is_resource: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ResourceType {
|
||||
App,
|
||||
Scope,
|
||||
Resource,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct IntrospectionNode {
|
||||
pub kind: ResourceType,
|
||||
pub pattern: String,
|
||||
pub full_path: String,
|
||||
pub methods: Vec<Method>,
|
||||
pub guards: Vec<String>,
|
||||
pub children: Vec<IntrospectionNode>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct IntrospectionReportItem {
|
||||
pub full_path: String,
|
||||
pub methods: Vec<String>,
|
||||
pub guards: Vec<String>,
|
||||
}
|
||||
|
||||
impl IntrospectionNode {
|
||||
pub fn new(kind: ResourceType, pattern: String, full_path: String) -> Self {
|
||||
IntrospectionNode {
|
||||
kind,
|
||||
pattern,
|
||||
full_path,
|
||||
methods: Vec::new(),
|
||||
guards: Vec::new(),
|
||||
children: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&IntrospectionNode> for Vec<IntrospectionReportItem> {
|
||||
fn from(node: &IntrospectionNode) -> Self {
|
||||
fn collect_report_items(
|
||||
node: &IntrospectionNode,
|
||||
parent_path: &str,
|
||||
report_items: &mut Vec<IntrospectionReportItem>,
|
||||
) {
|
||||
let full_path = if parent_path.is_empty() {
|
||||
node.pattern.clone()
|
||||
} else {
|
||||
format!(
|
||||
"{}/{}",
|
||||
parent_path.trim_end_matches('/'),
|
||||
node.pattern.trim_start_matches('/')
|
||||
)
|
||||
};
|
||||
|
||||
if !node.methods.is_empty() || !node.guards.is_empty() {
|
||||
let filtered_guards: Vec<String> = node
|
||||
.guards
|
||||
.iter()
|
||||
.filter(|guard| !node.methods.iter().any(|m| m.to_string() == **guard))
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
report_items.push(IntrospectionReportItem {
|
||||
full_path: full_path.clone(),
|
||||
methods: node.methods.iter().map(|m| m.to_string()).collect(),
|
||||
guards: filtered_guards,
|
||||
});
|
||||
}
|
||||
|
||||
for child in &node.children {
|
||||
collect_report_items(child, &full_path, report_items);
|
||||
}
|
||||
}
|
||||
|
||||
let mut report_items = Vec::new();
|
||||
collect_report_items(node, "/", &mut report_items);
|
||||
report_items
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct IntrospectionCollector {
|
||||
details: HashMap<String, RouteDetail>,
|
||||
}
|
||||
|
||||
impl IntrospectionCollector {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
details: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_pattern_detail(
|
||||
&mut self,
|
||||
full_path: String,
|
||||
methods: Vec<Method>,
|
||||
guards: Vec<String>,
|
||||
is_resource: bool,
|
||||
) {
|
||||
self.details
|
||||
.entry(full_path)
|
||||
.and_modify(|d| {
|
||||
update_unique(&mut d.methods, &methods);
|
||||
update_unique(&mut d.guards, &guards);
|
||||
if !d.is_resource && is_resource {
|
||||
d.is_resource = true;
|
||||
}
|
||||
})
|
||||
.or_insert(RouteDetail {
|
||||
methods,
|
||||
guards,
|
||||
is_resource,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn finalize(&mut self) -> IntrospectionTree {
|
||||
let detail_registry = std::mem::take(&mut self.details);
|
||||
let mut root = IntrospectionNode::new(ResourceType::App, "".into(), "".into());
|
||||
|
||||
for (full_path, _) in detail_registry.iter() {
|
||||
let parts: Vec<&str> = full_path.split('/').collect();
|
||||
let mut current_node = &mut root;
|
||||
|
||||
for (i, part) in parts.iter().enumerate() {
|
||||
let existing_child_index = current_node
|
||||
.children
|
||||
.iter()
|
||||
.position(|n| n.pattern == *part);
|
||||
|
||||
let child_index = if let Some(idx) = existing_child_index {
|
||||
idx
|
||||
} else {
|
||||
let child_full_path = parts[..=i].join("/");
|
||||
let kind = if detail_registry
|
||||
.get(&child_full_path)
|
||||
.is_some_and(|d| d.is_resource)
|
||||
{
|
||||
ResourceType::Resource
|
||||
} else {
|
||||
ResourceType::Scope
|
||||
};
|
||||
let new_node = IntrospectionNode::new(kind, part.to_string(), child_full_path);
|
||||
current_node.children.push(new_node);
|
||||
current_node.children.len() - 1
|
||||
};
|
||||
|
||||
current_node = &mut current_node.children[child_index];
|
||||
|
||||
if let ResourceType::Resource = current_node.kind {
|
||||
if let Some(detail) = detail_registry.get(¤t_node.full_path) {
|
||||
update_unique(&mut current_node.methods, &detail.methods);
|
||||
update_unique(&mut current_node.guards, &detail.guards);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IntrospectionTree { root }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct IntrospectionTree {
|
||||
pub root: IntrospectionNode,
|
||||
}
|
||||
|
||||
impl IntrospectionTree {
|
||||
pub fn report_as_text(&self) -> String {
|
||||
let report_items: Vec<IntrospectionReportItem> = (&self.root).into();
|
||||
|
||||
let mut buf = String::new();
|
||||
for item in report_items {
|
||||
writeln!(
|
||||
buf,
|
||||
"{} => Methods: {:?} | Guards: {:?}",
|
||||
item.full_path, item.methods, item.guards
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
pub fn report_as_json(&self) -> String {
|
||||
let report_items: Vec<IntrospectionReportItem> = (&self.root).into();
|
||||
serde_json::to_string_pretty(&report_items).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
fn update_unique<T: Clone + PartialEq>(existing: &mut Vec<T>, new_items: &[T]) {
|
||||
for item in new_items {
|
||||
if !existing.contains(item) {
|
||||
existing.push(item.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -108,6 +108,9 @@ mod thin_data;
|
|||
pub(crate) mod types;
|
||||
pub mod web;
|
||||
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
pub mod introspection;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use crate::error::Result;
|
||||
pub use crate::{
|
||||
|
|
|
|||
|
|
@ -417,6 +417,8 @@ where
|
|||
B: MessageBody + 'static,
|
||||
{
|
||||
fn register(mut self, config: &mut AppService) {
|
||||
let routes = std::mem::take(&mut self.routes);
|
||||
|
||||
let guards = if self.guards.is_empty() {
|
||||
None
|
||||
} else {
|
||||
|
|
@ -428,13 +430,55 @@ where
|
|||
} else {
|
||||
ResourceDef::new(self.rdef.clone())
|
||||
};
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
{
|
||||
use crate::http::Method;
|
||||
|
||||
let guards_routes = routes.iter().map(|r| r.guards()).collect::<Vec<_>>();
|
||||
|
||||
let pat = rdef.pattern().unwrap_or("").to_string();
|
||||
let full_path = if config.current_prefix.is_empty() {
|
||||
pat.clone()
|
||||
} else {
|
||||
format!(
|
||||
"{}/{}",
|
||||
config.current_prefix.trim_end_matches('/'),
|
||||
pat.trim_start_matches('/')
|
||||
)
|
||||
};
|
||||
|
||||
for route_guards in guards_routes {
|
||||
// Log the guards and methods for introspection
|
||||
let guard_names = route_guards.iter().map(|g| g.name()).collect::<Vec<_>>();
|
||||
let methods = route_guards
|
||||
.iter()
|
||||
.flat_map(|g| g.details().unwrap_or_default())
|
||||
.flat_map(|d| {
|
||||
if let crate::guard::GuardDetail::HttpMethods(v) = d {
|
||||
v.into_iter()
|
||||
.filter_map(|s| s.parse::<Method>().ok())
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
config.introspector.borrow_mut().register_pattern_detail(
|
||||
full_path.clone(),
|
||||
methods,
|
||||
guard_names,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref name) = self.name {
|
||||
rdef.set_name(name);
|
||||
}
|
||||
|
||||
*self.factory_ref.borrow_mut() = Some(ResourceFactory {
|
||||
routes: self.routes,
|
||||
routes,
|
||||
default: self.default,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -159,6 +159,11 @@ impl Route {
|
|||
self
|
||||
}
|
||||
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
pub(crate) fn guards(&self) -> &Vec<Box<dyn Guard>> {
|
||||
&self.guards
|
||||
}
|
||||
|
||||
/// Set handler function, use request extractors for parameters.
|
||||
///
|
||||
/// # Examples
|
||||
|
|
|
|||
|
|
@ -384,6 +384,11 @@ where
|
|||
|
||||
// register nested services
|
||||
let mut cfg = config.clone_config();
|
||||
|
||||
// Update the prefix for the nested scope
|
||||
#[cfg(feature = "experimental-introspection")]
|
||||
cfg.update_prefix(&self.rdef);
|
||||
|
||||
self.services
|
||||
.into_iter()
|
||||
.for_each(|mut srv| srv.register(&mut cfg));
|
||||
|
|
|
|||
|
|
@ -688,30 +688,20 @@ async fn test_brotli_encoding_large_openssl() {
|
|||
|
||||
#[cfg(feature = "rustls-0_23")]
|
||||
mod plus_rustls {
|
||||
use std::io::BufReader;
|
||||
|
||||
use rustls::{pki_types::PrivateKeyDer, ServerConfig as RustlsServerConfig};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
use rustls_pki_types::PrivatePkcs8KeyDer;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn tls_config() -> RustlsServerConfig {
|
||||
let rcgen::CertifiedKey { cert, key_pair } =
|
||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||
let cert_file = cert.pem();
|
||||
let key_file = key_pair.serialize_pem();
|
||||
|
||||
let cert_file = &mut BufReader::new(cert_file.as_bytes());
|
||||
let key_file = &mut BufReader::new(key_file.as_bytes());
|
||||
|
||||
let cert_chain = certs(cert_file).collect::<Result<Vec<_>, _>>().unwrap();
|
||||
let mut keys = pkcs8_private_keys(key_file)
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
let cert_chain = vec![cert.der().clone()];
|
||||
let key_der = PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key_pair.serialize_der()));
|
||||
|
||||
RustlsServerConfig::builder()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(cert_chain, PrivateKeyDer::Pkcs8(keys.remove(0)))
|
||||
.with_single_cert(cert_chain, key_der)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.82.
|
||||
|
||||
## 3.8.1
|
||||
|
||||
- Fix a bug where `GO_AWAY` errors did not stop connections from returning to the pool.
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ flate2 = "1.0.13"
|
|||
futures-util = { version = "0.3.17", default-features = false }
|
||||
static_assertions = "1.1"
|
||||
rcgen = "0.13"
|
||||
rustls-pemfile = "2"
|
||||
rustls-pki-types = "1.13.1"
|
||||
tokio = { version = "1.38.2", features = ["rt-multi-thread", "macros"] }
|
||||
zstd = "0.13"
|
||||
tls-rustls-0_23 = { package = "rustls", version = "0.23" } # add rustls 0.23 with default features to make aws_lc_rs work in tests
|
||||
|
|
|
|||
|
|
@ -309,10 +309,7 @@ impl ClientRequest {
|
|||
/// Freeze request builder and construct `FrozenClientRequest`,
|
||||
/// which could be used for sending same request multiple times.
|
||||
pub fn freeze(self) -> Result<FrozenClientRequest, FreezeRequestError> {
|
||||
let slf = match self.prep_for_sending() {
|
||||
Ok(slf) => slf,
|
||||
Err(err) => return Err(err.into()),
|
||||
};
|
||||
let slf = self.prep_for_sending()?;
|
||||
|
||||
let request = FrozenClientRequest {
|
||||
head: Rc::new(slf.head),
|
||||
|
|
|
|||
|
|
@ -2,12 +2,9 @@
|
|||
|
||||
extern crate tls_rustls_0_23 as rustls;
|
||||
|
||||
use std::{
|
||||
io::BufReader,
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc,
|
||||
},
|
||||
use std::sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc,
|
||||
};
|
||||
|
||||
use actix_http::HttpService;
|
||||
|
|
@ -16,29 +13,18 @@ use actix_service::{fn_service, map_config, ServiceFactoryExt};
|
|||
use actix_tls::connect::rustls_0_23::webpki_roots_cert_store;
|
||||
use actix_utils::future::ok;
|
||||
use actix_web::{dev::AppConfig, http::Version, web, App, HttpResponse};
|
||||
use rustls::{
|
||||
pki_types::{CertificateDer, PrivateKeyDer, ServerName},
|
||||
ClientConfig, ServerConfig,
|
||||
};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
use rustls::{pki_types::ServerName, ClientConfig, ServerConfig};
|
||||
use rustls_pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};
|
||||
|
||||
fn tls_config() -> ServerConfig {
|
||||
let rcgen::CertifiedKey { cert, key_pair } =
|
||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||
let cert_file = cert.pem();
|
||||
let key_file = key_pair.serialize_pem();
|
||||
|
||||
let cert_file = &mut BufReader::new(cert_file.as_bytes());
|
||||
let key_file = &mut BufReader::new(key_file.as_bytes());
|
||||
|
||||
let cert_chain = certs(cert_file).collect::<Result<Vec<_>, _>>().unwrap();
|
||||
let mut keys = pkcs8_private_keys(key_file)
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
let cert_chain = vec![cert.der().clone()];
|
||||
let key_der = PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key_pair.serialize_der()));
|
||||
|
||||
ServerConfig::builder()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(cert_chain, PrivateKeyDer::Pkcs8(keys.remove(0)))
|
||||
.with_single_cert(cert_chain, key_der)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
|
|
|||
9
justfile
9
justfile
|
|
@ -12,14 +12,7 @@ fmt:
|
|||
# Downgrade dependencies necessary to run MSRV checks/tests.
|
||||
[private]
|
||||
downgrade-for-msrv:
|
||||
cargo {{ toolchain }} update -p=divan --precise=0.1.15 # next ver: 1.80.0
|
||||
cargo {{ toolchain }} update -p=rayon --precise=1.10.0 # next ver: 1.80.0
|
||||
cargo {{ toolchain }} update -p=rayon-core --precise=1.12.1 # next ver: 1.80.0
|
||||
cargo {{ toolchain }} update -p=half --precise=2.4.1 # next ver: 1.81.0
|
||||
cargo {{ toolchain }} update -p=idna_adapter --precise=1.2.0 # next ver: 1.82.0
|
||||
cargo {{ toolchain }} update -p=litemap --precise=0.7.4 # next ver: 1.81.0
|
||||
cargo {{ toolchain }} update -p=zerofrom --precise=0.1.5 # next ver: 1.81.0
|
||||
cargo {{ toolchain }} update -p=time --precise=0.3.41 # next ver: 1.81.0
|
||||
# no downgrades currently needed
|
||||
|
||||
msrv := ```
|
||||
cargo metadata --format-version=1 \
|
||||
|
|
|
|||
Loading…
Reference in New Issue