mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-17 03:19:01 +02:00
Compare commits
63 Commits
infallible
...
web-v4.10.
Author | SHA1 | Date | |
---|---|---|---|
|
e8351cc3aa | ||
|
f63cf69e6a | ||
|
92c1e2230d | ||
|
4bb495aba0 | ||
|
aa000b429d | ||
|
df0885cf21 | ||
|
0796f8e796 | ||
|
a2307fbb86 | ||
|
98ced477f7 | ||
|
98c263b3ee | ||
|
b8bdee0606 | ||
|
85843b9b0f | ||
|
9656383646 | ||
|
cee7451915 | ||
|
eb6f6a1976 | ||
|
04533a15fa | ||
|
a4eaa7f0bb | ||
|
66e2afe306 | ||
|
59961a58a8 | ||
|
33b487e854 | ||
|
182055bcb5 | ||
|
a36280466c | ||
|
8690f80a08 | ||
|
91e29c0ce4 | ||
|
b0fe679784 | ||
|
0fafb486d4 | ||
|
5aeb0dd950 | ||
|
856480cd90 | ||
|
bb1442e20b | ||
|
ac2a3bb124 | ||
|
8200e4ee82 | ||
|
5b60d81f57 | ||
|
ee6a6ec03e | ||
|
34327bd221 | ||
|
472dbca64e | ||
|
d8566da66f | ||
|
a908afa56b | ||
|
8115c818c1 | ||
|
002c1b5a19 | ||
|
836c75064b | ||
|
2132c95b01 | ||
|
eff2a20c90 | ||
|
9d849c19a5 | ||
|
6771be20b3 | ||
|
ef977055fc | ||
|
568bffeb58 | ||
|
03c65d93e5 | ||
|
ec05381f6f | ||
|
4c05c87b11 | ||
|
27c07f122b | ||
|
3849cdaa6c | ||
|
a5c2d0531b | ||
|
049b49290d | ||
|
b7a0ff0a3a | ||
|
a0a6761bfe | ||
|
ff9c0f7157 | ||
|
1c4e265a70 | ||
|
d9d22825d4 | ||
|
9a685cabad | ||
|
93edef8fee | ||
|
d148e84aba | ||
|
7360c732b3 | ||
|
48aaf41638 |
10
.github/workflows/ci-post-merge.yml
vendored
10
.github/workflows/ci-post-merge.yml
vendored
@@ -32,7 +32,7 @@ jobs:
|
||||
|
||||
- name: Install nasm
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
uses: ilammy/setup-nasm@v1.5.1
|
||||
uses: ilammy/setup-nasm@v1.5.2
|
||||
|
||||
- name: Install OpenSSL
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
@@ -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.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||
with:
|
||||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
||||
uses: taiki-e/install-action@v2.42.37
|
||||
uses: taiki-e/install-action@v2.49.17
|
||||
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.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||
|
||||
- name: Install just, cargo-hack
|
||||
uses: taiki-e/install-action@v2.42.37
|
||||
uses: taiki-e/install-action@v2.49.17
|
||||
with:
|
||||
tool: just,cargo-hack
|
||||
|
||||
|
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
@@ -43,7 +43,7 @@ jobs:
|
||||
|
||||
- name: Install nasm
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
uses: ilammy/setup-nasm@v1.5.1
|
||||
uses: ilammy/setup-nasm@v1.5.2
|
||||
|
||||
- name: Install OpenSSL
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
@@ -59,12 +59,12 @@ jobs:
|
||||
uses: rui314/setup-mold@v1
|
||||
|
||||
- name: Install Rust (${{ matrix.version.name }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||
with:
|
||||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
||||
uses: taiki-e/install-action@v2.42.37
|
||||
uses: taiki-e/install-action@v2.49.17
|
||||
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.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.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.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||
with:
|
||||
toolchain: nightly
|
||||
|
||||
- name: Install just
|
||||
uses: taiki-e/install-action@v2.42.37
|
||||
uses: taiki-e/install-action@v2.49.17
|
||||
with:
|
||||
tool: just
|
||||
|
||||
|
6
.github/workflows/coverage.yml
vendored
6
.github/workflows/coverage.yml
vendored
@@ -18,13 +18,13 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: llvm-tools
|
||||
|
||||
- name: Install just, cargo-llvm-cov, cargo-nextest
|
||||
uses: taiki-e/install-action@v2.42.37
|
||||
uses: taiki-e/install-action@v2.49.17
|
||||
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@v4.5.0
|
||||
uses: codecov/codecov-action@v5.4.0
|
||||
with:
|
||||
files: codecov.json
|
||||
fail_ci_if_error: true
|
||||
|
46
.github/workflows/lint.yml
vendored
46
.github/workflows/lint.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.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.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.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.9.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: rust-docs
|
||||
@@ -66,51 +66,25 @@ jobs:
|
||||
run: cargo +nightly doc --no-deps --workspace --all-features
|
||||
|
||||
check-external-types:
|
||||
if: false # rustdoc mismatch currently
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust (nightly-2024-05-01)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
|
||||
- name: Install Rust (${{ vars.RUST_VERSION_EXTERNAL_TYPES }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.11.0
|
||||
with:
|
||||
toolchain: nightly-2024-05-01
|
||||
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
||||
|
||||
- name: Install just
|
||||
uses: taiki-e/install-action@v2.42.37
|
||||
uses: taiki-e/install-action@v2.49.17
|
||||
with:
|
||||
tool: just
|
||||
|
||||
- name: Install cargo-check-external-types
|
||||
uses: taiki-e/cache-cargo-install-action@v2.0.1
|
||||
uses: taiki-e/cache-cargo-install-action@v2.1.1
|
||||
with:
|
||||
tool: cargo-check-external-types
|
||||
|
||||
- name: check external types
|
||||
run: just check-external-types-all +nightly-2024-05-01
|
||||
|
||||
public-api-diff:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout main branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.base_ref }}
|
||||
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust (nightly-2024-06-07)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.9.0
|
||||
with:
|
||||
toolchain: nightly-2024-06-07
|
||||
|
||||
- name: Install cargo-public-api
|
||||
uses: taiki-e/install-action@v2.42.37
|
||||
with:
|
||||
tool: cargo-public-api
|
||||
|
||||
- name: Generate API diff
|
||||
run: |
|
||||
for f in $(find -mindepth 2 -maxdepth 2 -name Cargo.toml); do
|
||||
cargo public-api --manifest-path "$f" --simplified diff ${{ github.event.pull_request.base.sha }}..${{ github.sha }}
|
||||
done
|
||||
run: just check-external-types-all +${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
||||
|
@@ -33,7 +33,7 @@ actix-web = { version = "4", default-features = false }
|
||||
|
||||
bitflags = "2"
|
||||
bytes = "1"
|
||||
derive_more = { version = "1", features = ["display", "error", "from"] }
|
||||
derive_more = { version = "2", features = ["display", "error", "from"] }
|
||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
http-range = "0.1.4"
|
||||
log = "0.4"
|
||||
|
@@ -1,5 +1,5 @@
|
||||
use actix_web::{http::StatusCode, ResponseError};
|
||||
use derive_more::derive::Display;
|
||||
use derive_more::Display;
|
||||
|
||||
/// Errors which can occur when serving static files.
|
||||
#[derive(Debug, PartialEq, Eq, Display)]
|
||||
|
@@ -21,7 +21,7 @@ use actix_web::{
|
||||
Error, HttpMessage, HttpRequest, HttpResponse, Responder,
|
||||
};
|
||||
use bitflags::bitflags;
|
||||
use derive_more::derive::{Deref, DerefMut};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use mime::Mime;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use std::fmt;
|
||||
|
||||
use derive_more::derive::Error;
|
||||
use derive_more::Error;
|
||||
|
||||
/// Copy of `http_range::HttpRangeParseError`.
|
||||
#[derive(Debug, Clone)]
|
||||
|
@@ -2,6 +2,18 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 3.10.0
|
||||
|
||||
### Added
|
||||
|
||||
- Add `header::CLEAR_SITE_DATA` constant.
|
||||
- Add `Extensions::get_or_insert[_with]()` methods.
|
||||
- Implement `From<Bytes>` for `Payload`.
|
||||
- Implement `From<Vec<u8>>` for `Payload`.
|
||||
|
||||
### Changed
|
||||
|
||||
- Update `brotli` dependency to `7`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
||||
|
||||
## 3.9.0
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-http"
|
||||
version = "3.9.0"
|
||||
version = "3.10.0"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
@@ -106,12 +106,12 @@ actix-codec = "0.5"
|
||||
actix-utils = "3"
|
||||
actix-rt = { version = "2.2", default-features = false }
|
||||
|
||||
ahash = "0.8"
|
||||
bitflags = "2"
|
||||
bytes = "1"
|
||||
bytestring = "1"
|
||||
derive_more = { version = "1", features = ["as_ref", "deref", "deref_mut", "display", "error", "from"] }
|
||||
derive_more = { version = "2", features = ["as_ref", "deref", "deref_mut", "display", "error", "from"] }
|
||||
encoding_rs = "0.8"
|
||||
foldhash = "0.1"
|
||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
http = "0.2.7"
|
||||
httparse = "1.5.1"
|
||||
@@ -132,14 +132,14 @@ h2 = { version = "0.3.26", optional = true }
|
||||
# websockets
|
||||
local-channel = { version = "0.1", optional = true }
|
||||
base64 = { version = "0.22", optional = true }
|
||||
rand = { version = "0.8", optional = true }
|
||||
rand = { version = "0.9", optional = true }
|
||||
sha1 = { version = "0.10", optional = true }
|
||||
|
||||
# openssl/rustls
|
||||
actix-tls = { version = "3.4", default-features = false, optional = true }
|
||||
|
||||
# compress-*
|
||||
brotli = { version = "6", optional = true }
|
||||
brotli = { version = "7", optional = true }
|
||||
flate2 = { version = "1.0.13", optional = true }
|
||||
zstd = { version = "0.13", optional = true }
|
||||
|
||||
|
@@ -5,11 +5,11 @@
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-http)
|
||||
[](https://docs.rs/actix-http/3.9.0)
|
||||
[](https://docs.rs/actix-http/3.10.0)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-http/3.9.0)
|
||||
[](https://deps.rs/crate/actix-http/3.10.0)
|
||||
[](https://crates.io/crates/actix-http)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
|
@@ -75,7 +75,7 @@ mod tests {
|
||||
time::{sleep, Sleep},
|
||||
};
|
||||
use actix_utils::future::poll_fn;
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use futures_core::ready;
|
||||
use futures_util::{stream, FutureExt as _};
|
||||
use pin_project_lite::pin_project;
|
||||
|
@@ -3,7 +3,7 @@ use std::task::Poll;
|
||||
use actix_rt::pin;
|
||||
use actix_utils::future::poll_fn;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use futures_core::ready;
|
||||
|
||||
use super::{BodySize, MessageBody};
|
||||
|
@@ -10,7 +10,7 @@ use std::{
|
||||
|
||||
use actix_rt::task::{spawn_blocking, JoinHandle};
|
||||
use bytes::Bytes;
|
||||
use derive_more::derive::Display;
|
||||
use derive_more::Display;
|
||||
#[cfg(feature = "compress-gzip")]
|
||||
use flate2::write::{GzEncoder, ZlibEncoder};
|
||||
use futures_core::ready;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::{error::Error as StdError, fmt, io, str::Utf8Error, string::FromUtf8Error};
|
||||
|
||||
use derive_more::derive::{Display, Error, From};
|
||||
use derive_more::{Display, Error, From};
|
||||
pub use http::{status::InvalidStatusCode, Error as HttpError};
|
||||
use http::{uri::InvalidUri, StatusCode};
|
||||
|
||||
|
@@ -31,7 +31,7 @@ impl Hasher for NoOpHasher {
|
||||
/// All entries into this map must be owned types (or static references).
|
||||
#[derive(Default)]
|
||||
pub struct Extensions {
|
||||
/// Use AHasher with a std HashMap with for faster lookups on the small `TypeId` keys.
|
||||
// use no-op hasher with a std HashMap with for faster lookups on the small `TypeId` keys
|
||||
map: HashMap<TypeId, Box<dyn Any>, BuildHasherDefault<NoOpHasher>>,
|
||||
}
|
||||
|
||||
@@ -104,6 +104,46 @@ impl Extensions {
|
||||
.and_then(|boxed| boxed.downcast_mut())
|
||||
}
|
||||
|
||||
/// Inserts the given `value` into the extensions if it is not present, then returns a reference
|
||||
/// to the value in the extensions.
|
||||
///
|
||||
/// ```
|
||||
/// # use actix_http::Extensions;
|
||||
/// let mut map = Extensions::new();
|
||||
/// assert_eq!(map.get::<Vec<u32>>(), None);
|
||||
///
|
||||
/// map.get_or_insert(Vec::<u32>::new()).push(1);
|
||||
/// assert_eq!(map.get::<Vec<u32>>(), Some(&vec![1]));
|
||||
///
|
||||
/// map.get_or_insert(Vec::<u32>::new()).push(2);
|
||||
/// assert_eq!(map.get::<Vec<u32>>(), Some(&vec![1,2]));
|
||||
/// ```
|
||||
pub fn get_or_insert<T: 'static>(&mut self, value: T) -> &mut T {
|
||||
self.get_or_insert_with(|| value)
|
||||
}
|
||||
|
||||
/// Inserts a value computed from `f` into the extensions if the given `value` is not present,
|
||||
/// then returns a reference to the value in the extensions.
|
||||
///
|
||||
/// ```
|
||||
/// # use actix_http::Extensions;
|
||||
/// let mut map = Extensions::new();
|
||||
/// assert_eq!(map.get::<Vec<u32>>(), None);
|
||||
///
|
||||
/// map.get_or_insert_with(Vec::<u32>::new).push(1);
|
||||
/// assert_eq!(map.get::<Vec<u32>>(), Some(&vec![1]));
|
||||
///
|
||||
/// map.get_or_insert_with(Vec::<u32>::new).push(2);
|
||||
/// assert_eq!(map.get::<Vec<u32>>(), Some(&vec![1,2]));
|
||||
/// ```
|
||||
pub fn get_or_insert_with<T: 'static, F: FnOnce() -> T>(&mut self, default: F) -> &mut T {
|
||||
self.map
|
||||
.entry(TypeId::of::<T>())
|
||||
.or_insert_with(|| Box::new(default()))
|
||||
.downcast_mut()
|
||||
.expect("extensions map should now contain a T value")
|
||||
}
|
||||
|
||||
/// Remove an item from the map of a given type.
|
||||
///
|
||||
/// If an item of this type was already stored, it will be returned.
|
||||
|
@@ -18,6 +18,14 @@ pub const CACHE_STATUS: HeaderName = HeaderName::from_static("cache-status");
|
||||
// TODO(breaking): replace with http's version
|
||||
pub const CDN_CACHE_CONTROL: HeaderName = HeaderName::from_static("cdn-cache-control");
|
||||
|
||||
/// Response header field that sends a signal to the user agent that it ought to remove all data of
|
||||
/// a certain set of types.
|
||||
///
|
||||
/// See the [W3C Clear-Site-Data spec] for full semantics.
|
||||
///
|
||||
/// [W3C Clear-Site-Data spec]: https://www.w3.org/TR/clear-site-data/#header
|
||||
pub const CLEAR_SITE_DATA: HeaderName = HeaderName::from_static("clear-site-data");
|
||||
|
||||
/// Response header that prevents a document from loading any cross-origin resources that don't
|
||||
/// explicitly grant the document permission (using [CORP] or [CORS]).
|
||||
///
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::{borrow::Cow, collections::hash_map, iter, ops};
|
||||
|
||||
use ahash::AHashMap;
|
||||
use foldhash::{HashMap as FoldHashMap, HashMapExt as _};
|
||||
use http::header::{HeaderName, HeaderValue};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
@@ -47,7 +47,7 @@ use super::AsHeaderName;
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct HeaderMap {
|
||||
pub(crate) inner: AHashMap<HeaderName, Value>,
|
||||
pub(crate) inner: FoldHashMap<HeaderName, Value>,
|
||||
}
|
||||
|
||||
/// A bespoke non-empty list for HeaderMap values.
|
||||
@@ -116,7 +116,7 @@ impl HeaderMap {
|
||||
/// ```
|
||||
pub fn with_capacity(capacity: usize) -> Self {
|
||||
HeaderMap {
|
||||
inner: AHashMap::with_capacity(capacity),
|
||||
inner: FoldHashMap::with_capacity(capacity),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -830,7 +830,7 @@ impl<'a> Drain<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for Drain<'a> {
|
||||
impl Iterator for Drain<'_> {
|
||||
type Item = (Option<HeaderName>, HeaderValue);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@@ -42,9 +42,9 @@ pub use self::{
|
||||
as_name::AsHeaderName,
|
||||
// re-export list is explicit so that any updates to `http` do not conflict with this set
|
||||
common::{
|
||||
CACHE_STATUS, CDN_CACHE_CONTROL, CROSS_ORIGIN_EMBEDDER_POLICY, CROSS_ORIGIN_OPENER_POLICY,
|
||||
CROSS_ORIGIN_RESOURCE_POLICY, PERMISSIONS_POLICY, X_FORWARDED_FOR, X_FORWARDED_HOST,
|
||||
X_FORWARDED_PROTO,
|
||||
CACHE_STATUS, CDN_CACHE_CONTROL, CLEAR_SITE_DATA, CROSS_ORIGIN_EMBEDDER_POLICY,
|
||||
CROSS_ORIGIN_OPENER_POLICY, CROSS_ORIGIN_RESOURCE_POLICY, PERMISSIONS_POLICY,
|
||||
X_FORWARDED_FOR, X_FORWARDED_HOST, X_FORWARDED_PROTO,
|
||||
},
|
||||
into_pair::TryIntoHeaderPair,
|
||||
into_value::TryIntoHeaderValue,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use http::header::InvalidHeaderValue;
|
||||
|
||||
use crate::{
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use std::fmt;
|
||||
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
|
||||
const MAX_QUALITY_INT: u16 = 1000;
|
||||
const MAX_QUALITY_FLOAT: f32 = 1.0;
|
||||
|
@@ -61,7 +61,7 @@ pub fn write_content_length<B: BufMut>(n: u64, buf: &mut B, camel_case: bool) {
|
||||
/// perform a remaining length check before writing.
|
||||
pub(crate) struct MutWriter<'a, B>(pub(crate) &'a mut B);
|
||||
|
||||
impl<'a, B> io::Write for MutWriter<'a, B>
|
||||
impl<B> io::Write for MutWriter<'_, B>
|
||||
where
|
||||
B: BufMut,
|
||||
{
|
||||
|
@@ -103,7 +103,7 @@ pub trait HttpMessage: Sized {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> HttpMessage for &'a mut T
|
||||
impl<T> HttpMessage for &mut T
|
||||
where
|
||||
T: HttpMessage,
|
||||
{
|
||||
|
@@ -41,13 +41,31 @@ pin_project! {
|
||||
}
|
||||
|
||||
impl<S> From<crate::h1::Payload> for Payload<S> {
|
||||
#[inline]
|
||||
fn from(payload: crate::h1::Payload) -> Self {
|
||||
Payload::H1 { payload }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> From<Bytes> for Payload<S> {
|
||||
#[inline]
|
||||
fn from(bytes: Bytes) -> Self {
|
||||
let (_, mut pl) = crate::h1::Payload::create(true);
|
||||
pl.unread_data(bytes);
|
||||
self::Payload::from(pl)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> From<Vec<u8>> for Payload<S> {
|
||||
#[inline]
|
||||
fn from(vec: Vec<u8>) -> Self {
|
||||
Payload::from(Bytes::from(vec))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "http2")]
|
||||
impl<S> From<crate::h2::Payload> for Payload<S> {
|
||||
#[inline]
|
||||
fn from(payload: crate::h2::Payload) -> Self {
|
||||
Payload::H2 { payload }
|
||||
}
|
||||
@@ -55,6 +73,7 @@ impl<S> From<crate::h2::Payload> for Payload<S> {
|
||||
|
||||
#[cfg(feature = "http2")]
|
||||
impl<S> From<::h2::RecvStream> for Payload<S> {
|
||||
#[inline]
|
||||
fn from(stream: ::h2::RecvStream) -> Self {
|
||||
Payload::H2 {
|
||||
payload: crate::h2::Payload::new(stream),
|
||||
@@ -63,13 +82,15 @@ impl<S> From<::h2::RecvStream> for Payload<S> {
|
||||
}
|
||||
|
||||
impl From<BoxedPayloadStream> for Payload {
|
||||
#[inline]
|
||||
fn from(payload: BoxedPayloadStream) -> Self {
|
||||
Payload::Stream { payload }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Payload<S> {
|
||||
/// Takes current payload and replaces it with `None` value
|
||||
/// Takes current payload and replaces it with `None` value.
|
||||
#[must_use]
|
||||
pub fn take(&mut self) -> Payload<S> {
|
||||
mem::replace(self, Payload::None)
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
use std::io;
|
||||
|
||||
use derive_more::derive::{Display, Error, From};
|
||||
use derive_more::{Display, Error, From};
|
||||
use http::{header, Method, StatusCode};
|
||||
|
||||
use crate::{body::BoxBody, header::HeaderValue, RequestHead, Response, ResponseBuilder};
|
||||
|
@@ -5,7 +5,7 @@ use actix_http_test::test_server;
|
||||
use actix_service::ServiceFactoryExt;
|
||||
use actix_utils::future;
|
||||
use bytes::Bytes;
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use futures_util::StreamExt as _;
|
||||
|
||||
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
||||
|
@@ -14,7 +14,7 @@ use actix_http_test::test_server;
|
||||
use actix_service::{fn_service, ServiceFactoryExt};
|
||||
use actix_utils::future::{err, ok, ready};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use futures_core::Stream;
|
||||
use futures_util::{stream::once, StreamExt as _};
|
||||
use openssl::{
|
||||
|
@@ -23,7 +23,7 @@ use actix_service::{fn_factory_with_config, fn_service};
|
||||
use actix_tls::connect::rustls_0_23::webpki_roots_cert_store;
|
||||
use actix_utils::future::{err, ok, poll_fn};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use futures_core::{ready, Stream};
|
||||
use futures_util::stream::once;
|
||||
use rustls::{pki_types::ServerName, ServerConfig as RustlsServerConfig};
|
||||
|
@@ -14,8 +14,9 @@ use actix_rt::{net::TcpStream, time::sleep};
|
||||
use actix_service::fn_service;
|
||||
use actix_utils::future::{err, ok, ready};
|
||||
use bytes::Bytes;
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use futures_util::{stream::once, FutureExt as _, StreamExt as _};
|
||||
use rand::Rng as _;
|
||||
use regex::Regex;
|
||||
|
||||
#[actix_rt::test]
|
||||
@@ -164,7 +165,10 @@ async fn chunked_payload() {
|
||||
|
||||
for chunk_size in chunk_sizes.iter() {
|
||||
let mut bytes = Vec::new();
|
||||
let random_bytes: Vec<u8> = (0..*chunk_size).map(|_| rand::random::<u8>()).collect();
|
||||
let random_bytes = rand::rng()
|
||||
.sample_iter(rand::distr::StandardUniform)
|
||||
.take(*chunk_size)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
bytes.extend(format!("{:X}\r\n", chunk_size).as_bytes());
|
||||
bytes.extend(&random_bytes[..]);
|
||||
|
@@ -14,7 +14,7 @@ use actix_http::{
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{fn_factory, Service};
|
||||
use bytes::Bytes;
|
||||
use derive_more::derive::{Display, Error, From};
|
||||
use derive_more::{Display, Error, From};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use futures_util::{SinkExt as _, StreamExt as _};
|
||||
|
||||
|
@@ -42,7 +42,7 @@ actix-multipart-derive = { version = "=0.7.0", optional = true }
|
||||
actix-utils = "3"
|
||||
actix-web = { version = "4", default-features = false }
|
||||
|
||||
derive_more = { version = "1", features = ["display", "error", "from"] }
|
||||
derive_more = { version = "2", features = ["display", "error", "from"] }
|
||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
futures-util = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
httparse = "1.3"
|
||||
@@ -50,7 +50,7 @@ local-waker = "0.1"
|
||||
log = "0.4"
|
||||
memchr = "2.5"
|
||||
mime = "0.3"
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
serde_plain = "1"
|
||||
@@ -59,7 +59,7 @@ tokio = { version = "1.24.2", features = ["sync", "io-util"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-http = "3"
|
||||
actix-multipart-rfc7578 = "0.10"
|
||||
actix-multipart-rfc7578 = "0.11"
|
||||
actix-rt = "2.2"
|
||||
actix-test = "0.1"
|
||||
actix-web = "4"
|
||||
|
@@ -5,7 +5,7 @@ use actix_web::{
|
||||
http::StatusCode,
|
||||
ResponseError,
|
||||
};
|
||||
use derive_more::derive::{Display, Error, From};
|
||||
use derive_more::{Display, Error, From};
|
||||
|
||||
/// A set of errors that can occur during parsing multipart streams.
|
||||
#[derive(Debug, Display, From, Error)]
|
||||
|
@@ -13,7 +13,7 @@ use actix_web::{
|
||||
http::header::{self, ContentDisposition, HeaderMap},
|
||||
web::{Bytes, BytesMut},
|
||||
};
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use futures_core::Stream;
|
||||
use mime::Mime;
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::{http::StatusCode, web, Error, HttpRequest, ResponseError};
|
||||
use derive_more::derive::{Deref, DerefMut, Display, Error};
|
||||
use derive_more::{Deref, DerefMut, Display, Error};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
|
@@ -8,7 +8,7 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_web::{dev, error::PayloadError, web, Error, FromRequest, HttpRequest};
|
||||
use derive_more::derive::{Deref, DerefMut};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use futures_util::{TryFutureExt as _, TryStreamExt as _};
|
||||
|
||||
|
@@ -7,7 +7,7 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_web::{http::StatusCode, web, Error, HttpRequest, ResponseError};
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use futures_util::TryStreamExt as _;
|
||||
use mime::Mime;
|
||||
|
@@ -3,7 +3,7 @@
|
||||
use std::{str, sync::Arc};
|
||||
|
||||
use actix_web::{http::StatusCode, web, Error, HttpRequest, ResponseError};
|
||||
use derive_more::derive::{Deref, DerefMut, Display, Error};
|
||||
use derive_more::{Deref, DerefMut, Display, Error};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
|
@@ -5,10 +5,7 @@ use actix_web::{
|
||||
web::{BufMut as _, Bytes, BytesMut},
|
||||
};
|
||||
use mime::Mime;
|
||||
use rand::{
|
||||
distributions::{Alphanumeric, DistString as _},
|
||||
thread_rng,
|
||||
};
|
||||
use rand::distr::{Alphanumeric, SampleString as _};
|
||||
|
||||
const CRLF: &[u8] = b"\r\n";
|
||||
const CRLF_CRLF: &[u8] = b"\r\n\r\n";
|
||||
@@ -64,7 +61,7 @@ pub fn create_form_data_payload_and_headers(
|
||||
content_type: Option<Mime>,
|
||||
file: Bytes,
|
||||
) -> (Bytes, HeaderMap) {
|
||||
let boundary = Alphanumeric.sample_string(&mut thread_rng(), 32);
|
||||
let boundary = Alphanumeric.sample_string(&mut rand::rng(), 32);
|
||||
|
||||
create_form_data_payload_and_headers_with_boundary(
|
||||
&boundary,
|
||||
|
@@ -105,7 +105,7 @@ fn hex_pair_to_char(d1: u8, d2: u8) -> Option<u8> {
|
||||
let d_low = char::from(d2).to_digit(16)?;
|
||||
|
||||
// left shift high nibble by 4 bits
|
||||
Some((d_high as u8) << 4 | (d_low as u8))
|
||||
Some(((d_high as u8) << 4) | (d_low as u8))
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
|
@@ -1021,6 +1021,7 @@ impl ResourceDef {
|
||||
panic!("prefix resource definitions should not have tail segments");
|
||||
}
|
||||
|
||||
#[allow(clippy::literal_string_with_formatting_args)]
|
||||
if unprocessed.ends_with('*') {
|
||||
// unnamed tail segment
|
||||
|
||||
@@ -1369,6 +1370,7 @@ mod tests {
|
||||
assert_eq!(path.unprocessed(), "");
|
||||
}
|
||||
|
||||
#[allow(clippy::literal_string_with_formatting_args)]
|
||||
#[test]
|
||||
fn newline_patterns_and_paths() {
|
||||
let re = ResourceDef::new("/user/a\nb");
|
||||
|
@@ -19,7 +19,7 @@ impl ResourcePath for String {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ResourcePath for &'a str {
|
||||
impl ResourcePath for &str {
|
||||
fn path(&self) -> &str {
|
||||
self
|
||||
}
|
||||
|
@@ -145,6 +145,7 @@ mod tests {
|
||||
};
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
#[allow(clippy::literal_string_with_formatting_args)]
|
||||
#[test]
|
||||
fn test_recognizer_1() {
|
||||
let mut router = Router::<usize>::build();
|
||||
|
@@ -136,7 +136,7 @@ async fn routes_overlapping_inaccessible_test(req: HttpRequest) -> impl Responde
|
||||
}
|
||||
|
||||
#[get("/custom_resource_name", name = "custom")]
|
||||
async fn custom_resource_name_test<'a>(req: HttpRequest) -> impl Responder {
|
||||
async fn custom_resource_name_test(req: HttpRequest) -> impl Responder {
|
||||
assert!(req.url_for_static("custom").is_ok());
|
||||
assert!(req.url_for_static("custom_resource_name_test").is_err());
|
||||
HttpResponse::Ok()
|
||||
|
@@ -2,6 +2,16 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 4.10.0
|
||||
|
||||
### Added
|
||||
|
||||
- Implement `Responder` for `Result<(), E: Into<Error>>`. Returning `Ok(())` responds with HTTP 204 No Content.
|
||||
|
||||
### Changed
|
||||
|
||||
- On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use.
|
||||
- Update `brotli` dependency to `7`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
||||
|
||||
## 4.9.0
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-web"
|
||||
version = "4.9.0"
|
||||
version = "4.10.0"
|
||||
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
@@ -141,13 +141,13 @@ actix-http = { version = "3.7", features = ["ws"] }
|
||||
actix-router = { version = "0.5.3", default-features = false, features = ["http"] }
|
||||
actix-web-codegen = { version = "4.3", optional = true, default-features = false }
|
||||
|
||||
ahash = "0.8"
|
||||
bytes = "1"
|
||||
bytestring = "1"
|
||||
cfg-if = "1"
|
||||
cookie = { version = "0.16", features = ["percent-encode"], optional = true }
|
||||
derive_more = { version = "1", features = ["display", "error", "from"] }
|
||||
derive_more = { version = "2", features = ["display", "error", "from"] }
|
||||
encoding_rs = "0.8"
|
||||
foldhash = "0.1"
|
||||
futures-core = { version = "0.3.17", default-features = false }
|
||||
futures-util = { version = "0.3.17", default-features = false }
|
||||
itoa = "1"
|
||||
@@ -163,6 +163,7 @@ serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_urlencoded = "0.7"
|
||||
smallvec = "1.6.1"
|
||||
tracing = "0.1.30"
|
||||
socket2 = "0.5"
|
||||
time = { version = "0.3", default-features = false, features = ["formatting"] }
|
||||
url = "2.1"
|
||||
@@ -172,14 +173,14 @@ actix-files = "0.6"
|
||||
actix-test = { version = "0.1", features = ["openssl", "rustls-0_23"] }
|
||||
awc = { version = "3", features = ["openssl"] }
|
||||
|
||||
brotli = "6"
|
||||
brotli = "7"
|
||||
const-str = "0.5"
|
||||
core_affinity = "0.8"
|
||||
criterion = { version = "0.5", features = ["html_reports"] }
|
||||
env_logger = "0.11"
|
||||
flate2 = "1.0.13"
|
||||
futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
rcgen = "0.13"
|
||||
rustls-pemfile = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
|
@@ -8,13 +8,13 @@
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web)
|
||||
[](https://docs.rs/actix-web/4.9.0)
|
||||
[](https://docs.rs/actix-web/4.10.0)
|
||||

|
||||

|
||||
[](https://deps.rs/crate/actix-web/4.9.0)
|
||||
[](https://deps.rs/crate/actix-web/4.10.0)
|
||||
<br />
|
||||
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
||||
[](https://codecov.io/gh/actix/actix-web)
|
||||
[](https://codecov.io/gh/actix/actix-web)
|
||||

|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
|
128
actix-web/examples/from_fn.rs
Normal file
128
actix-web/examples/from_fn.rs
Normal file
@@ -0,0 +1,128 @@
|
||||
//! Shows a few of ways to use the `from_fn` middleware.
|
||||
|
||||
use std::{collections::HashMap, io, rc::Rc, time::Duration};
|
||||
|
||||
use actix_web::{
|
||||
body::MessageBody,
|
||||
dev::{Service, ServiceRequest, ServiceResponse, Transform},
|
||||
http::header::{self, HeaderValue, Range},
|
||||
middleware::{from_fn, Logger, Next},
|
||||
web::{self, Header, Query},
|
||||
App, Error, HttpResponse, HttpServer,
|
||||
};
|
||||
use tracing::info;
|
||||
|
||||
async fn noop<B>(req: ServiceRequest, next: Next<B>) -> Result<ServiceResponse<B>, Error> {
|
||||
next.call(req).await
|
||||
}
|
||||
|
||||
async fn print_range_header<B>(
|
||||
range_header: Option<Header<Range>>,
|
||||
req: ServiceRequest,
|
||||
next: Next<B>,
|
||||
) -> Result<ServiceResponse<B>, Error> {
|
||||
if let Some(Header(range)) = range_header {
|
||||
println!("Range: {range}");
|
||||
} else {
|
||||
println!("No Range header");
|
||||
}
|
||||
|
||||
next.call(req).await
|
||||
}
|
||||
|
||||
async fn mutate_body_type(
|
||||
req: ServiceRequest,
|
||||
next: Next<impl MessageBody + 'static>,
|
||||
) -> Result<ServiceResponse<impl MessageBody>, Error> {
|
||||
let res = next.call(req).await?;
|
||||
Ok(res.map_into_left_body::<()>())
|
||||
}
|
||||
|
||||
async fn mutate_body_type_with_extractors(
|
||||
string_body: String,
|
||||
query: Query<HashMap<String, String>>,
|
||||
req: ServiceRequest,
|
||||
next: Next<impl MessageBody + 'static>,
|
||||
) -> Result<ServiceResponse<impl MessageBody>, Error> {
|
||||
println!("body is: {string_body}");
|
||||
println!("query string: {query:?}");
|
||||
|
||||
let res = next.call(req).await?;
|
||||
|
||||
Ok(res.map_body(move |_, _| string_body))
|
||||
}
|
||||
|
||||
async fn timeout_10secs(
|
||||
req: ServiceRequest,
|
||||
next: Next<impl MessageBody + 'static>,
|
||||
) -> Result<ServiceResponse<impl MessageBody>, Error> {
|
||||
match tokio::time::timeout(Duration::from_secs(10), next.call(req)).await {
|
||||
Ok(res) => res,
|
||||
Err(_err) => Err(actix_web::error::ErrorRequestTimeout("")),
|
||||
}
|
||||
}
|
||||
|
||||
struct MyMw(bool);
|
||||
|
||||
impl MyMw {
|
||||
async fn mw_cb(
|
||||
&self,
|
||||
req: ServiceRequest,
|
||||
next: Next<impl MessageBody + 'static>,
|
||||
) -> Result<ServiceResponse<impl MessageBody>, Error> {
|
||||
let mut res = match self.0 {
|
||||
true => req.into_response("short-circuited").map_into_right_body(),
|
||||
false => next.call(req).await?.map_into_left_body(),
|
||||
};
|
||||
|
||||
res.headers_mut()
|
||||
.insert(header::WARNING, HeaderValue::from_static("42"));
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn into_middleware<S, B>(
|
||||
self,
|
||||
) -> impl Transform<
|
||||
S,
|
||||
ServiceRequest,
|
||||
Response = ServiceResponse<impl MessageBody>,
|
||||
Error = Error,
|
||||
InitError = (),
|
||||
>
|
||||
where
|
||||
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
let this = Rc::new(self);
|
||||
from_fn(move |req, next| {
|
||||
let this = Rc::clone(&this);
|
||||
async move { Self::mw_cb(&this, req, next).await }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
let bind = ("127.0.0.1", 8080);
|
||||
info!("staring server at http://{}:{}", &bind.0, &bind.1);
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(from_fn(noop))
|
||||
.wrap(from_fn(print_range_header))
|
||||
.wrap(from_fn(mutate_body_type))
|
||||
.wrap(from_fn(mutate_body_type_with_extractors))
|
||||
.wrap(from_fn(timeout_10secs))
|
||||
// switch bool to true to observe early response
|
||||
.wrap(MyMw(false).into_middleware())
|
||||
.wrap(Logger::default())
|
||||
.default_service(web::to(HttpResponse::Ok))
|
||||
})
|
||||
.workers(1)
|
||||
.bind(bind)?
|
||||
.run()
|
||||
.await
|
||||
}
|
@@ -6,7 +6,7 @@
|
||||
//
|
||||
// See <https://github.com/rust-lang/rust/issues/83375>
|
||||
pub use actix_http::error::{ContentTypeError, DispatchError, HttpError, ParseError, PayloadError};
|
||||
use derive_more::derive::{Display, Error, From};
|
||||
use derive_more::{Display, Error, From};
|
||||
use serde_json::error::Error as JsonError;
|
||||
use serde_urlencoded::{de::Error as FormDeError, ser::Error as FormError};
|
||||
use url::ParseError as UrlParseError;
|
||||
|
@@ -10,7 +10,7 @@ use bytes::BufMut;
|
||||
/// perform a remaining length check before writing.
|
||||
pub(crate) struct MutWriter<'a, B>(pub(crate) &'a mut B);
|
||||
|
||||
impl<'a, B> io::Write for MutWriter<'a, B>
|
||||
impl<B> io::Write for MutWriter<'_, B>
|
||||
where
|
||||
B: BufMut,
|
||||
{
|
||||
|
@@ -206,11 +206,11 @@ impl DispositionParam {
|
||||
}
|
||||
}
|
||||
|
||||
/// A *Content-Disposition* header. It is compatible to be used either as
|
||||
/// [a response header for the main body](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#as_a_response_header_for_the_main_body)
|
||||
/// as (re)defined in [RFC 6266](https://datatracker.ietf.org/doc/html/rfc6266), or as
|
||||
/// [a header for a multipart body](https://mdn.io/Content-Disposition#As_a_header_for_a_multipart_body)
|
||||
/// as (re)defined in [RFC 7587](https://datatracker.ietf.org/doc/html/rfc7578).
|
||||
/// `Content-Disposition` header.
|
||||
///
|
||||
/// It is compatible to be used either as [a response header for the main body][use_main_body]
|
||||
/// as (re)defined in [RFC 6266], or as [a header for a multipart body][use_multipart] as
|
||||
/// (re)defined in [RFC 7587].
|
||||
///
|
||||
/// In a regular HTTP response, the *Content-Disposition* response header is a header indicating if
|
||||
/// the content is expected to be displayed *inline* in the browser, that is, as a Web page or as
|
||||
@@ -267,7 +267,7 @@ impl DispositionParam {
|
||||
/// parameters: vec![DispositionParam::FilenameExt(ExtendedValue {
|
||||
/// charset: Charset::Iso_8859_1, // The character set for the bytes of the filename
|
||||
/// language_tag: None, // The optional language tag (see `language-tag` crate)
|
||||
/// value: b"\xa9 Copyright 1989.txt".to_vec(), // the actual bytes of the filename
|
||||
/// value: b"\xA9 Ferris 2011.txt".to_vec(), // the actual bytes of the filename
|
||||
/// })],
|
||||
/// };
|
||||
/// assert!(cd1.is_attachment());
|
||||
@@ -305,6 +305,11 @@ impl DispositionParam {
|
||||
/// change to match local file system conventions if applicable, and do not use directory path
|
||||
/// information that may be present.
|
||||
/// See [RFC 2183 §2.3](https://datatracker.ietf.org/doc/html/rfc2183#section-2.3).
|
||||
///
|
||||
/// [use_main_body]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#as_a_response_header_for_the_main_body
|
||||
/// [RFC 6266]: https://datatracker.ietf.org/doc/html/rfc6266
|
||||
/// [use_multipart]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#as_a_header_for_a_multipart_body
|
||||
/// [RFC 7587]: https://datatracker.ietf.org/doc/html/rfc7578
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ContentDisposition {
|
||||
/// The disposition type
|
||||
|
@@ -1,6 +1,6 @@
|
||||
use std::{convert::Infallible, str};
|
||||
|
||||
use derive_more::derive::{Deref, DerefMut};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
|
||||
use crate::{
|
||||
error::ParseError,
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use std::{convert::Infallible, net::SocketAddr};
|
||||
|
||||
use actix_utils::future::{err, ok, Ready};
|
||||
use derive_more::derive::{Display, Error};
|
||||
use derive_more::{Display, Error};
|
||||
|
||||
use crate::{
|
||||
dev::{AppConfig, Payload, RequestHead},
|
||||
|
@@ -8,7 +8,7 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_service::{Service, Transform};
|
||||
use ahash::AHashMap;
|
||||
use foldhash::HashMap as FoldHashMap;
|
||||
use futures_core::{future::LocalBoxFuture, ready};
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
@@ -185,7 +185,7 @@ pub struct ErrorHandlers<B> {
|
||||
handlers: Handlers<B>,
|
||||
}
|
||||
|
||||
type Handlers<B> = Rc<AHashMap<StatusCode, Box<ErrorHandler<B>>>>;
|
||||
type Handlers<B> = Rc<FoldHashMap<StatusCode, Box<ErrorHandler<B>>>>;
|
||||
|
||||
impl<B> Default for ErrorHandlers<B> {
|
||||
fn default() -> Self {
|
||||
|
@@ -704,7 +704,7 @@ impl FormatText {
|
||||
/// Converter to get a String from something that writes to a Formatter.
|
||||
pub(crate) struct FormatDisplay<'a>(&'a dyn Fn(&mut fmt::Formatter<'_>) -> Result<(), fmt::Error>);
|
||||
|
||||
impl<'a> fmt::Display for FormatDisplay<'a> {
|
||||
impl fmt::Display for FormatDisplay<'_> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
(self.0)(fmt)
|
||||
}
|
||||
|
@@ -28,9 +28,9 @@ use crate::{
|
||||
///
|
||||
/// Resource in turn has at least one route. Route consists of an handlers objects and list of
|
||||
/// guards (objects that implement `Guard` trait). Resources and routes uses builder-like pattern
|
||||
/// for configuration. During request handling, resource object iterate through all routes and check
|
||||
/// guards for specific route, if request matches all guards, route considered matched and route
|
||||
/// handler get called.
|
||||
/// for configuration. During request handling, the resource object iterates through all routes
|
||||
/// and checks guards for the specific route, if the request matches all the guards, then the route
|
||||
/// is considered matched and the route handler gets called.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
|
@@ -131,6 +131,23 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
// Note: see https://github.com/actix/actix-web/issues/1108 for reasoning why Responder is not
|
||||
// implemented for `()`, and https://github.com/actix/actix-web/pull/3560 for discussion about this
|
||||
// impl and the decision not to include a similar one for `Option<()>`.
|
||||
impl<E> Responder for Result<(), E>
|
||||
where
|
||||
E: Into<Error>,
|
||||
{
|
||||
type Body = BoxBody;
|
||||
|
||||
fn respond_to(self, _req: &HttpRequest) -> HttpResponse {
|
||||
match self {
|
||||
Ok(()) => HttpResponse::new(StatusCode::NO_CONTENT),
|
||||
Err(err) => HttpResponse::from_error(err.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Responder> Responder for (R, StatusCode) {
|
||||
type Body = R::Body;
|
||||
|
||||
|
@@ -6,7 +6,7 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_router::ResourceDef;
|
||||
use ahash::AHashMap;
|
||||
use foldhash::HashMap as FoldHashMap;
|
||||
use url::Url;
|
||||
|
||||
use crate::{error::UrlGenerationError, request::HttpRequest};
|
||||
@@ -19,7 +19,7 @@ pub struct ResourceMap {
|
||||
|
||||
/// Named resources within the tree or, for external resources, it points to isolated nodes
|
||||
/// outside the tree.
|
||||
named: AHashMap<String, Rc<ResourceMap>>,
|
||||
named: FoldHashMap<String, Rc<ResourceMap>>,
|
||||
|
||||
parent: RefCell<Weak<ResourceMap>>,
|
||||
|
||||
@@ -32,7 +32,7 @@ impl ResourceMap {
|
||||
pub fn new(root: ResourceDef) -> Self {
|
||||
ResourceMap {
|
||||
pattern: root,
|
||||
named: AHashMap::default(),
|
||||
named: FoldHashMap::default(),
|
||||
parent: RefCell::new(Weak::new()),
|
||||
nodes: Some(Vec::new()),
|
||||
}
|
||||
@@ -86,7 +86,7 @@ impl ResourceMap {
|
||||
} else {
|
||||
let new_node = Rc::new(ResourceMap {
|
||||
pattern: pattern.clone(),
|
||||
named: AHashMap::default(),
|
||||
named: FoldHashMap::default(),
|
||||
parent: RefCell::new(Weak::new()),
|
||||
nodes: None,
|
||||
});
|
||||
|
@@ -193,7 +193,7 @@ where
|
||||
///
|
||||
/// One thread pool is set up **per worker**; not shared across workers.
|
||||
///
|
||||
/// By default set to 512 divided by the number of workers.
|
||||
/// By default, set to 512 divided by [available parallelism](std::thread::available_parallelism()).
|
||||
pub fn worker_max_blocking_threads(mut self, num: usize) -> Self {
|
||||
self.builder = self.builder.worker_max_blocking_threads(num);
|
||||
self
|
||||
@@ -1085,7 +1085,10 @@ fn create_tcp_listener(addr: net::SocketAddr, backlog: u32) -> io::Result<net::T
|
||||
use socket2::{Domain, Protocol, Socket, Type};
|
||||
let domain = Domain::for_address(addr);
|
||||
let socket = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?;
|
||||
socket.set_reuse_address(true)?;
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
socket.set_reuse_address(true)?;
|
||||
}
|
||||
socket.bind(&addr.into())?;
|
||||
// clamp backlog to max u32 that fits in i32 range
|
||||
let backlog = cmp::min(backlog, i32::MAX as u32) as i32;
|
||||
|
@@ -662,6 +662,7 @@ where
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! services {
|
||||
() => {()};
|
||||
($($x:expr),+ $(,)?) => {
|
||||
($($x,)+)
|
||||
}
|
||||
@@ -870,4 +871,40 @@ mod tests {
|
||||
let req = test::TestRequest::default().to_request();
|
||||
let _res = test::call_service(&app, req).await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn define_services_macro_with_multiple_arguments() {
|
||||
let result = services!(1, 2, 3);
|
||||
assert_eq!(result, (1, 2, 3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn define_services_macro_with_single_argument() {
|
||||
let result = services!(1);
|
||||
assert_eq!(result, (1,));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn define_services_macro_with_no_arguments() {
|
||||
let result = services!();
|
||||
let () = result;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn define_services_macro_with_trailing_comma() {
|
||||
let result = services!(1, 2, 3,);
|
||||
assert_eq!(result, (1, 2, 3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn define_services_macro_with_comments_in_arguments() {
|
||||
let result = services!(
|
||||
1, // First comment
|
||||
2, // Second comment
|
||||
3 // Third comment
|
||||
);
|
||||
|
||||
// Assert that comments are ignored and it correctly returns a tuple.
|
||||
assert_eq!(result, (1, 2, 3));
|
||||
}
|
||||
}
|
||||
|
@@ -332,7 +332,7 @@ impl<T: DeserializeOwned> JsonBody<T> {
|
||||
(true, Ok(Some(mime))) => {
|
||||
mime.subtype() == mime::JSON
|
||||
|| mime.suffix() == Some(mime::JSON)
|
||||
|| ctype_fn.map_or(false, |predicate| predicate(mime))
|
||||
|| ctype_fn.is_some_and(|predicate| predicate(mime))
|
||||
}
|
||||
|
||||
// if content-type is expected but not parsable as mime type, bail
|
||||
|
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use actix_router::PathDeserializer;
|
||||
use actix_utils::future::{ready, Ready};
|
||||
use derive_more::derive::{AsRef, Deref, DerefMut, Display, From};
|
||||
use derive_more::{AsRef, Deref, DerefMut, Display, From};
|
||||
use serde::de;
|
||||
|
||||
use crate::{
|
||||
@@ -152,7 +152,7 @@ impl PathConfig {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_router::ResourceDef;
|
||||
use derive_more::derive::Display;
|
||||
use derive_more::Display;
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::*;
|
||||
|
@@ -187,7 +187,7 @@ impl QueryConfig {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_http::StatusCode;
|
||||
use derive_more::derive::Display;
|
||||
use derive_more::Display;
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::*;
|
||||
|
@@ -1,13 +1,10 @@
|
||||
#[cfg(feature = "openssl")]
|
||||
extern crate tls_openssl as openssl;
|
||||
|
||||
#[cfg(any(unix, feature = "openssl"))]
|
||||
use {
|
||||
actix_web::{web, App, HttpResponse, HttpServer},
|
||||
std::{sync::mpsc, thread, time::Duration},
|
||||
};
|
||||
use std::{sync::mpsc, thread, time::Duration};
|
||||
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
|
||||
#[cfg(unix)]
|
||||
#[actix_rt::test]
|
||||
async fn test_start() {
|
||||
let addr = actix_test::unused_addr();
|
||||
@@ -53,6 +50,27 @@ async fn test_start() {
|
||||
let response = client.get(host.clone()).send().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
|
||||
// Attempt to start a second server using the same address.
|
||||
let result = HttpServer::new(|| {
|
||||
App::new().service(
|
||||
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body("test") })),
|
||||
)
|
||||
})
|
||||
.workers(1)
|
||||
.backlog(1)
|
||||
.max_connections(10)
|
||||
.max_connection_rate(10)
|
||||
.keep_alive(Duration::from_secs(10))
|
||||
.client_request_timeout(Duration::from_secs(5))
|
||||
.client_disconnect_timeout(Duration::ZERO)
|
||||
.server_hostname("localhost")
|
||||
.system_exit()
|
||||
.disable_signals()
|
||||
.bind(format!("{}", addr));
|
||||
|
||||
// This should fail: the address is in use.
|
||||
assert!(result.is_err());
|
||||
|
||||
srv.stop(false).await;
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ use openssl::{
|
||||
ssl::{SslAcceptor, SslMethod},
|
||||
x509::X509,
|
||||
};
|
||||
use rand::{distributions::Alphanumeric, Rng as _};
|
||||
use rand::distr::{Alphanumeric, SampleString as _};
|
||||
|
||||
mod utils;
|
||||
|
||||
@@ -188,11 +188,7 @@ async fn body_gzip_large() {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_body_gzip_large_random() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(70_000)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 70_000);
|
||||
let srv_data = data.clone();
|
||||
|
||||
let srv = actix_test::start_with(actix_test::config().h1(), move || {
|
||||
@@ -432,11 +428,7 @@ async fn test_zstd_encoding() {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_zstd_encoding_large() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(320_000)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 320_000);
|
||||
|
||||
let srv = actix_test::start_with(actix_test::config().h1(), || {
|
||||
App::new().service(
|
||||
@@ -529,11 +521,7 @@ async fn test_gzip_encoding_large() {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_reading_gzip_encoding_large_random() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(60_000)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 60_000);
|
||||
|
||||
let srv = actix_test::start_with(actix_test::config().h1(), || {
|
||||
App::new().service(web::resource("/").route(web::to(move |body: Bytes| async {
|
||||
@@ -599,11 +587,7 @@ async fn test_reading_deflate_encoding_large() {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_reading_deflate_encoding_large_random() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(160_000)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 160_000);
|
||||
|
||||
let srv = actix_test::start_with(actix_test::config().h1(), || {
|
||||
App::new().service(web::resource("/").route(web::to(move |body: Bytes| async {
|
||||
@@ -648,11 +632,7 @@ async fn test_brotli_encoding() {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_brotli_encoding_large() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(320_000)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 320_000);
|
||||
|
||||
let srv = actix_test::start_with(actix_test::config().h1(), || {
|
||||
App::new().service(
|
||||
@@ -737,11 +717,7 @@ mod plus_rustls {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_reading_deflate_encoding_large_random_rustls() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(160_000)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 160_000);
|
||||
|
||||
let srv = actix_test::start_with(actix_test::config().rustls_0_23(tls_config()), || {
|
||||
App::new().service(web::resource("/").route(web::to(|bytes: Bytes| async {
|
||||
|
@@ -2,7 +2,11 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 3.6.0
|
||||
|
||||
- Prevent panics on connection pool drop when Tokio runtime is shutdown early.
|
||||
- Do not send `Host` header on HTTP/2 requests, as it is not required, and some web servers may reject it.
|
||||
- Update `brotli` dependency to `7`.
|
||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
||||
|
||||
## 3.5.1
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "awc"
|
||||
version = "3.5.1"
|
||||
version = "3.6.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Async HTTP and WebSocket client library"
|
||||
keywords = ["actix", "http", "framework", "async", "web"]
|
||||
@@ -106,7 +106,7 @@ actix-utils = "3"
|
||||
base64 = "0.22"
|
||||
bytes = "1"
|
||||
cfg-if = "1"
|
||||
derive_more = { version = "1", features = ["display", "error", "from"] }
|
||||
derive_more = { version = "2", features = ["display", "error", "from"] }
|
||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
futures-util = { version = "0.3.17", default-features = false, features = ["alloc", "sink"] }
|
||||
h2 = "0.3.26"
|
||||
@@ -116,7 +116,7 @@ log =" 0.4"
|
||||
mime = "0.3"
|
||||
percent-encoding = "2.1"
|
||||
pin-project-lite = "0.2"
|
||||
rand = "0.8"
|
||||
rand = "0.9"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_urlencoded = "0.7"
|
||||
@@ -141,7 +141,7 @@ actix-tls = { version = "3.4", features = ["openssl", "rustls-0_23"] }
|
||||
actix-utils = "3"
|
||||
actix-web = { version = "4", features = ["openssl"] }
|
||||
|
||||
brotli = "6"
|
||||
brotli = "7"
|
||||
const-str = "0.5"
|
||||
env_logger = "0.11"
|
||||
flate2 = "1.0.13"
|
||||
@@ -153,9 +153,9 @@ tokio = { version = "1.24.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
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[[example]]
|
||||
name = "client"
|
||||
required-features = ["rustls-0_23-webpki-roots"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
@@ -5,9 +5,9 @@
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/awc)
|
||||
[](https://docs.rs/awc/3.5.1)
|
||||
[](https://docs.rs/awc/3.6.0)
|
||||

|
||||
[](https://deps.rs/crate/awc/3.5.1)
|
||||
[](https://deps.rs/crate/awc/3.6.0)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
@@ -1,25 +1,39 @@
|
||||
use std::error::Error as StdError;
|
||||
//! Demonstrates construction and usage of a TLS-capable HTTP client.
|
||||
|
||||
extern crate tls_rustls_0_23 as rustls;
|
||||
|
||||
use std::{error::Error as StdError, sync::Arc};
|
||||
|
||||
use actix_tls::connect::rustls_0_23::webpki_roots_cert_store;
|
||||
use rustls::ClientConfig;
|
||||
|
||||
/// If we want to make requests to addresses starting with `https`, we need to enable the rustls feature of awc
|
||||
/// `awc = { version = "3.5.0", features = ["rustls"] }`
|
||||
#[actix_rt::main]
|
||||
async fn main() -> Result<(), Box<dyn StdError>> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
// construct request builder
|
||||
let client = awc::Client::new();
|
||||
let mut config = ClientConfig::builder()
|
||||
.with_root_certificates(webpki_roots_cert_store())
|
||||
.with_no_client_auth();
|
||||
|
||||
let protos = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
|
||||
config.alpn_protocols = protos;
|
||||
|
||||
// construct request builder with TLS support
|
||||
let client = awc::Client::builder()
|
||||
.connector(awc::Connector::new().rustls_0_23(Arc::new(config)))
|
||||
.finish();
|
||||
|
||||
// configure request
|
||||
let request = client
|
||||
.get("https://www.rust-lang.org/")
|
||||
.append_header(("User-Agent", "Actix-web"));
|
||||
.append_header(("User-Agent", "awc/3.0"));
|
||||
|
||||
println!("Request: {:?}", request);
|
||||
println!("Request: {request:?}");
|
||||
|
||||
let mut response = request.send().await?;
|
||||
|
||||
// server response head
|
||||
println!("Response: {:?}", response);
|
||||
println!("Response: {response:?}");
|
||||
|
||||
// read response body
|
||||
let body = response.body().await?;
|
||||
|
@@ -511,7 +511,8 @@ where
|
||||
let h2 = sock
|
||||
.ssl()
|
||||
.selected_alpn_protocol()
|
||||
.map_or(false, |protos| protos.windows(2).any(|w| w == H2));
|
||||
.is_some_and(|protos| protos.windows(2).any(|w| w == H2));
|
||||
|
||||
if h2 {
|
||||
(Box::new(sock), Protocol::Http2)
|
||||
} else {
|
||||
@@ -550,7 +551,8 @@ where
|
||||
.get_ref()
|
||||
.1
|
||||
.alpn_protocol()
|
||||
.map_or(false, |protos| protos.windows(2).any(|w| w == H2));
|
||||
.is_some_and(|protos| protos.windows(2).any(|w| w == H2));
|
||||
|
||||
if h2 {
|
||||
(Box::new(sock), Protocol::Http2)
|
||||
} else {
|
||||
@@ -584,7 +586,8 @@ where
|
||||
.get_ref()
|
||||
.1
|
||||
.alpn_protocol()
|
||||
.map_or(false, |protos| protos.windows(2).any(|w| w == H2));
|
||||
.is_some_and(|protos| protos.windows(2).any(|w| w == H2));
|
||||
|
||||
if h2 {
|
||||
(Box::new(sock), Protocol::Http2)
|
||||
} else {
|
||||
@@ -621,7 +624,8 @@ where
|
||||
.get_ref()
|
||||
.1
|
||||
.alpn_protocol()
|
||||
.map_or(false, |protos| protos.windows(2).any(|w| w == H2));
|
||||
.is_some_and(|protos| protos.windows(2).any(|w| w == H2));
|
||||
|
||||
if h2 {
|
||||
(Box::new(sock), Protocol::Http2)
|
||||
} else {
|
||||
@@ -655,7 +659,8 @@ where
|
||||
.get_ref()
|
||||
.1
|
||||
.alpn_protocol()
|
||||
.map_or(false, |protos| protos.windows(2).any(|w| w == H2));
|
||||
.is_some_and(|protos| protos.windows(2).any(|w| w == H2));
|
||||
|
||||
if h2 {
|
||||
(Box::new(sock), Protocol::Http2)
|
||||
} else {
|
||||
|
@@ -3,7 +3,7 @@ use std::{fmt, io};
|
||||
use actix_http::error::{HttpError, ParseError};
|
||||
#[cfg(feature = "openssl")]
|
||||
use actix_tls::accept::openssl::reexports::Error as OpensslError;
|
||||
use derive_more::derive::{Display, From};
|
||||
use derive_more::{Display, From};
|
||||
|
||||
use crate::BoxError;
|
||||
|
||||
|
@@ -12,7 +12,7 @@ use h2::{
|
||||
SendStream,
|
||||
};
|
||||
use http::{
|
||||
header::{HeaderValue, CONNECTION, CONTENT_LENGTH, TRANSFER_ENCODING},
|
||||
header::{HeaderValue, CONNECTION, CONTENT_LENGTH, HOST, TRANSFER_ENCODING},
|
||||
request::Request,
|
||||
Method, Version,
|
||||
};
|
||||
@@ -97,7 +97,7 @@ where
|
||||
// TODO: consider skipping other headers according to:
|
||||
// https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.2
|
||||
// omit HTTP/1.x only headers
|
||||
CONNECTION | TRANSFER_ENCODING => continue,
|
||||
CONNECTION | TRANSFER_ENCODING | HOST => continue,
|
||||
CONTENT_LENGTH if skip_len => continue,
|
||||
// DATE => has_date = true,
|
||||
_ => {}
|
||||
|
@@ -7,7 +7,7 @@ pub use actix_http::{
|
||||
ws::{HandshakeError as WsHandshakeError, ProtocolError as WsProtocolError},
|
||||
StatusCode,
|
||||
};
|
||||
use derive_more::derive::{Display, From};
|
||||
use derive_more::{Display, From};
|
||||
use serde_json::error::Error as JsonError;
|
||||
|
||||
pub use crate::client::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
|
||||
|
@@ -17,7 +17,7 @@ use actix_http::{
|
||||
use actix_http::{encoding::Decoder, header::ContentEncoding, Payload};
|
||||
use actix_rt::time::{sleep, Sleep};
|
||||
use bytes::Bytes;
|
||||
use derive_more::derive::From;
|
||||
use derive_more::From;
|
||||
use futures_core::Stream;
|
||||
use serde::Serialize;
|
||||
|
||||
|
@@ -326,7 +326,7 @@ impl WebsocketsRequest {
|
||||
|
||||
// Generate a random key for the `Sec-WebSocket-Key` header which is a base64-encoded
|
||||
// (see RFC 4648 §4) value that, when decoded, is 16 bytes in length (RFC 6455 §1.3).
|
||||
let sec_key: [u8; 16] = rand::random();
|
||||
let sec_key = rand::random::<[u8; 16]>();
|
||||
let key = BASE64_STANDARD.encode(sec_key);
|
||||
|
||||
self.head.headers.insert(
|
||||
@@ -444,7 +444,7 @@ struct Host<'a> {
|
||||
port: Option<http::uri::Port<&'a str>>,
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for Host<'a> {
|
||||
impl fmt::Display for Host<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(self.hostname)?;
|
||||
|
||||
|
@@ -20,7 +20,7 @@ use base64::prelude::*;
|
||||
use bytes::Bytes;
|
||||
use cookie::Cookie;
|
||||
use futures_util::stream;
|
||||
use rand::Rng;
|
||||
use rand::distr::{Alphanumeric, SampleString as _};
|
||||
|
||||
mod utils;
|
||||
|
||||
@@ -516,11 +516,7 @@ async fn client_gzip_encoding_large() {
|
||||
#[cfg(feature = "compress-gzip")]
|
||||
#[actix_rt::test]
|
||||
async fn client_gzip_encoding_large_random() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(&rand::distributions::Alphanumeric)
|
||||
.take(100_000)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 100_000);
|
||||
|
||||
let srv = actix_test::start(|| {
|
||||
App::new().service(web::resource("/").route(web::to(|data: Bytes| async {
|
||||
@@ -562,11 +558,7 @@ async fn client_brotli_encoding() {
|
||||
#[cfg(feature = "compress-brotli")]
|
||||
#[actix_rt::test]
|
||||
async fn client_brotli_encoding_large_random() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(&rand::distributions::Alphanumeric)
|
||||
.take(70_000)
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 70_000);
|
||||
|
||||
let srv = actix_test::start(|| {
|
||||
App::new().service(web::resource("/").route(web::to(|data: Bytes| async {
|
||||
@@ -607,11 +599,7 @@ async fn client_deflate_encoding() {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn client_deflate_encoding_large_random() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(rand::distributions::Alphanumeric)
|
||||
.map(char::from)
|
||||
.take(70_000)
|
||||
.collect::<String>();
|
||||
let data = Alphanumeric.sample_string(&mut rand::rng(), 70_000);
|
||||
|
||||
let srv = actix_test::start(|| {
|
||||
App::new().default_service(web::to(|body: Bytes| async {
|
||||
|
14
justfile
14
justfile
@@ -10,7 +10,11 @@ fmt:
|
||||
# Downgrade dev-dependencies necessary to run MSRV checks/tests.
|
||||
[private]
|
||||
downgrade-for-msrv:
|
||||
cargo update -p=parse-size --precise=1.0.0
|
||||
cargo update -p=clap --precise=4.4.18
|
||||
cargo update -p=divan --precise=0.1.15
|
||||
cargo update -p=litemap --precise=0.7.4
|
||||
cargo update -p=zerofrom --precise=0.1.5
|
||||
|
||||
msrv := ```
|
||||
cargo metadata --format-version=1 \
|
||||
@@ -35,6 +39,9 @@ check-min:
|
||||
check-default:
|
||||
cargo hack --workspace check
|
||||
|
||||
# Run Clippy over workspace.
|
||||
check toolchain="": && (clippy toolchain)
|
||||
|
||||
# Run Clippy over workspace.
|
||||
clippy toolchain="":
|
||||
cargo {{ toolchain }} clippy --workspace --all-targets {{ all_crate_features }}
|
||||
@@ -46,8 +53,8 @@ test-msrv: downgrade-for-msrv (test msrv_rustup)
|
||||
test toolchain="":
|
||||
cargo {{ toolchain }} test --lib --tests -p=actix-web-codegen --all-features
|
||||
cargo {{ toolchain }} test --lib --tests -p=actix-multipart-derive --all-features
|
||||
cargo {{ toolchain }} nextest run -p=actix-router --no-default-features
|
||||
cargo {{ toolchain }} nextest run --workspace --exclude=actix-web-codegen --exclude=actix-multipart-derive {{ all_crate_features }} --filter-expr="not test(test_reading_deflate_encoding_large_random_rustls)"
|
||||
cargo {{ toolchain }} nextest run --no-tests=warn -p=actix-router --no-default-features
|
||||
cargo {{ toolchain }} nextest run --no-tests=warn --workspace --exclude=actix-web-codegen --exclude=actix-multipart-derive {{ all_crate_features }} --filter-expr="not test(test_reading_deflate_encoding_large_random_rustls)"
|
||||
|
||||
# Test workspace docs.
|
||||
test-docs toolchain="": && doc
|
||||
@@ -59,7 +66,7 @@ test-all toolchain="": (test toolchain) (test-docs toolchain)
|
||||
# Test workspace and collect coverage info.
|
||||
[private]
|
||||
test-coverage toolchain="":
|
||||
cargo {{ toolchain }} llvm-cov nextest --no-report {{ all_crate_features }}
|
||||
cargo {{ toolchain }} llvm-cov nextest --no-tests=warn --no-report {{ all_crate_features }}
|
||||
cargo {{ toolchain }} llvm-cov --doc --no-report {{ all_crate_features }}
|
||||
|
||||
# Test workspace and generate Codecov report.
|
||||
@@ -72,6 +79,7 @@ test-coverage-lcov toolchain="": (test-coverage toolchain)
|
||||
|
||||
# Document crates in workspace.
|
||||
doc *args: && doc-set-workspace-crates
|
||||
rm -f "$(cargo metadata --format-version=1 | jq -r '.target_directory')/doc/crates.js"
|
||||
RUSTDOCFLAGS="--cfg=docsrs -Dwarnings" cargo +nightly doc --workspace {{ all_crate_features }} {{ args }}
|
||||
|
||||
[private]
|
||||
|
Reference in New Issue
Block a user