mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-13 21:53:59 +02:00
Compare commits
1 Commits
web-v4.5.1
...
real-async
Author | SHA1 | Date | |
---|---|---|---|
9a4090761c |
@ -1,6 +1,6 @@
|
||||
[alias]
|
||||
lint = "clippy --workspace --all-targets -- -Dclippy::todo"
|
||||
lint-all = "clippy --workspace --all-features --all-targets -- -Dclippy::todo"
|
||||
lint = "clippy --workspace --tests --examples --bins -- -Dclippy::todo"
|
||||
lint-all = "clippy --workspace --all-features --tests --examples --bins -- -Dclippy::todo"
|
||||
|
||||
# lib checking
|
||||
ci-check-min = "hack --workspace check --no-default-features"
|
||||
|
36
.github/workflows/ci-post-merge.yml
vendored
36
.github/workflows/ci-post-merge.yml
vendored
@ -32,22 +32,22 @@ jobs:
|
||||
|
||||
- name: Install OpenSSL
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
shell: bash
|
||||
run: choco install openssl -y --forcex64 --no-progress
|
||||
- name: Set OpenSSL dir in env
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
run: |
|
||||
set -e
|
||||
choco install openssl --version=1.1.1.2100 -y --no-progress
|
||||
echo 'OPENSSL_DIR=C:\Program Files\OpenSSL' >> $GITHUB_ENV
|
||||
echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
|
||||
echo 'OPENSSL_DIR=C:\Program Files\OpenSSL-Win64' | Out-File -FilePath $env:GITHUB_ENV -Append
|
||||
echo 'OPENSSL_DIR=C:\Program Files\OpenSSL' | Out-File -FilePath $env:GITHUB_ENV -Append
|
||||
|
||||
- name: Install Rust (${{ matrix.version.name }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install cargo-hack and cargo-ci-cache-clean
|
||||
uses: taiki-e/install-action@v2.26.8
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
with:
|
||||
tool: cargo-hack,cargo-ci-cache-clean
|
||||
tool: cargo-hack
|
||||
|
||||
- name: check minimal
|
||||
run: cargo ci-check-min
|
||||
@ -57,12 +57,10 @@ jobs:
|
||||
|
||||
- name: tests
|
||||
timeout-minutes: 60
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
cargo test --lib --tests -p=actix-router --all-features
|
||||
cargo test --lib --tests -p=actix-http --all-features
|
||||
cargo test --lib --tests -p=actix-web --features=rustls-0_20,rustls-0_21,rustls-0_22,openssl -- --skip=test_reading_deflate_encoding_large_random_rustls
|
||||
cargo test --lib --tests -p=actix-web --features=rustls-0_20,rustls-0_21,openssl -- --skip=test_reading_deflate_encoding_large_random_rustls
|
||||
cargo test --lib --tests -p=actix-web-codegen --all-features
|
||||
cargo test --lib --tests -p=awc --all-features
|
||||
cargo test --lib --tests -p=actix-http-test --all-features
|
||||
@ -71,8 +69,10 @@ jobs:
|
||||
cargo test --lib --tests -p=actix-multipart --all-features
|
||||
cargo test --lib --tests -p=actix-web-actors --all-features
|
||||
|
||||
- name: CI cache clean
|
||||
run: cargo-ci-cache-clean
|
||||
- name: Clear the cargo caches
|
||||
run: |
|
||||
cargo install cargo-cache --version 0.8.3 --no-default-features --features ci-autoclean
|
||||
cargo-cache
|
||||
|
||||
ci_feature_powerset_check:
|
||||
name: Verify Feature Combinations
|
||||
@ -82,10 +82,10 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@v2.26.8
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
with:
|
||||
tool: cargo-hack
|
||||
|
||||
@ -103,10 +103,10 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
|
||||
- name: Install nextest
|
||||
uses: taiki-e/install-action@v2.26.8
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
with:
|
||||
tool: nextest
|
||||
|
||||
|
34
.github/workflows/ci.yml
vendored
34
.github/workflows/ci.yml
vendored
@ -37,28 +37,26 @@ jobs:
|
||||
|
||||
- name: Install OpenSSL
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
shell: bash
|
||||
run: choco install openssl -y --forcex64 --no-progress
|
||||
- name: Set OpenSSL dir in env
|
||||
if: matrix.target.os == 'windows-latest'
|
||||
run: |
|
||||
set -e
|
||||
choco install openssl --version=1.1.1.2100 -y --no-progress
|
||||
echo 'OPENSSL_DIR=C:\Program Files\OpenSSL' >> $GITHUB_ENV
|
||||
echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
|
||||
echo 'OPENSSL_DIR=C:\Program Files\OpenSSL-Win64' | Out-File -FilePath $env:GITHUB_ENV -Append
|
||||
echo 'OPENSSL_DIR=C:\Program Files\OpenSSL' | Out-File -FilePath $env:GITHUB_ENV -Append
|
||||
|
||||
- name: Install Rust (${{ matrix.version.name }})
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install cargo-hack and cargo-ci-cache-clean
|
||||
uses: taiki-e/install-action@v2.26.8
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
with:
|
||||
tool: cargo-hack,cargo-ci-cache-clean
|
||||
tool: cargo-hack
|
||||
|
||||
- name: workaround MSRV issues
|
||||
if: matrix.version.name == 'msrv'
|
||||
run: |
|
||||
cargo update -p=ciborium --precise=0.2.1
|
||||
cargo update -p=ciborium-ll --precise=0.2.1
|
||||
cargo update -p=clap --precise=4.3.24
|
||||
cargo update -p=clap_lex --precise=0.5.0
|
||||
cargo update -p=anstyle --precise=1.0.2
|
||||
@ -71,12 +69,10 @@ jobs:
|
||||
|
||||
- name: tests
|
||||
timeout-minutes: 60
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
cargo test --lib --tests -p=actix-router --all-features
|
||||
cargo test --lib --tests -p=actix-http --all-features
|
||||
cargo test --lib --tests -p=actix-web --features=rustls-0_20,rustls-0_21,rustls-0_22,openssl -- --skip=test_reading_deflate_encoding_large_random_rustls
|
||||
cargo test --lib --tests -p=actix-web --features=rustls-0_20,rustls-0_21,openssl -- --skip=test_reading_deflate_encoding_large_random_rustls
|
||||
cargo test --lib --tests -p=actix-web-codegen --all-features
|
||||
cargo test --lib --tests -p=awc --all-features
|
||||
cargo test --lib --tests -p=actix-http-test --all-features
|
||||
@ -85,8 +81,10 @@ jobs:
|
||||
cargo test --lib --tests -p=actix-multipart --all-features
|
||||
cargo test --lib --tests -p=actix-web-actors --all-features
|
||||
|
||||
- name: CI cache clean
|
||||
run: cargo-ci-cache-clean
|
||||
- name: Clear the cargo caches
|
||||
run: |
|
||||
cargo install cargo-cache --version 0.8.3 --no-default-features --features ci-autoclean
|
||||
cargo-cache
|
||||
|
||||
io-uring:
|
||||
name: io-uring tests
|
||||
@ -95,7 +93,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
toolchain: nightly
|
||||
|
||||
@ -111,7 +109,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
toolchain: nightly
|
||||
|
||||
|
8
.github/workflows/coverage.yml
vendored
8
.github/workflows/coverage.yml
vendored
@ -18,12 +18,12 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
components: llvm-tools-preview
|
||||
|
||||
- name: Install cargo-llvm-cov
|
||||
uses: taiki-e/install-action@v2.26.8
|
||||
uses: taiki-e/install-action@v2.22.0
|
||||
with:
|
||||
tool: cargo-llvm-cov
|
||||
|
||||
@ -31,9 +31,7 @@ jobs:
|
||||
run: cargo llvm-cov --workspace --all-features --codecov --output-path codecov.json
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v4.0.0
|
||||
uses: codecov/codecov-action@v3.1.4
|
||||
with:
|
||||
files: codecov.json
|
||||
fail_ci_if_error: true
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
24
.github/workflows/lint.yml
vendored
24
.github/workflows/lint.yml
vendored
@ -17,13 +17,12 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: rustfmt
|
||||
|
||||
- name: Check with Rustfmt
|
||||
- name: Check with rustfmt
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
clippy:
|
||||
@ -36,7 +35,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
components: clippy
|
||||
|
||||
@ -54,8 +53,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: rust-docs
|
||||
@ -68,25 +66,21 @@ jobs:
|
||||
public-api-diff:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout main branch
|
||||
uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.base_ref }}
|
||||
|
||||
- name: Checkout PR branch
|
||||
uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
toolchain: nightly-2023-08-25
|
||||
|
||||
- name: Install cargo-public-api
|
||||
uses: taiki-e/install-action@v2.26.8
|
||||
- uses: taiki-e/cache-cargo-install-action@v1.3.0
|
||||
with:
|
||||
tool: cargo-public-api
|
||||
|
||||
- name: Generate API diff
|
||||
- name: generate API diff
|
||||
run: |
|
||||
for f in $(find -mindepth 2 -maxdepth 2 -name Cargo.toml); do
|
||||
cargo public-api --manifest-path "$f" diff ${{ github.event.pull_request.base.sha }}..${{ github.sha }}
|
||||
|
2
.github/workflows/upload-doc.yml
vendored
2
.github/workflows/upload-doc.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.6.0
|
||||
with:
|
||||
toolchain: nightly
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
overrides:
|
||||
- files: "*.md"
|
||||
- files: '*.md'
|
||||
options:
|
||||
printWidth: 9999
|
||||
proseWrap: never
|
||||
|
@ -2,13 +2,6 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 0.6.5
|
||||
|
||||
- Fix handling of special characters in filenames.
|
||||
|
||||
## 0.6.4
|
||||
|
||||
- Fix handling of newlines in filenames.
|
||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||
|
||||
## 0.6.3
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-files"
|
||||
version = "0.6.5"
|
||||
version = "0.6.3"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
|
@ -1,32 +1,18 @@
|
||||
# `actix-files`
|
||||
# actix-files
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
> Static file serving for Actix Web
|
||||
|
||||
[](https://crates.io/crates/actix-files)
|
||||
[](https://docs.rs/actix-files/0.6.5)
|
||||
[](https://docs.rs/actix-files/0.6.3)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-files/0.6.5)
|
||||
[](https://deps.rs/crate/actix-files/0.6.3)
|
||||
[](https://crates.io/crates/actix-files)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
## Documentation & Resources
|
||||
|
||||
<!-- cargo-rdme start -->
|
||||
|
||||
Static file serving for Actix Web.
|
||||
|
||||
Provides a non-blocking service for serving static files from disk.
|
||||
|
||||
## Examples
|
||||
|
||||
```rust
|
||||
use actix_web::App;
|
||||
use actix_files::Files;
|
||||
|
||||
let app = App::new()
|
||||
.service(Files::new("/static", ".").prefer_utf8(true));
|
||||
```
|
||||
|
||||
<!-- cargo-rdme end -->
|
||||
- [API Documentation](https://docs.rs/actix-files)
|
||||
- [Example Project](https://github.com/actix/examples/tree/master/basics/static-files)
|
||||
- Minimum Supported Rust Version (MSRV): 1.68
|
||||
|
@ -568,30 +568,6 @@ mod tests {
|
||||
assert_eq!(bytes, data);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[actix_rt::test]
|
||||
async fn test_static_files_with_special_characters() {
|
||||
// Create the file we want to test against ad-hoc. We can't check it in as otherwise
|
||||
// Windows can't even checkout this repository.
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let file_with_newlines = temp_dir.path().join("test\n\x0B\x0C\rnewline.text");
|
||||
fs::write(&file_with_newlines, "Look at my newlines").unwrap();
|
||||
|
||||
let srv = test::init_service(
|
||||
App::new().service(Files::new("/", temp_dir.path()).index_file("Cargo.toml")),
|
||||
)
|
||||
.await;
|
||||
let request = TestRequest::get()
|
||||
.uri("/test%0A%0B%0C%0Dnewline.text")
|
||||
.to_request();
|
||||
let response = test::call_service(&srv, request).await;
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
|
||||
let bytes = test::read_body(response).await;
|
||||
let data = web::Bytes::from(fs::read(file_with_newlines).unwrap());
|
||||
assert_eq!(bytes, data);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_files_not_allowed() {
|
||||
let srv = test::init_service(App::new().service(Files::new("/", "."))).await;
|
||||
@ -864,9 +840,9 @@ mod tests {
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_percent_encoding_2() {
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let tmpdir = tempfile::tempdir().unwrap();
|
||||
let filename = match cfg!(unix) {
|
||||
true => "ض:?#[]{}<>()@!$&'`|*+,;= %20\n.test",
|
||||
true => "ض:?#[]{}<>()@!$&'`|*+,;= %20.test",
|
||||
false => "ض#[]{}()@!$&'`+,;= %20.test",
|
||||
};
|
||||
let filename_encoded = filename
|
||||
@ -876,9 +852,9 @@ mod tests {
|
||||
write!(&mut buf, "%{:02X}", c).unwrap();
|
||||
buf
|
||||
});
|
||||
std::fs::File::create(temp_dir.path().join(filename)).unwrap();
|
||||
std::fs::File::create(tmpdir.path().join(filename)).unwrap();
|
||||
|
||||
let srv = test::init_service(App::new().service(Files::new("/", temp_dir.path()))).await;
|
||||
let srv = test::init_service(App::new().service(Files::new("", tmpdir.path()))).await;
|
||||
|
||||
let req = TestRequest::get()
|
||||
.uri(&format!("/{}", filename_encoded))
|
||||
|
@ -24,6 +24,7 @@ use bitflags::bitflags;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use mime::Mime;
|
||||
use mime_guess::from_path;
|
||||
|
||||
use crate::{encoding::equiv_utf8_text, range::HttpRange};
|
||||
|
||||
@ -127,7 +128,7 @@ impl NamedFile {
|
||||
}
|
||||
};
|
||||
|
||||
let ct = mime_guess::from_path(&path).first_or_octet_stream();
|
||||
let ct = from_path(&path).first_or_octet_stream();
|
||||
|
||||
let disposition = match ct.type_() {
|
||||
mime::IMAGE | mime::TEXT | mime::AUDIO | mime::VIDEO => DispositionType::Inline,
|
||||
@ -139,13 +140,7 @@ impl NamedFile {
|
||||
_ => DispositionType::Attachment,
|
||||
};
|
||||
|
||||
// replace special characters in filenames which could occur on some filesystems
|
||||
let filename_s = filename
|
||||
.replace('\n', "%0A") // \n line break
|
||||
.replace('\x0B', "%0B") // \v vertical tab
|
||||
.replace('\x0C', "%0C") // \f form feed
|
||||
.replace('\r', "%0D"); // \r carriage return
|
||||
let mut parameters = vec![DispositionParam::Filename(filename_s)];
|
||||
let mut parameters = vec![DispositionParam::Filename(String::from(filename.as_ref()))];
|
||||
|
||||
if !filename.is_ascii() {
|
||||
parameters.push(DispositionParam::FilenameExt(ExtendedValue {
|
||||
|
@ -3,7 +3,6 @@ use std::{
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use actix_utils::future::{ready, Ready};
|
||||
use actix_web::{dev::Payload, FromRequest, HttpRequest};
|
||||
|
||||
use crate::error::UriSegmentError;
|
||||
@ -88,10 +87,10 @@ impl AsRef<Path> for PathBufWrap {
|
||||
|
||||
impl FromRequest for PathBufWrap {
|
||||
type Error = UriSegmentError;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
ready(req.match_info().unprocessed().parse())
|
||||
#[inline]
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
req.match_info().unprocessed().parse()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 3.2.0
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||
|
||||
## 3.1.0
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-http-test"
|
||||
version = "3.2.0"
|
||||
version = "3.1.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Various helpers for Actix applications to use during testing"
|
||||
keywords = ["http", "web", "framework", "async", "futures"]
|
||||
|
@ -1,20 +1,16 @@
|
||||
# `actix-http-test`
|
||||
# actix-http-test
|
||||
|
||||
> Various helpers for Actix applications to use during testing.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-http-test)
|
||||
[](https://docs.rs/actix-http-test/3.2.0)
|
||||
[](https://docs.rs/actix-http-test/3.1.0)
|
||||

|
||||

|
||||
<br>
|
||||
[](https://deps.rs/crate/actix-http-test/3.2.0)
|
||||
[](https://deps.rs/crate/actix-http-test/3.1.0)
|
||||
[](https://crates.io/crates/actix-http-test)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-http-test)
|
||||
|
@ -2,33 +2,14 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 3.6.0
|
||||
|
||||
### Added
|
||||
|
||||
- Add `rustls-0_22` crate feature.
|
||||
- Add `{h1::H1Service, h2::H2Service, HttpService}::rustls_0_22()` and `HttpService::rustls_0_22_with_config()` service constructors.
|
||||
- Implement `From<&HeaderMap>` for `http::HeaderMap`.
|
||||
|
||||
## 3.5.1
|
||||
|
||||
### Fixed
|
||||
|
||||
- Prevent hang when returning zero-sized response bodies through compression layer.
|
||||
|
||||
## 3.5.0
|
||||
|
||||
### Added
|
||||
|
||||
- Implement `From<HeaderMap>` for `http::HeaderMap`.
|
||||
|
||||
### Changed
|
||||
|
||||
- Updated `zstd` dependency to `0.13`.
|
||||
- Implemented `From<HeaderMap>` for `http::HeaderMap`.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Prevent compression of zero-sized response bodies.
|
||||
- Do not encode zero-sized response bodies
|
||||
|
||||
## 3.4.0
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-http"
|
||||
version = "3.6.0"
|
||||
version = "3.4.0"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
@ -20,18 +20,8 @@ edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
features = [
|
||||
"http2",
|
||||
"ws",
|
||||
"openssl",
|
||||
"rustls-0_20",
|
||||
"rustls-0_21",
|
||||
"rustls-0_22",
|
||||
"compress-brotli",
|
||||
"compress-gzip",
|
||||
"compress-zstd",
|
||||
]
|
||||
# features that docs.rs will build with
|
||||
features = ["http2", "ws", "openssl", "rustls-0_20", "rustls-0_21", "compress-brotli", "compress-gzip", "compress-zstd"]
|
||||
|
||||
[lib]
|
||||
name = "actix_http"
|
||||
@ -63,9 +53,6 @@ rustls-0_20 = ["actix-tls/accept", "actix-tls/rustls-0_20"]
|
||||
# TLS via Rustls v0.21
|
||||
rustls-0_21 = ["actix-tls/accept", "actix-tls/rustls-0_21"]
|
||||
|
||||
# TLS via Rustls v0.22
|
||||
rustls-0_22 = ["actix-tls/accept", "actix-tls/rustls-0_22"]
|
||||
|
||||
# Compression codecs
|
||||
compress-brotli = ["__compress", "brotli"]
|
||||
compress-gzip = ["__compress", "flate2"]
|
||||
@ -102,7 +89,7 @@ tokio-util = { version = "0.7", features = ["io", "codec"] }
|
||||
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||
|
||||
# http2
|
||||
h2 = { version = "0.3.24", optional = true }
|
||||
h2 = { version = "0.3.17", optional = true }
|
||||
|
||||
# websockets
|
||||
local-channel = { version = "0.1", optional = true }
|
||||
@ -111,7 +98,7 @@ rand = { version = "0.8", optional = true }
|
||||
sha1 = { version = "0.10", optional = true }
|
||||
|
||||
# openssl/rustls
|
||||
actix-tls = { version = "3.3", default-features = false, optional = true }
|
||||
actix-tls = { version = "3.1", default-features = false, optional = true }
|
||||
|
||||
# compress-*
|
||||
brotli = { version = "3.3.3", optional = true }
|
||||
@ -121,7 +108,7 @@ zstd = { version = "0.13", optional = true }
|
||||
[dev-dependencies]
|
||||
actix-http-test = { version = "3", features = ["openssl"] }
|
||||
actix-server = "2"
|
||||
actix-tls = { version = "3.3", features = ["openssl", "rustls-0_22-webpki-roots"] }
|
||||
actix-tls = { version = "3.1", features = ["openssl"] }
|
||||
actix-web = "4"
|
||||
|
||||
async-stream = "0.3"
|
||||
@ -130,24 +117,24 @@ env_logger = "0.10"
|
||||
futures-util = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||
memchr = "2.4"
|
||||
once_cell = "1.9"
|
||||
rcgen = "0.12"
|
||||
rcgen = "0.11"
|
||||
regex = "1.3"
|
||||
rustversion = "1"
|
||||
rustls-pemfile = "2"
|
||||
rustls-pemfile = "1"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
static_assertions = "1"
|
||||
tls-openssl = { package = "openssl", version = "0.10.55" }
|
||||
tls-rustls_022 = { package = "rustls", version = "0.22" }
|
||||
tls-rustls_021 = { package = "rustls", version = "0.21" }
|
||||
tokio = { version = "1.24.2", features = ["net", "rt", "macros"] }
|
||||
|
||||
[[example]]
|
||||
name = "ws"
|
||||
required-features = ["ws", "rustls-0_22"]
|
||||
required-features = ["ws", "rustls-0_21"]
|
||||
|
||||
[[example]]
|
||||
name = "tls_rustls"
|
||||
required-features = ["http2", "rustls-0_22"]
|
||||
required-features = ["http2", "rustls-0_21"]
|
||||
|
||||
[[bench]]
|
||||
name = "response-body-compression"
|
||||
|
@ -5,11 +5,11 @@
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-http)
|
||||
[](https://docs.rs/actix-http/3.6.0)
|
||||
[](https://docs.rs/actix-http/3.4.0)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-http/3.6.0)
|
||||
[](https://deps.rs/crate/actix-http/3.4.0)
|
||||
[](https://crates.io/crates/actix-http)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
//! Protocol: HTTP/1.1
|
||||
//! ```
|
||||
|
||||
extern crate tls_rustls_022 as rustls;
|
||||
extern crate tls_rustls_021 as rustls;
|
||||
|
||||
use std::io;
|
||||
|
||||
@ -36,7 +36,7 @@ async fn main() -> io::Result<()> {
|
||||
);
|
||||
ok::<_, Error>(Response::ok().set_body(body))
|
||||
})
|
||||
.rustls_0_22(rustls_config())
|
||||
.rustls_021(rustls_config())
|
||||
})?
|
||||
.run()
|
||||
.await
|
||||
@ -51,18 +51,16 @@ fn rustls_config() -> rustls::ServerConfig {
|
||||
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();
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(rustls::Certificate)
|
||||
.collect();
|
||||
let mut keys = rustls_pemfile::pkcs8_private_keys(key_file).unwrap();
|
||||
|
||||
let mut config = rustls::ServerConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(
|
||||
cert_chain,
|
||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
||||
)
|
||||
.with_single_cert(cert_chain, rustls::PrivateKey(keys.remove(0)))
|
||||
.unwrap();
|
||||
|
||||
const H1_ALPN: &[u8] = b"http/1.1";
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Sets up a WebSocket server over TCP and TLS.
|
||||
//! Sends a heartbeat message every 4 seconds but does not respond to any incoming frames.
|
||||
|
||||
extern crate tls_rustls_022 as rustls;
|
||||
extern crate tls_rustls_021 as rustls;
|
||||
|
||||
use std::{
|
||||
io,
|
||||
@ -30,7 +30,7 @@ async fn main() -> io::Result<()> {
|
||||
.bind("tls", ("127.0.0.1", 8443), || {
|
||||
HttpService::build()
|
||||
.finish(handler)
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})?
|
||||
.run()
|
||||
.await
|
||||
@ -85,6 +85,7 @@ impl Stream for Heartbeat {
|
||||
fn tls_config() -> rustls::ServerConfig {
|
||||
use std::io::BufReader;
|
||||
|
||||
use rustls::{Certificate, PrivateKey};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
|
||||
let cert = rcgen::generate_simple_self_signed(vec!["localhost".to_owned()]).unwrap();
|
||||
@ -94,17 +95,17 @@ fn tls_config() -> rustls::ServerConfig {
|
||||
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 = certs(cert_file)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(Certificate)
|
||||
.collect();
|
||||
let mut keys = pkcs8_private_keys(key_file).unwrap();
|
||||
|
||||
let mut config = rustls::ServerConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(
|
||||
cert_chain,
|
||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
||||
)
|
||||
.with_single_cert(cert_chain, PrivateKey(keys.remove(0)))
|
||||
.unwrap();
|
||||
|
||||
config.alpn_protocols.push(b"http/1.1".to_vec());
|
||||
|
@ -50,21 +50,10 @@ impl<B: MessageBody> Encoder<B> {
|
||||
}
|
||||
}
|
||||
|
||||
fn empty() -> Self {
|
||||
Encoder {
|
||||
body: EncoderBody::Full { body: Bytes::new() },
|
||||
encoder: None,
|
||||
fut: None,
|
||||
eof: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn response(encoding: ContentEncoding, head: &mut ResponseHead, body: B) -> Self {
|
||||
// no need to compress empty bodies
|
||||
match body.size() {
|
||||
BodySize::None => return Self::none(),
|
||||
BodySize::Sized(0) => return Self::empty(),
|
||||
_ => {}
|
||||
// no need to compress an empty body
|
||||
if matches!(body.size(), BodySize::None | BodySize::Sized(0)) {
|
||||
return Self::none();
|
||||
}
|
||||
|
||||
let should_encode = !(head.headers().contains_key(&CONTENT_ENCODING)
|
||||
|
@ -153,7 +153,7 @@ mod openssl {
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_20")]
|
||||
mod rustls_0_20 {
|
||||
mod rustls_020 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
@ -214,7 +214,7 @@ mod rustls_0_20 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
mod rustls_0_21 {
|
||||
mod rustls_021 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
@ -274,67 +274,6 @@ mod rustls_0_21 {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
mod rustls_0_22 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
use actix_tls::accept::{
|
||||
rustls_0_22::{reexports::ServerConfig, Acceptor, TlsStream},
|
||||
TlsError,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
impl<S, B, X, U> H1Service<TlsStream<TcpStream>, S, B, X, U>
|
||||
where
|
||||
S: ServiceFactory<Request, Config = ()>,
|
||||
S::Future: 'static,
|
||||
S::Error: Into<Response<BoxBody>>,
|
||||
S::InitError: fmt::Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
|
||||
B: MessageBody,
|
||||
|
||||
X: ServiceFactory<Request, Config = (), Response = Request>,
|
||||
X::Future: 'static,
|
||||
X::Error: Into<Response<BoxBody>>,
|
||||
X::InitError: fmt::Debug,
|
||||
|
||||
U: ServiceFactory<
|
||||
(Request, Framed<TlsStream<TcpStream>, Codec>),
|
||||
Config = (),
|
||||
Response = (),
|
||||
>,
|
||||
U::Future: 'static,
|
||||
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
||||
U::InitError: fmt::Debug,
|
||||
{
|
||||
/// Create Rustls v0.22 based service.
|
||||
pub fn rustls_0_22(
|
||||
self,
|
||||
config: ServerConfig,
|
||||
) -> impl ServiceFactory<
|
||||
TcpStream,
|
||||
Config = (),
|
||||
Response = (),
|
||||
Error = TlsError<io::Error, DispatchError>,
|
||||
InitError = (),
|
||||
> {
|
||||
Acceptor::new(config)
|
||||
.map_init_err(|_| {
|
||||
unreachable!("TLS acceptor service factory does not error on init")
|
||||
})
|
||||
.map_err(TlsError::into_service_error)
|
||||
.map(|io: TlsStream<TcpStream>| {
|
||||
let peer_addr = io.get_ref().0.peer_addr().ok();
|
||||
(io, peer_addr)
|
||||
})
|
||||
.and_then(self.map_err(TlsError::Service))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B, X, U> H1Service<T, S, B, X, U>
|
||||
where
|
||||
S: ServiceFactory<Request, Config = ()>,
|
||||
|
@ -141,7 +141,7 @@ mod openssl {
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_20")]
|
||||
mod rustls_0_20 {
|
||||
mod rustls_020 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
@ -192,7 +192,7 @@ mod rustls_0_20 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
mod rustls_0_21 {
|
||||
mod rustls_021 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
@ -242,57 +242,6 @@ mod rustls_0_21 {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
mod rustls_0_22 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
use actix_tls::accept::{
|
||||
rustls_0_22::{reexports::ServerConfig, Acceptor, TlsStream},
|
||||
TlsError,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
impl<S, B> H2Service<TlsStream<TcpStream>, S, B>
|
||||
where
|
||||
S: ServiceFactory<Request, Config = ()>,
|
||||
S::Future: 'static,
|
||||
S::Error: Into<Response<BoxBody>> + 'static,
|
||||
S::Response: Into<Response<B>> + 'static,
|
||||
<S::Service as Service<Request>>::Future: 'static,
|
||||
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
/// Create Rustls v0.22 based service.
|
||||
pub fn rustls_0_22(
|
||||
self,
|
||||
mut config: ServerConfig,
|
||||
) -> impl ServiceFactory<
|
||||
TcpStream,
|
||||
Config = (),
|
||||
Response = (),
|
||||
Error = TlsError<io::Error, DispatchError>,
|
||||
InitError = S::InitError,
|
||||
> {
|
||||
let mut protos = vec![b"h2".to_vec()];
|
||||
protos.extend_from_slice(&config.alpn_protocols);
|
||||
config.alpn_protocols = protos;
|
||||
|
||||
Acceptor::new(config)
|
||||
.map_init_err(|_| {
|
||||
unreachable!("TLS acceptor service factory does not error on init")
|
||||
})
|
||||
.map_err(TlsError::into_service_error)
|
||||
.map(|io: TlsStream<TcpStream>| {
|
||||
let peer_addr = io.get_ref().0.peer_addr().ok();
|
||||
(io, peer_addr)
|
||||
})
|
||||
.and_then(self.map_err(TlsError::Service))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> ServiceFactory<(T, Option<net::SocketAddr>)> for H2Service<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + Unpin + 'static,
|
||||
|
@ -650,13 +650,6 @@ impl From<HeaderMap> for http::HeaderMap {
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert our `&HeaderMap` to a `http::HeaderMap`.
|
||||
impl From<&HeaderMap> for http::HeaderMap {
|
||||
fn from(map: &HeaderMap) -> Self {
|
||||
map.to_owned().into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator over removed, owned values with the same associated name.
|
||||
///
|
||||
/// Returned from methods that remove or replace items. See [`HeaderMap::insert`]
|
||||
|
@ -58,12 +58,7 @@ pub mod ws;
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub use self::payload::PayloadStream;
|
||||
#[cfg(any(
|
||||
feature = "openssl",
|
||||
feature = "rustls-0_20",
|
||||
feature = "rustls-0_21",
|
||||
feature = "rustls-0_22",
|
||||
))]
|
||||
#[cfg(any(feature = "openssl", feature = "rustls-0_20", feature = "rustls-0_21"))]
|
||||
pub use self::service::TlsAcceptorConfig;
|
||||
pub use self::{
|
||||
builder::HttpServiceBuilder,
|
||||
|
@ -16,10 +16,7 @@ pub struct RequestHead {
|
||||
pub uri: Uri,
|
||||
pub version: Version,
|
||||
pub headers: HeaderMap,
|
||||
|
||||
/// Will only be None when called in unit tests unless set manually.
|
||||
pub peer_addr: Option<net::SocketAddr>,
|
||||
|
||||
flags: Flags,
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ impl<P> Request<P> {
|
||||
/// Peer address is the directly connected peer's socket address. If a proxy is used in front of
|
||||
/// the Actix Web server, then it would be address of this proxy.
|
||||
///
|
||||
/// Will only return None when called in unit tests unless set manually.
|
||||
/// Will only return None when called in unit tests.
|
||||
#[inline]
|
||||
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
|
||||
self.head().peer_addr
|
||||
|
@ -241,23 +241,13 @@ where
|
||||
}
|
||||
|
||||
/// Configuration options used when accepting TLS connection.
|
||||
#[cfg(any(
|
||||
feature = "openssl",
|
||||
feature = "rustls-0_20",
|
||||
feature = "rustls-0_21",
|
||||
feature = "rustls-0_22",
|
||||
))]
|
||||
#[cfg(any(feature = "openssl", feature = "rustls-0_20", feature = "rustls-0_21"))]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct TlsAcceptorConfig {
|
||||
pub(crate) handshake_timeout: Option<std::time::Duration>,
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
feature = "openssl",
|
||||
feature = "rustls-0_20",
|
||||
feature = "rustls-0_21",
|
||||
feature = "rustls-0_22",
|
||||
))]
|
||||
#[cfg(any(feature = "openssl", feature = "rustls-0_20", feature = "rustls-0_21"))]
|
||||
impl TlsAcceptorConfig {
|
||||
/// Set TLS handshake timeout duration.
|
||||
pub fn handshake_timeout(self, dur: std::time::Duration) -> Self {
|
||||
@ -363,12 +353,12 @@ mod openssl {
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_20")]
|
||||
mod rustls_0_20 {
|
||||
mod rustls_020 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
use actix_tls::accept::{
|
||||
rustls_0_20::{reexports::ServerConfig, Acceptor, TlsStream},
|
||||
rustls::{reexports::ServerConfig, Acceptor, TlsStream},
|
||||
TlsError,
|
||||
};
|
||||
|
||||
@ -399,7 +389,7 @@ mod rustls_0_20 {
|
||||
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
||||
U::InitError: fmt::Debug,
|
||||
{
|
||||
/// Create Rustls v0.20 based service.
|
||||
/// Create Rustls based service.
|
||||
pub fn rustls(
|
||||
self,
|
||||
config: ServerConfig,
|
||||
@ -413,7 +403,7 @@ mod rustls_0_20 {
|
||||
self.rustls_with_config(config, TlsAcceptorConfig::default())
|
||||
}
|
||||
|
||||
/// Create Rustls v0.20 based service with custom TLS acceptor configuration.
|
||||
/// Create Rustls based service with custom TLS acceptor configuration.
|
||||
pub fn rustls_with_config(
|
||||
self,
|
||||
mut config: ServerConfig,
|
||||
@ -459,7 +449,7 @@ mod rustls_0_20 {
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
mod rustls_0_21 {
|
||||
mod rustls_021 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
@ -495,7 +485,7 @@ mod rustls_0_21 {
|
||||
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
||||
U::InitError: fmt::Debug,
|
||||
{
|
||||
/// Create Rustls v0.21 based service.
|
||||
/// Create Rustls based service.
|
||||
pub fn rustls_021(
|
||||
self,
|
||||
config: ServerConfig,
|
||||
@ -509,7 +499,7 @@ mod rustls_0_21 {
|
||||
self.rustls_021_with_config(config, TlsAcceptorConfig::default())
|
||||
}
|
||||
|
||||
/// Create Rustls v0.21 based service with custom TLS acceptor configuration.
|
||||
/// Create Rustls based service with custom TLS acceptor configuration.
|
||||
pub fn rustls_021_with_config(
|
||||
self,
|
||||
mut config: ServerConfig,
|
||||
@ -554,102 +544,6 @@ mod rustls_0_21 {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
mod rustls_0_22 {
|
||||
use std::io;
|
||||
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
use actix_tls::accept::{
|
||||
rustls_0_22::{reexports::ServerConfig, Acceptor, TlsStream},
|
||||
TlsError,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
impl<S, B, X, U> HttpService<TlsStream<TcpStream>, S, B, X, U>
|
||||
where
|
||||
S: ServiceFactory<Request, Config = ()>,
|
||||
S::Future: 'static,
|
||||
S::Error: Into<Response<BoxBody>> + 'static,
|
||||
S::InitError: fmt::Debug,
|
||||
S::Response: Into<Response<B>> + 'static,
|
||||
<S::Service as Service<Request>>::Future: 'static,
|
||||
|
||||
B: MessageBody + 'static,
|
||||
|
||||
X: ServiceFactory<Request, Config = (), Response = Request>,
|
||||
X::Future: 'static,
|
||||
X::Error: Into<Response<BoxBody>>,
|
||||
X::InitError: fmt::Debug,
|
||||
|
||||
U: ServiceFactory<
|
||||
(Request, Framed<TlsStream<TcpStream>, h1::Codec>),
|
||||
Config = (),
|
||||
Response = (),
|
||||
>,
|
||||
U::Future: 'static,
|
||||
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
||||
U::InitError: fmt::Debug,
|
||||
{
|
||||
/// Create Rustls v0.22 based service.
|
||||
pub fn rustls_0_22(
|
||||
self,
|
||||
config: ServerConfig,
|
||||
) -> impl ServiceFactory<
|
||||
TcpStream,
|
||||
Config = (),
|
||||
Response = (),
|
||||
Error = TlsError<io::Error, DispatchError>,
|
||||
InitError = (),
|
||||
> {
|
||||
self.rustls_0_22_with_config(config, TlsAcceptorConfig::default())
|
||||
}
|
||||
|
||||
/// Create Rustls v0.22 based service with custom TLS acceptor configuration.
|
||||
pub fn rustls_0_22_with_config(
|
||||
self,
|
||||
mut config: ServerConfig,
|
||||
tls_acceptor_config: TlsAcceptorConfig,
|
||||
) -> impl ServiceFactory<
|
||||
TcpStream,
|
||||
Config = (),
|
||||
Response = (),
|
||||
Error = TlsError<io::Error, DispatchError>,
|
||||
InitError = (),
|
||||
> {
|
||||
let mut protos = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
|
||||
protos.extend_from_slice(&config.alpn_protocols);
|
||||
config.alpn_protocols = protos;
|
||||
|
||||
let mut acceptor = Acceptor::new(config);
|
||||
|
||||
if let Some(handshake_timeout) = tls_acceptor_config.handshake_timeout {
|
||||
acceptor.set_handshake_timeout(handshake_timeout);
|
||||
}
|
||||
|
||||
acceptor
|
||||
.map_init_err(|_| {
|
||||
unreachable!("TLS acceptor service factory does not error on init")
|
||||
})
|
||||
.map_err(TlsError::into_service_error)
|
||||
.and_then(|io: TlsStream<TcpStream>| async {
|
||||
let proto = if let Some(protos) = io.get_ref().1.alpn_protocol() {
|
||||
if protos.windows(2).any(|window| window == b"h2") {
|
||||
Protocol::Http2
|
||||
} else {
|
||||
Protocol::Http1
|
||||
}
|
||||
} else {
|
||||
Protocol::Http1
|
||||
};
|
||||
let peer_addr = io.get_ref().0.peer_addr().ok();
|
||||
Ok((io, proto, peer_addr))
|
||||
})
|
||||
.and_then(self.map_err(TlsError::Service))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B, X, U> ServiceFactory<(T, Protocol, Option<net::SocketAddr>)>
|
||||
for HttpService<T, S, B, X, U>
|
||||
where
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![cfg(feature = "rustls-0_22")]
|
||||
#![cfg(feature = "rustls-0_21")]
|
||||
|
||||
extern crate tls_rustls_022 as rustls;
|
||||
extern crate tls_rustls_021 as rustls;
|
||||
|
||||
use std::{
|
||||
convert::Infallible,
|
||||
@ -20,13 +20,13 @@ use actix_http::{
|
||||
use actix_http_test::test_server;
|
||||
use actix_rt::pin;
|
||||
use actix_service::{fn_factory_with_config, fn_service};
|
||||
use actix_tls::connect::rustls_0_22::webpki_roots_cert_store;
|
||||
use actix_tls::connect::rustls_0_21::webpki_roots_cert_store;
|
||||
use actix_utils::future::{err, ok, poll_fn};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
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::{Certificate, PrivateKey, ServerConfig as RustlsServerConfig, ServerName};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
|
||||
async fn load_body<S>(stream: S) -> Result<BytesMut, PayloadError>
|
||||
@ -59,17 +59,17 @@ fn tls_config() -> RustlsServerConfig {
|
||||
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 = certs(cert_file)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(Certificate)
|
||||
.collect();
|
||||
let mut keys = pkcs8_private_keys(key_file).unwrap();
|
||||
|
||||
let mut config = RustlsServerConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(
|
||||
cert_chain,
|
||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
||||
)
|
||||
.with_single_cert(cert_chain, PrivateKey(keys.remove(0)))
|
||||
.unwrap();
|
||||
|
||||
config.alpn_protocols.push(HTTP1_1_ALPN_PROTOCOL.to_vec());
|
||||
@ -83,6 +83,7 @@ pub fn get_negotiated_alpn_protocol(
|
||||
client_alpn_protocol: &[u8],
|
||||
) -> Option<Vec<u8>> {
|
||||
let mut config = rustls::ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(webpki_roots_cert_store())
|
||||
.with_no_client_auth();
|
||||
|
||||
@ -108,7 +109,7 @@ async fn h1() -> io::Result<()> {
|
||||
let srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h1(|_| ok::<_, Error>(Response::ok()))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -122,7 +123,7 @@ async fn h2() -> io::Result<()> {
|
||||
let srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h2(|_| ok::<_, Error>(Response::ok()))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -140,7 +141,7 @@ async fn h1_1() -> io::Result<()> {
|
||||
assert_eq!(req.version(), Version::HTTP_11);
|
||||
ok::<_, Error>(Response::ok())
|
||||
})
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -158,7 +159,7 @@ async fn h2_1() -> io::Result<()> {
|
||||
assert_eq!(req.version(), Version::HTTP_2);
|
||||
ok::<_, Error>(Response::ok())
|
||||
})
|
||||
.rustls_0_22_with_config(
|
||||
.rustls_021_with_config(
|
||||
tls_config(),
|
||||
TlsAcceptorConfig::default().handshake_timeout(Duration::from_secs(5)),
|
||||
)
|
||||
@ -179,7 +180,7 @@ async fn h2_body1() -> io::Result<()> {
|
||||
let body = load_body(req.take_payload()).await?;
|
||||
Ok::<_, Error>(Response::ok().set_body(body))
|
||||
})
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -205,7 +206,7 @@ async fn h2_content_length() {
|
||||
];
|
||||
ok::<_, Infallible>(Response::new(statuses[indx]))
|
||||
})
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -277,7 +278,7 @@ async fn h2_headers() {
|
||||
}
|
||||
ok::<_, Infallible>(config.body(data.clone()))
|
||||
})
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -316,7 +317,7 @@ async fn h2_body2() {
|
||||
let mut srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -333,7 +334,7 @@ async fn h2_head_empty() {
|
||||
let mut srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.finish(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -359,7 +360,7 @@ async fn h2_head_binary() {
|
||||
let mut srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -384,7 +385,7 @@ async fn h2_head_binary2() {
|
||||
let srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -410,7 +411,7 @@ async fn h2_body_length() {
|
||||
Response::ok().set_body(SizedStream::new(STR.len() as u64, body)),
|
||||
)
|
||||
})
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -434,7 +435,7 @@ async fn h2_body_chunked_explicit() {
|
||||
.body(BodyStream::new(body)),
|
||||
)
|
||||
})
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -463,7 +464,7 @@ async fn h2_response_http_error_handling() {
|
||||
)
|
||||
}))
|
||||
}))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -493,7 +494,7 @@ async fn h2_service_error() {
|
||||
let mut srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h2(|_| err::<Response<BoxBody>, _>(BadRequest))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -510,7 +511,7 @@ async fn h1_service_error() {
|
||||
let mut srv = test_server(move || {
|
||||
HttpService::build()
|
||||
.h1(|_| err::<Response<BoxBody>, _>(BadRequest))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -533,7 +534,7 @@ async fn alpn_h1() -> io::Result<()> {
|
||||
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
||||
HttpService::build()
|
||||
.h1(|_| ok::<_, Error>(Response::ok()))
|
||||
.rustls_0_22(config)
|
||||
.rustls_021(config)
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -555,7 +556,7 @@ async fn alpn_h2() -> io::Result<()> {
|
||||
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
||||
HttpService::build()
|
||||
.h2(|_| ok::<_, Error>(Response::ok()))
|
||||
.rustls_0_22(config)
|
||||
.rustls_021(config)
|
||||
})
|
||||
.await;
|
||||
|
||||
@ -581,7 +582,7 @@ async fn alpn_h2_1() -> io::Result<()> {
|
||||
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
|
||||
HttpService::build()
|
||||
.finish(|_| ok::<_, Error>(Response::ok()))
|
||||
.rustls_0_22(config)
|
||||
.rustls_021(config)
|
||||
})
|
||||
.await;
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
# `actix-multipart-derive`
|
||||
# actix-multipart-derive
|
||||
|
||||
> The derive macro implementation for actix-multipart-derive.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-multipart-derive)
|
||||
[](https://docs.rs/actix-multipart-derive/0.6.1)
|
||||

|
||||
@ -13,8 +11,6 @@
|
||||
[](https://crates.io/crates/actix-multipart-derive)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-multipart-derive)
|
||||
|
@ -1,9 +1,7 @@
|
||||
# `actix-multipart`
|
||||
# actix-multipart
|
||||
|
||||
> Multipart form support for Actix Web.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-multipart)
|
||||
[](https://docs.rs/actix-multipart/0.6.1)
|
||||

|
||||
@ -13,8 +11,6 @@
|
||||
[](https://crates.io/crates/actix-multipart)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-multipart)
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 0.5.2
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||
|
||||
## 0.5.1
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-router"
|
||||
version = "0.5.2"
|
||||
version = "0.5.1"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com>",
|
||||
|
@ -1,18 +1,14 @@
|
||||
# `actix-router`
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-router)
|
||||
[](https://docs.rs/actix-router/0.5.2)
|
||||
[](https://docs.rs/actix-router/0.5.1)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-router/0.5.2)
|
||||
[](https://deps.rs/crate/actix-router/0.5.1)
|
||||
[](https://crates.io/crates/actix-router)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
<!-- cargo-rdme start -->
|
||||
|
||||
Resource path matching and router.
|
||||
|
@ -2,10 +2,6 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 0.1.3
|
||||
|
||||
- Add `TestServerConfig::rustls_0_22()` method for Rustls v0.22 support behind new `rustls-0_22` crate feature.
|
||||
|
||||
## 0.1.2
|
||||
|
||||
- Add `TestServerConfig::rustls_021()` method for Rustls v0.21 support behind new `rustls-0_21` crate feature.
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-test"
|
||||
version = "0.1.3"
|
||||
version = "0.1.2"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
"Rob Ede <robjtede@icloud.com>",
|
||||
@ -27,21 +27,19 @@ rustls = ["rustls-0_20"]
|
||||
rustls-0_20 = ["tls-rustls-0_20", "actix-http/rustls-0_20", "awc/rustls-0_20"]
|
||||
# TLS via Rustls v0.21
|
||||
rustls-0_21 = ["tls-rustls-0_21", "actix-http/rustls-0_21", "awc/rustls-0_21"]
|
||||
# TLS via Rustls v0.22
|
||||
rustls-0_22 = ["tls-rustls-0_22", "actix-http/rustls-0_22", "awc/rustls-0_22-webpki-roots"]
|
||||
|
||||
# TLS via OpenSSL
|
||||
openssl = ["tls-openssl", "actix-http/openssl", "awc/openssl"]
|
||||
|
||||
[dependencies]
|
||||
actix-codec = "0.5"
|
||||
actix-http = "3.6"
|
||||
actix-http = "3"
|
||||
actix-http-test = "3"
|
||||
actix-rt = "2.1"
|
||||
actix-service = "2"
|
||||
actix-utils = "3"
|
||||
actix-web = { version = "4.5", default-features = false, features = ["cookies"] }
|
||||
awc = { version = "3.4", default-features = false, features = ["cookies"] }
|
||||
actix-web = { version = "4", default-features = false, features = ["cookies"] }
|
||||
awc = { version = "3", default-features = false, features = ["cookies"] }
|
||||
|
||||
futures-core = { version = "0.3.17", default-features = false, features = ["std"] }
|
||||
futures-util = { version = "0.3.17", default-features = false, features = [] }
|
||||
@ -52,5 +50,4 @@ serde_urlencoded = "0.7"
|
||||
tls-openssl = { package = "openssl", version = "0.10.55", optional = true }
|
||||
tls-rustls-0_20 = { package = "rustls", version = "0.20", optional = true }
|
||||
tls-rustls-0_21 = { package = "rustls", version = "0.21", optional = true }
|
||||
tls-rustls-0_22 = { package = "rustls", version = "0.22", optional = true }
|
||||
tokio = { version = "1.24.2", features = ["sync"] }
|
||||
|
@ -143,8 +143,6 @@ where
|
||||
StreamType::Rustls020(_) => true,
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
StreamType::Rustls021(_) => true,
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
StreamType::Rustls022(_) => true,
|
||||
};
|
||||
|
||||
// run server in separate orphaned thread
|
||||
@ -329,48 +327,6 @@ where
|
||||
.rustls_021(config.clone())
|
||||
}),
|
||||
},
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
StreamType::Rustls022(config) => match cfg.tp {
|
||||
HttpVer::Http1 => builder.listen("test", tcp, move || {
|
||||
let app_cfg =
|
||||
AppConfig::__priv_test_new(false, local_addr.to_string(), local_addr);
|
||||
|
||||
let fac = factory()
|
||||
.into_factory()
|
||||
.map_err(|err| err.into().error_response());
|
||||
|
||||
HttpService::build()
|
||||
.client_request_timeout(timeout)
|
||||
.h1(map_config(fac, move |_| app_cfg.clone()))
|
||||
.rustls_0_22(config.clone())
|
||||
}),
|
||||
HttpVer::Http2 => builder.listen("test", tcp, move || {
|
||||
let app_cfg =
|
||||
AppConfig::__priv_test_new(false, local_addr.to_string(), local_addr);
|
||||
|
||||
let fac = factory()
|
||||
.into_factory()
|
||||
.map_err(|err| err.into().error_response());
|
||||
|
||||
HttpService::build()
|
||||
.client_request_timeout(timeout)
|
||||
.h2(map_config(fac, move |_| app_cfg.clone()))
|
||||
.rustls_0_22(config.clone())
|
||||
}),
|
||||
HttpVer::Both => builder.listen("test", tcp, move || {
|
||||
let app_cfg =
|
||||
AppConfig::__priv_test_new(false, local_addr.to_string(), local_addr);
|
||||
|
||||
let fac = factory()
|
||||
.into_factory()
|
||||
.map_err(|err| err.into().error_response());
|
||||
|
||||
HttpService::build()
|
||||
.client_request_timeout(timeout)
|
||||
.finish(map_config(fac, move |_| app_cfg.clone()))
|
||||
.rustls_0_22(config.clone())
|
||||
}),
|
||||
},
|
||||
}
|
||||
.expect("test server could not be created");
|
||||
|
||||
@ -445,8 +401,6 @@ enum StreamType {
|
||||
Rustls020(tls_rustls_0_20::ServerConfig),
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
Rustls021(tls_rustls_0_21::ServerConfig),
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
Rustls022(tls_rustls_0_22::ServerConfig),
|
||||
}
|
||||
|
||||
/// Create default test server config.
|
||||
@ -470,7 +424,7 @@ impl Default for TestServerConfig {
|
||||
}
|
||||
|
||||
impl TestServerConfig {
|
||||
/// Constructs default server configuration.
|
||||
/// Create default server configuration
|
||||
pub(crate) fn new() -> TestServerConfig {
|
||||
TestServerConfig {
|
||||
tp: HttpVer::Both,
|
||||
@ -481,63 +435,40 @@ impl TestServerConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/// Accepts HTTP/1.1 only.
|
||||
/// Accept HTTP/1.1 only.
|
||||
pub fn h1(mut self) -> Self {
|
||||
self.tp = HttpVer::Http1;
|
||||
self
|
||||
}
|
||||
|
||||
/// Accepts HTTP/2 only.
|
||||
/// Accept HTTP/2 only.
|
||||
pub fn h2(mut self) -> Self {
|
||||
self.tp = HttpVer::Http2;
|
||||
self
|
||||
}
|
||||
|
||||
/// Accepts secure connections via OpenSSL.
|
||||
/// Accept secure connections via OpenSSL.
|
||||
#[cfg(feature = "openssl")]
|
||||
pub fn openssl(mut self, acceptor: openssl::ssl::SslAcceptor) -> Self {
|
||||
self.stream = StreamType::Openssl(acceptor);
|
||||
self
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[deprecated(note = "Renamed to `rustls_0_20()`.")]
|
||||
/// Accept secure connections via Rustls.
|
||||
#[cfg(feature = "rustls-0_20")]
|
||||
pub fn rustls(mut self, config: tls_rustls_0_20::ServerConfig) -> Self {
|
||||
self.stream = StreamType::Rustls020(config);
|
||||
self
|
||||
}
|
||||
|
||||
/// Accepts secure connections via Rustls v0.20.
|
||||
#[cfg(feature = "rustls-0_20")]
|
||||
pub fn rustls_0_20(mut self, config: tls_rustls_0_20::ServerConfig) -> Self {
|
||||
self.stream = StreamType::Rustls020(config);
|
||||
self
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[deprecated(note = "Renamed to `rustls_0_21()`.")]
|
||||
/// Accept secure connections via Rustls.
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
pub fn rustls_021(mut self, config: tls_rustls_0_21::ServerConfig) -> Self {
|
||||
self.stream = StreamType::Rustls021(config);
|
||||
self
|
||||
}
|
||||
|
||||
/// Accepts secure connections via Rustls v0.21.
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
pub fn rustls_0_21(mut self, config: tls_rustls_0_21::ServerConfig) -> Self {
|
||||
self.stream = StreamType::Rustls021(config);
|
||||
self
|
||||
}
|
||||
|
||||
/// Accepts secure connections via Rustls v0.22.
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
pub fn rustls_0_22(mut self, config: tls_rustls_0_22::ServerConfig) -> Self {
|
||||
self.stream = StreamType::Rustls022(config);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets client timeout for first request.
|
||||
/// Set client timeout for first request.
|
||||
pub fn client_request_timeout(mut self, dur: Duration) -> Self {
|
||||
self.client_request_timeout = dur;
|
||||
self
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 4.3.0
|
||||
|
||||
- Minimum supported Rust version (MSRV) is now 1.68 due to transitive `time` dependency.
|
||||
|
||||
## 4.2.0
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-web-actors"
|
||||
version = "4.3.0"
|
||||
version = "4.2.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Actix actors support for Actix Web"
|
||||
keywords = ["actix", "http", "web", "framework", "async"]
|
||||
|
@ -1,20 +1,16 @@
|
||||
# `actix-web-actors`
|
||||
# actix-web-actors
|
||||
|
||||
> Actix actors support for Actix Web.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web-actors)
|
||||
[](https://docs.rs/actix-web-actors/4.3.0)
|
||||
[](https://docs.rs/actix-web-actors/4.2.0)
|
||||

|
||||

|
||||
<br />
|
||||
[](https://deps.rs/crate/actix-web-actors/4.3.0)
|
||||
[](https://deps.rs/crate/actix-web-actors/4.2.0)
|
||||
[](https://crates.io/crates/actix-web-actors)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-web-actors)
|
||||
|
@ -1,9 +1,7 @@
|
||||
# `actix-web-codegen`
|
||||
# actix-web-codegen
|
||||
|
||||
> Routing and runtime macros for Actix Web.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web-codegen)
|
||||
[](https://docs.rs/actix-web-codegen/4.2.2)
|
||||

|
||||
@ -13,8 +11,6 @@
|
||||
[](https://crates.io/crates/actix-web-codegen)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/actix-web-codegen)
|
||||
|
@ -2,21 +2,6 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 4.5.1
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix missing import when using enabling Rustls v0.22 support.
|
||||
|
||||
## 4.5.0
|
||||
|
||||
### Added
|
||||
|
||||
- Add `rustls-0_22` crate feature.
|
||||
- Add `HttpServer::{bind_rustls_0_22, listen_rustls_0_22}()` builder methods.
|
||||
|
||||
## 4.4.1
|
||||
|
||||
### Changed
|
||||
|
||||
- Updated `zstd` dependency to `0.13`.
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "actix-web"
|
||||
version = "4.5.1"
|
||||
version = "4.4.0"
|
||||
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
||||
authors = [
|
||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||
@ -20,20 +20,9 @@ edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
# features that docs.rs will build with
|
||||
features = ["macros", "openssl", "rustls-0_20", "rustls-0_21", "compress-brotli", "compress-gzip", "compress-zstd", "cookies", "secure-cookies"]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
features = [
|
||||
"macros",
|
||||
"openssl",
|
||||
"rustls-0_20",
|
||||
"rustls-0_21",
|
||||
"rustls-0_22",
|
||||
"compress-brotli",
|
||||
"compress-gzip",
|
||||
"compress-zstd",
|
||||
"cookies",
|
||||
"secure-cookies",
|
||||
]
|
||||
|
||||
|
||||
[lib]
|
||||
name = "actix_web"
|
||||
@ -69,8 +58,6 @@ rustls = ["rustls-0_20"]
|
||||
rustls-0_20 = ["http2", "actix-http/rustls-0_20", "actix-tls/accept", "actix-tls/rustls-0_20"]
|
||||
# TLS via Rustls v0.21
|
||||
rustls-0_21 = ["http2", "actix-http/rustls-0_21", "actix-tls/accept", "actix-tls/rustls-0_21"]
|
||||
# TLS via Rustls v0.22
|
||||
rustls-0_22 = ["http2", "actix-http/rustls-0_22", "actix-tls/accept", "actix-tls/rustls-0_22"]
|
||||
|
||||
# Internal (PRIVATE!) features used to aid testing and checking feature status.
|
||||
# Don't rely on these whatsoever. They may disappear at anytime.
|
||||
@ -86,9 +73,9 @@ actix-rt = { version = "2.6", default-features = false }
|
||||
actix-server = "2"
|
||||
actix-service = "2"
|
||||
actix-utils = "3"
|
||||
actix-tls = { version = "3.3", default-features = false, optional = true }
|
||||
actix-tls = { version = "3.1", default-features = false, optional = true }
|
||||
|
||||
actix-http = { version = "3.6", features = ["ws"] }
|
||||
actix-http = { version = "3.4", features = ["ws"] }
|
||||
actix-router = "0.5"
|
||||
actix-web-codegen = { version = "4.2", optional = true }
|
||||
|
||||
@ -113,6 +100,7 @@ serde_json = "1.0"
|
||||
serde_urlencoded = "0.7"
|
||||
smallvec = "1.6.1"
|
||||
socket2 = "0.5"
|
||||
tokio = { version = "1.24.2", features = ["macros"] }
|
||||
time = { version = "0.3", default-features = false, features = ["formatting"] }
|
||||
url = "2.1"
|
||||
|
||||
|
@ -372,13 +372,13 @@ You may need to review the [guidance on shared mutable state](https://docs.rs/ac
|
||||
HttpServer::new(|| {
|
||||
- App::new()
|
||||
- .data(MyState::default())
|
||||
- .service(handler)
|
||||
- .service(hander)
|
||||
|
||||
+ let my_state: Data<MyState> = Data::new(MyState::default());
|
||||
+
|
||||
+ App::new()
|
||||
+ .app_data(my_state)
|
||||
+ .service(handler)
|
||||
+ .service(hander)
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -8,10 +8,10 @@
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web)
|
||||
[](https://docs.rs/actix-web/4.5.1)
|
||||
[](https://docs.rs/actix-web/4.4.0)
|
||||

|
||||

|
||||
[](https://deps.rs/crate/actix-web/4.5.1)
|
||||
[](https://deps.rs/crate/actix-web/4.4.0)
|
||||
<br />
|
||||
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
||||
[](https://codecov.io/gh/actix/actix-web)
|
||||
|
@ -129,8 +129,6 @@ where
|
||||
///
|
||||
/// Data items are constructed during application initialization, before the server starts
|
||||
/// accepting requests.
|
||||
///
|
||||
/// The returned data value `D` is wrapped as [`Data<D>`].
|
||||
pub fn data_factory<F, Out, D, E>(mut self, data: F) -> Self
|
||||
where
|
||||
F: Fn() -> Out + 'static,
|
||||
|
@ -1,7 +1,6 @@
|
||||
use std::{any::type_name, ops::Deref, sync::Arc};
|
||||
|
||||
use actix_http::Extensions;
|
||||
use actix_utils::future::{err, ok, Ready};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use serde::{de, Serialize};
|
||||
|
||||
@ -69,7 +68,7 @@ pub(crate) type FnDataFactory =
|
||||
/// HttpResponse::Ok()
|
||||
/// }
|
||||
///
|
||||
/// /// Alternatively, use the `HttpRequest::app_data` method to access data in a handler.
|
||||
/// /// Alteratively, use the `HttpRequest::app_data` method to access data in a handler.
|
||||
/// async fn index_alt(req: HttpRequest) -> impl Responder {
|
||||
/// let data = req.app_data::<Data<Mutex<MyData>>>().unwrap();
|
||||
/// let mut my_data = data.lock().unwrap();
|
||||
@ -159,12 +158,11 @@ where
|
||||
|
||||
impl<T: ?Sized + 'static> FromRequest for Data<T> {
|
||||
type Error = Error;
|
||||
type Future = Ready<Result<Self, Error>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
if let Some(st) = req.app_data::<Data<T>>() {
|
||||
ok(st.clone())
|
||||
Ok(st.clone())
|
||||
} else {
|
||||
log::debug!(
|
||||
"Failed to extract `Data<{}>` for `{}` handler. For the Data extractor to work \
|
||||
@ -174,7 +172,7 @@ impl<T: ?Sized + 'static> FromRequest for Data<T> {
|
||||
req.match_name().unwrap_or_else(|| req.path())
|
||||
);
|
||||
|
||||
err(error::ErrorInternalServerError(
|
||||
Err(error::ErrorInternalServerError(
|
||||
"Requested application data is not configured correctly. \
|
||||
View/enable debug logs for more details.",
|
||||
))
|
||||
|
@ -3,13 +3,11 @@
|
||||
use std::{
|
||||
convert::Infallible,
|
||||
future::Future,
|
||||
marker::PhantomData,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
use actix_http::{Method, Uri};
|
||||
use actix_utils::future::{ok, Ready};
|
||||
use futures_core::ready;
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
@ -66,33 +64,17 @@ pub trait FromRequest: Sized {
|
||||
/// The associated error which can be returned.
|
||||
type Error: Into<Error>;
|
||||
|
||||
/// Future that resolves to a `Self`.
|
||||
///
|
||||
/// To use an async function or block, the futures must be boxed. The following snippet will be
|
||||
/// common when creating async/await extractors (that do not consume the body).
|
||||
///
|
||||
/// ```ignore
|
||||
/// type Future = Pin<Box<dyn Future<Output = Result<Self, Self::Error>>>>;
|
||||
/// // or
|
||||
/// type Future = futures_util::future::LocalBoxFuture<'static, Result<Self, Self::Error>>;
|
||||
///
|
||||
/// fn from_request(req: HttpRequest, ...) -> Self::Future {
|
||||
/// let req = req.clone();
|
||||
/// Box::pin(async move {
|
||||
/// ...
|
||||
/// })
|
||||
/// }
|
||||
/// ```
|
||||
type Future: Future<Output = Result<Self, Self::Error>>;
|
||||
|
||||
/// Create a `Self` from request parts asynchronously.
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future;
|
||||
/// Creates a `Self` from request parts asynchronously.
|
||||
fn from_request(
|
||||
req: &HttpRequest,
|
||||
payload: &mut Payload,
|
||||
) -> impl Future<Output = Result<Self, Self::Error>>;
|
||||
|
||||
/// Create a `Self` from request head asynchronously.
|
||||
///
|
||||
/// This method is short for `T::from_request(req, &mut Payload::None)`.
|
||||
fn extract(req: &HttpRequest) -> Self::Future {
|
||||
Self::from_request(req, &mut Payload::None)
|
||||
fn extract(req: &HttpRequest) -> impl Future<Output = Result<Self, Self::Error>> {
|
||||
async { Self::from_request(req, &mut Payload::None).await }
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,12 +128,19 @@ where
|
||||
T: FromRequest,
|
||||
{
|
||||
type Error = Infallible;
|
||||
type Future = FromRequestOptFuture<T::Future>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||
FromRequestOptFuture {
|
||||
fut: T::from_request(req, payload),
|
||||
async fn from_request(req: &HttpRequest, payload: &mut Payload) -> Result<Self, Self::Error> {
|
||||
match T::from_request(req, payload).await {
|
||||
Ok(t) => Ok(Some(t)),
|
||||
Err(err) => {
|
||||
log::debug!(
|
||||
"Error from `Option<{}>` extractor: {}",
|
||||
std::any::type_name::<T>(),
|
||||
err.into()
|
||||
);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,9 +192,11 @@ where
|
||||
///
|
||||
/// impl FromRequest for Thing {
|
||||
/// type Error = Error;
|
||||
/// type Future = Ready<Result<Thing, Error>>;
|
||||
///
|
||||
/// fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||
/// async fn from_request(
|
||||
/// req: &HttpRequest,
|
||||
/// payload: &mut dev::Payload,
|
||||
/// ) -> Result<Self, Self::Error> {
|
||||
/// if rand::random() {
|
||||
/// ok(Thing { name: "thingy".into() })
|
||||
/// } else {
|
||||
@ -232,36 +223,10 @@ where
|
||||
T::Error: Into<E>,
|
||||
{
|
||||
type Error = Infallible;
|
||||
type Future = FromRequestResFuture<T::Future, E>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||
FromRequestResFuture {
|
||||
fut: T::from_request(req, payload),
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
pub struct FromRequestResFuture<Fut, E> {
|
||||
#[pin]
|
||||
fut: Fut,
|
||||
_phantom: PhantomData<E>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<Fut, T, Ei, E> Future for FromRequestResFuture<Fut, E>
|
||||
where
|
||||
Fut: Future<Output = Result<T, Ei>>,
|
||||
Ei: Into<E>,
|
||||
{
|
||||
type Output = Result<Result<T, E>, Infallible>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.project();
|
||||
let res = ready!(this.fut.poll(cx));
|
||||
Poll::Ready(Ok(res.map_err(Into::into)))
|
||||
async fn from_request(req: &HttpRequest, payload: &mut Payload) -> Result<Self, Self::Error> {
|
||||
Ok(T::from_request(req, payload).await.map_err(Into::into))
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,10 +244,9 @@ where
|
||||
/// ```
|
||||
impl FromRequest for Uri {
|
||||
type Error = Infallible;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
ok(req.uri().clone())
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
Ok(req.uri().clone())
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,10 +264,9 @@ impl FromRequest for Uri {
|
||||
/// ```
|
||||
impl FromRequest for Method {
|
||||
type Error = Infallible;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
ok(req.method().clone())
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
Ok(req.method().clone())
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,88 +282,24 @@ mod tuple_from_req {
|
||||
impl<$($T: FromRequest + 'static),+> FromRequest for ($($T,)+)
|
||||
{
|
||||
type Error = Error;
|
||||
type Future = $fut<$($T),+>;
|
||||
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||
$fut {
|
||||
$(
|
||||
$T: ExtractFuture::Future {
|
||||
fut: $T::from_request(req, payload)
|
||||
},
|
||||
)+
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
pub struct $fut<$($T: FromRequest),+> {
|
||||
async fn from_request(req: &HttpRequest, payload: &mut Payload) -> Result<Self, Self::Error> {
|
||||
$(
|
||||
#[pin]
|
||||
$T: ExtractFuture<$T::Future, $T>,
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
impl<$($T: FromRequest),+> Future for $fut<$($T),+>
|
||||
{
|
||||
type Output = Result<($($T,)+), Error>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let mut this = self.project();
|
||||
|
||||
let mut ready = true;
|
||||
$(
|
||||
match this.$T.as_mut().project() {
|
||||
ExtractProj::Future { fut } => match fut.poll(cx) {
|
||||
Poll::Ready(Ok(output)) => {
|
||||
let _ = this.$T.as_mut().project_replace(ExtractFuture::Done { output });
|
||||
},
|
||||
Poll::Ready(Err(err)) => return Poll::Ready(Err(err.into())),
|
||||
Poll::Pending => ready = false,
|
||||
},
|
||||
ExtractProj::Done { .. } => {},
|
||||
ExtractProj::Empty => unreachable!("FromRequest polled after finished"),
|
||||
}
|
||||
let $T = $T::from_request(req, payload).await.map_err(Into::into)?;
|
||||
)+
|
||||
|
||||
if ready {
|
||||
Poll::Ready(Ok(
|
||||
($(
|
||||
match this.$T.project_replace(ExtractFuture::Empty) {
|
||||
ExtractReplaceProj::Done { output } => output,
|
||||
_ => unreachable!("FromRequest polled after finished"),
|
||||
},
|
||||
)+)
|
||||
))
|
||||
} else {
|
||||
Poll::Pending
|
||||
}
|
||||
Ok(($($T,)+))
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
#[project = ExtractProj]
|
||||
#[project_replace = ExtractReplaceProj]
|
||||
enum ExtractFuture<Fut, Res> {
|
||||
Future {
|
||||
#[pin]
|
||||
fut: Fut
|
||||
},
|
||||
Done {
|
||||
output: Res,
|
||||
},
|
||||
Empty
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRequest for () {
|
||||
type Error = Infallible;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
fn from_request(_: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
ok(())
|
||||
#[inline]
|
||||
async fn from_request(_: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ use crate::http::header::Accept;
|
||||
pub struct Acceptable {
|
||||
mime: mime::Mime,
|
||||
|
||||
/// Whether to match `*/*` mime type.
|
||||
/// Wether to match `*/*` mime type.
|
||||
///
|
||||
/// Defaults to false because it's not very useful otherwise.
|
||||
match_star_star: bool,
|
||||
|
@ -2,7 +2,7 @@ use actix_http::{header, uri::Uri, RequestHead};
|
||||
|
||||
use super::{Guard, GuardContext};
|
||||
|
||||
/// Creates a guard that matches requests targeting a specific host.
|
||||
/// Creates a guard that matches requests targetting a specific host.
|
||||
///
|
||||
/// # Matching Host
|
||||
/// This guard will:
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::{convert::Infallible, net::SocketAddr};
|
||||
|
||||
use actix_utils::future::{err, ok, Ready};
|
||||
use derive_more::{Display, Error};
|
||||
|
||||
use crate::{
|
||||
@ -198,10 +197,10 @@ impl ConnectionInfo {
|
||||
|
||||
impl FromRequest for ConnectionInfo {
|
||||
type Error = Infallible;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
ok(req.connection_info().clone())
|
||||
#[inline]
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
Ok(req.connection_info().clone())
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,14 +239,14 @@ impl ResponseError for MissingPeerAddr {}
|
||||
|
||||
impl FromRequest for PeerAddr {
|
||||
type Error = MissingPeerAddr;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
#[inline]
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
match req.peer_addr() {
|
||||
Some(addr) => ok(PeerAddr(addr)),
|
||||
Some(addr) => Ok(PeerAddr(addr)),
|
||||
None => {
|
||||
log::error!("Missing peer address.");
|
||||
err(MissingPeerAddr)
|
||||
Err(MissingPeerAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
cell::{Ref, RefCell, RefMut},
|
||||
convert::Infallible,
|
||||
fmt, net,
|
||||
rc::Rc,
|
||||
str,
|
||||
@ -7,7 +8,6 @@ use std::{
|
||||
|
||||
use actix_http::{Message, RequestHead};
|
||||
use actix_router::{Path, Url};
|
||||
use actix_utils::future::{ok, Ready};
|
||||
#[cfg(feature = "cookies")]
|
||||
use cookie::{Cookie, ParseError as CookieParseError};
|
||||
use smallvec::SmallVec;
|
||||
@ -20,7 +20,7 @@ use crate::{
|
||||
http::{header::HeaderMap, Method, Uri, Version},
|
||||
info::ConnectionInfo,
|
||||
rmap::ResourceMap,
|
||||
Error, FromRequest, HttpMessage,
|
||||
FromRequest, HttpMessage,
|
||||
};
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
@ -417,12 +417,11 @@ impl Drop for HttpRequest {
|
||||
/// );
|
||||
/// ```
|
||||
impl FromRequest for HttpRequest {
|
||||
type Error = Error;
|
||||
type Future = Ready<Result<Self, Error>>;
|
||||
type Error = Infallible;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
ok(req.clone())
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
Ok(req.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
use std::{any::type_name, ops::Deref};
|
||||
|
||||
use actix_utils::future::{err, ok, Ready};
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::{
|
||||
dev::Payload, error::ErrorInternalServerError, Error, FromRequest, HttpMessage as _,
|
||||
@ -66,19 +64,19 @@ impl<T: Clone + 'static> Deref for ReqData<T> {
|
||||
|
||||
impl<T: Clone + 'static> FromRequest for ReqData<T> {
|
||||
type Error = Error;
|
||||
type Future = Ready<Result<Self, Error>>;
|
||||
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
#[inline]
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
if let Some(st) = req.extensions().get::<T>() {
|
||||
ok(ReqData(st.clone()))
|
||||
Ok(ReqData(st.clone()))
|
||||
} else {
|
||||
log::debug!(
|
||||
"Failed to construct App-level ReqData extractor. \
|
||||
Request path: {:?} (type: {})",
|
||||
"Failed to extract App-level ReqData<{}>. Request path: {}",
|
||||
std::any::type_name::<T>(),
|
||||
req.path(),
|
||||
type_name::<T>(),
|
||||
);
|
||||
err(ErrorInternalServerError(
|
||||
|
||||
Err(ErrorInternalServerError(
|
||||
"Missing expected request extension data",
|
||||
))
|
||||
}
|
||||
|
@ -7,12 +7,7 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
#[cfg(any(
|
||||
feature = "openssl",
|
||||
feature = "rustls-0_20",
|
||||
feature = "rustls-0_21",
|
||||
feature = "rustls-0_22",
|
||||
))]
|
||||
#[cfg(any(feature = "openssl", feature = "rustls-0_20", feature = "rustls-0_21"))]
|
||||
use actix_http::TlsAcceptorConfig;
|
||||
use actix_http::{body::MessageBody, Extensions, HttpService, KeepAlive, Request, Response};
|
||||
use actix_server::{Server, ServerBuilder};
|
||||
@ -447,25 +442,6 @@ where
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Resolves socket address(es) and binds server to created listener(s) for TLS connections
|
||||
/// using Rustls v0.22.
|
||||
///
|
||||
/// See [`bind()`](Self::bind()) for more details on `addrs` argument.
|
||||
///
|
||||
/// ALPN protocols "h2" and "http/1.1" are added to any configured ones.
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
pub fn bind_rustls_0_22<A: net::ToSocketAddrs>(
|
||||
mut self,
|
||||
addrs: A,
|
||||
config: actix_tls::accept::rustls_0_22::reexports::ServerConfig,
|
||||
) -> io::Result<Self> {
|
||||
let sockets = bind_addrs(addrs, self.backlog)?;
|
||||
for lst in sockets {
|
||||
self = self.listen_rustls_0_22_inner(lst, config.clone())?;
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Resolves socket address(es) and binds server to created listener(s) for TLS connections
|
||||
/// using OpenSSL.
|
||||
///
|
||||
@ -709,72 +685,6 @@ where
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Binds to existing listener for accepting incoming TLS connection requests using Rustls
|
||||
/// v0.22.
|
||||
///
|
||||
/// See [`listen()`](Self::listen) for more details on the `lst` argument.
|
||||
///
|
||||
/// ALPN protocols "h2" and "http/1.1" are added to any configured ones.
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
pub fn listen_rustls_0_22(
|
||||
self,
|
||||
lst: net::TcpListener,
|
||||
config: actix_tls::accept::rustls_0_22::reexports::ServerConfig,
|
||||
) -> io::Result<Self> {
|
||||
self.listen_rustls_0_22_inner(lst, config)
|
||||
}
|
||||
|
||||
#[cfg(feature = "rustls-0_22")]
|
||||
fn listen_rustls_0_22_inner(
|
||||
mut self,
|
||||
lst: net::TcpListener,
|
||||
config: actix_tls::accept::rustls_0_22::reexports::ServerConfig,
|
||||
) -> io::Result<Self> {
|
||||
let factory = self.factory.clone();
|
||||
let cfg = self.config.clone();
|
||||
let addr = lst.local_addr().unwrap();
|
||||
self.sockets.push(Socket {
|
||||
addr,
|
||||
scheme: "https",
|
||||
});
|
||||
|
||||
let on_connect_fn = self.on_connect_fn.clone();
|
||||
|
||||
self.builder =
|
||||
self.builder
|
||||
.listen(format!("actix-web-service-{}", addr), lst, move || {
|
||||
let c = cfg.lock().unwrap();
|
||||
let host = c.host.clone().unwrap_or_else(|| format!("{}", addr));
|
||||
|
||||
let svc = HttpService::build()
|
||||
.keep_alive(c.keep_alive)
|
||||
.client_request_timeout(c.client_request_timeout)
|
||||
.client_disconnect_timeout(c.client_disconnect_timeout);
|
||||
|
||||
let svc = if let Some(handler) = on_connect_fn.clone() {
|
||||
svc.on_connect_ext(move |io: &_, ext: _| (handler)(io as &dyn Any, ext))
|
||||
} else {
|
||||
svc
|
||||
};
|
||||
|
||||
let fac = factory()
|
||||
.into_factory()
|
||||
.map_err(|err| err.into().error_response());
|
||||
|
||||
let acceptor_config = match c.tls_handshake_timeout {
|
||||
Some(dur) => TlsAcceptorConfig::default().handshake_timeout(dur),
|
||||
None => TlsAcceptorConfig::default(),
|
||||
};
|
||||
|
||||
svc.finish(map_config(fac, move |_| {
|
||||
AppConfig::new(true, host.clone(), addr)
|
||||
}))
|
||||
.rustls_0_22_with_config(config.clone(), acceptor_config)
|
||||
})?;
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Binds to existing listener for accepting incoming TLS connection requests using OpenSSL.
|
||||
///
|
||||
/// See [`listen()`](Self::listen) for more details on the `lst` argument.
|
||||
|
@ -125,11 +125,11 @@ impl ServiceRequest {
|
||||
/// # todo!()
|
||||
/// }
|
||||
/// ```
|
||||
pub fn extract<T>(&mut self) -> <T as FromRequest>::Future
|
||||
pub async fn extract<T: FromRequest>(&mut self) -> Result<T, <T as FromRequest>::Error>
|
||||
where
|
||||
T: FromRequest,
|
||||
{
|
||||
T::from_request(&self.req, &mut self.payload)
|
||||
T::from_request(&self.req, &mut self.payload).await
|
||||
}
|
||||
|
||||
/// Construct request from parts.
|
||||
@ -221,9 +221,12 @@ impl ServiceRequest {
|
||||
|
||||
/// Returns peer's socket address.
|
||||
///
|
||||
/// See [`HttpRequest::peer_addr`] for more details.
|
||||
/// Peer address is the directly connected peer's socket address. If a proxy is used in front of
|
||||
/// the Actix Web server, then it would be address of this proxy.
|
||||
///
|
||||
/// [`HttpRequest::peer_addr`]: crate::HttpRequest::peer_addr
|
||||
/// To get client connection information `ConnectionInfo` should be used.
|
||||
///
|
||||
/// Will only return None when called in unit tests.
|
||||
#[inline]
|
||||
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
|
||||
self.head().peer_addr
|
||||
|
@ -86,77 +86,76 @@ impl Default for TestRequest {
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
impl TestRequest {
|
||||
/// Constructs test request and sets request URI.
|
||||
pub fn with_uri(uri: &str) -> TestRequest {
|
||||
TestRequest::default().uri(uri)
|
||||
/// Create TestRequest and set request uri
|
||||
pub fn with_uri(path: &str) -> TestRequest {
|
||||
TestRequest::default().uri(path)
|
||||
}
|
||||
|
||||
/// Constructs test request with GET method.
|
||||
/// Create TestRequest and set method to `Method::GET`
|
||||
pub fn get() -> TestRequest {
|
||||
TestRequest::default().method(Method::GET)
|
||||
}
|
||||
|
||||
/// Constructs test request with POST method.
|
||||
/// Create TestRequest and set method to `Method::POST`
|
||||
pub fn post() -> TestRequest {
|
||||
TestRequest::default().method(Method::POST)
|
||||
}
|
||||
|
||||
/// Constructs test request with PUT method.
|
||||
/// Create TestRequest and set method to `Method::PUT`
|
||||
pub fn put() -> TestRequest {
|
||||
TestRequest::default().method(Method::PUT)
|
||||
}
|
||||
|
||||
/// Constructs test request with PATCH method.
|
||||
/// Create TestRequest and set method to `Method::PATCH`
|
||||
pub fn patch() -> TestRequest {
|
||||
TestRequest::default().method(Method::PATCH)
|
||||
}
|
||||
|
||||
/// Constructs test request with DELETE method.
|
||||
/// Create TestRequest and set method to `Method::DELETE`
|
||||
pub fn delete() -> TestRequest {
|
||||
TestRequest::default().method(Method::DELETE)
|
||||
}
|
||||
|
||||
/// Sets HTTP version of this request.
|
||||
/// Set HTTP version of this request
|
||||
pub fn version(mut self, ver: Version) -> Self {
|
||||
self.req.version(ver);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets method of this request.
|
||||
/// Set HTTP method of this request
|
||||
pub fn method(mut self, meth: Method) -> Self {
|
||||
self.req.method(meth);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets URI of this request.
|
||||
/// Set HTTP URI of this request
|
||||
pub fn uri(mut self, path: &str) -> Self {
|
||||
self.req.uri(path);
|
||||
self
|
||||
}
|
||||
|
||||
/// Inserts a header, replacing any that were set with an equivalent field name.
|
||||
/// Insert a header, replacing any that were set with an equivalent field name.
|
||||
pub fn insert_header(mut self, header: impl TryIntoHeaderPair) -> Self {
|
||||
self.req.insert_header(header);
|
||||
self
|
||||
}
|
||||
|
||||
/// Appends a header, keeping any that were set with an equivalent field name.
|
||||
/// Append a header, keeping any that were set with an equivalent field name.
|
||||
pub fn append_header(mut self, header: impl TryIntoHeaderPair) -> Self {
|
||||
self.req.append_header(header);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets cookie for this request.
|
||||
/// Set cookie for this request.
|
||||
#[cfg(feature = "cookies")]
|
||||
pub fn cookie(mut self, cookie: Cookie<'_>) -> Self {
|
||||
self.cookies.add(cookie.into_owned());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets request path pattern parameter.
|
||||
/// Set request path pattern parameter.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use actix_web::test::TestRequest;
|
||||
///
|
||||
@ -172,19 +171,19 @@ impl TestRequest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets peer address.
|
||||
/// Set peer addr.
|
||||
pub fn peer_addr(mut self, addr: SocketAddr) -> Self {
|
||||
self.peer_addr = Some(addr);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets request payload.
|
||||
/// Set request payload.
|
||||
pub fn set_payload(mut self, data: impl Into<Bytes>) -> Self {
|
||||
self.req.set_payload(data);
|
||||
self
|
||||
}
|
||||
|
||||
/// Serializes `data` to a URL encoded form and set it as the request payload.
|
||||
/// Serialize `data` to a URL encoded form and set it as the request payload.
|
||||
///
|
||||
/// The `Content-Type` header is set to `application/x-www-form-urlencoded`.
|
||||
pub fn set_form(mut self, data: impl Serialize) -> Self {
|
||||
@ -195,7 +194,7 @@ impl TestRequest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Serializes `data` to JSON and set it as the request payload.
|
||||
/// Serialize `data` to JSON and set it as the request payload.
|
||||
///
|
||||
/// The `Content-Type` header is set to `application/json`.
|
||||
pub fn set_json(mut self, data: impl Serialize) -> Self {
|
||||
@ -205,33 +204,27 @@ impl TestRequest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Inserts application data.
|
||||
///
|
||||
/// This is equivalent of `App::app_data()` method for testing purpose.
|
||||
pub fn app_data<T: 'static>(mut self, data: T) -> Self {
|
||||
self.app_data.insert(data);
|
||||
self
|
||||
}
|
||||
|
||||
/// Inserts application data.
|
||||
///
|
||||
/// This is equivalent of `App::data()` method for testing purpose.
|
||||
#[doc(hidden)]
|
||||
/// Set application data. This is equivalent of `App::data()` method
|
||||
/// for testing purpose.
|
||||
pub fn data<T: 'static>(mut self, data: T) -> Self {
|
||||
self.app_data.insert(Data::new(data));
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets resource map.
|
||||
/// Set application data. This is equivalent of `App::app_data()` method
|
||||
/// for testing purpose.
|
||||
pub fn app_data<T: 'static>(mut self, data: T) -> Self {
|
||||
self.app_data.insert(data);
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
/// Set request config
|
||||
pub(crate) fn rmap(mut self, rmap: ResourceMap) -> Self {
|
||||
self.rmap = rmap;
|
||||
self
|
||||
}
|
||||
|
||||
/// Finalizes test request.
|
||||
///
|
||||
/// This request builder will be useless after calling `finish()`.
|
||||
fn finish(&mut self) -> Request {
|
||||
// mut used when cookie feature is enabled
|
||||
#[allow(unused_mut)]
|
||||
@ -258,14 +251,14 @@ impl TestRequest {
|
||||
req
|
||||
}
|
||||
|
||||
/// Finalizes request creation and returns `Request` instance.
|
||||
/// Complete request creation and generate `Request` instance
|
||||
pub fn to_request(mut self) -> Request {
|
||||
let mut req = self.finish();
|
||||
req.head_mut().peer_addr = self.peer_addr;
|
||||
req
|
||||
}
|
||||
|
||||
/// Finalizes request creation and returns `ServiceRequest` instance.
|
||||
/// Complete request creation and generate `ServiceRequest` instance
|
||||
pub fn to_srv_request(mut self) -> ServiceRequest {
|
||||
let (mut head, payload) = self.finish().into_parts();
|
||||
head.peer_addr = self.peer_addr;
|
||||
@ -286,12 +279,12 @@ impl TestRequest {
|
||||
)
|
||||
}
|
||||
|
||||
/// Finalizes request creation and returns `ServiceResponse` instance.
|
||||
/// Complete request creation and generate `ServiceResponse` instance
|
||||
pub fn to_srv_response<B>(self, res: HttpResponse<B>) -> ServiceResponse<B> {
|
||||
self.to_srv_request().into_response(res)
|
||||
}
|
||||
|
||||
/// Finalizes request creation and returns `HttpRequest` instance.
|
||||
/// Complete request creation and generate `HttpRequest` instance
|
||||
pub fn to_http_request(mut self) -> HttpRequest {
|
||||
let (mut head, _) = self.finish().into_parts();
|
||||
head.peer_addr = self.peer_addr;
|
||||
@ -309,7 +302,7 @@ impl TestRequest {
|
||||
)
|
||||
}
|
||||
|
||||
/// Finalizes request creation and returns `HttpRequest` and `Payload` pair.
|
||||
/// Complete request creation and generate `HttpRequest` and `Payload` instances
|
||||
pub fn to_http_parts(mut self) -> (HttpRequest, Payload) {
|
||||
let (mut head, payload) = self.finish().into_parts();
|
||||
head.peer_addr = self.peer_addr;
|
||||
@ -329,7 +322,7 @@ impl TestRequest {
|
||||
(req, payload)
|
||||
}
|
||||
|
||||
/// Finalizes request creation, calls service, and waits for response future completion.
|
||||
/// Complete request creation, calls service and waits for response future completion.
|
||||
pub async fn send_request<S, B, E>(self, app: &S) -> S::Response
|
||||
where
|
||||
S: Service<Request, Response = ServiceResponse<B>, Error = E>,
|
||||
|
@ -1,15 +1,6 @@
|
||||
//! For either helper, see [`Either`].
|
||||
|
||||
use std::{
|
||||
future::Future,
|
||||
mem,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
use bytes::Bytes;
|
||||
use futures_core::ready;
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
use crate::{
|
||||
body::EitherBody,
|
||||
@ -158,7 +149,7 @@ where
|
||||
fn from(err: EitherExtractError<L, R>) -> Error {
|
||||
match err {
|
||||
EitherExtractError::Bytes(err) => err,
|
||||
EitherExtractError::Extract(a_err, _b_err) => a_err.into(),
|
||||
EitherExtractError::Extract(l_err, _r_err) => l_err.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,112 +161,25 @@ where
|
||||
R: FromRequest + 'static,
|
||||
{
|
||||
type Error = EitherExtractError<L::Error, R::Error>;
|
||||
type Future = EitherExtractFut<L, R>;
|
||||
|
||||
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||
EitherExtractFut {
|
||||
req: req.clone(),
|
||||
state: EitherExtractState::Bytes {
|
||||
bytes: Bytes::from_request(req, payload),
|
||||
async fn from_request(
|
||||
req: &HttpRequest,
|
||||
payload: &mut dev::Payload,
|
||||
) -> Result<Self, Self::Error> {
|
||||
let buf = Bytes::from_request(req, payload)
|
||||
.await
|
||||
.map_err(EitherExtractError::Bytes)?;
|
||||
|
||||
match L::from_request(req, &mut payload_from_bytes(buf.clone())).await {
|
||||
Ok(left) => Ok(Either::Left(left)),
|
||||
Err(l_err) => match R::from_request(req, &mut payload_from_bytes(buf)).await {
|
||||
Ok(right) => Ok(Either::Right(right)),
|
||||
Err(r_err) => Err(EitherExtractError::Extract(l_err, r_err)),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
pub struct EitherExtractFut<L, R>
|
||||
where
|
||||
R: FromRequest,
|
||||
L: FromRequest,
|
||||
{
|
||||
req: HttpRequest,
|
||||
#[pin]
|
||||
state: EitherExtractState<L, R>,
|
||||
}
|
||||
}
|
||||
|
||||
pin_project! {
|
||||
#[project = EitherExtractProj]
|
||||
pub enum EitherExtractState<L, R>
|
||||
where
|
||||
L: FromRequest,
|
||||
R: FromRequest,
|
||||
{
|
||||
Bytes {
|
||||
#[pin]
|
||||
bytes: <Bytes as FromRequest>::Future,
|
||||
},
|
||||
Left {
|
||||
#[pin]
|
||||
left: L::Future,
|
||||
fallback: Bytes,
|
||||
},
|
||||
Right {
|
||||
#[pin]
|
||||
right: R::Future,
|
||||
left_err: Option<L::Error>,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
impl<R, RF, RE, L, LF, LE> Future for EitherExtractFut<L, R>
|
||||
where
|
||||
L: FromRequest<Future = LF, Error = LE>,
|
||||
R: FromRequest<Future = RF, Error = RE>,
|
||||
LF: Future<Output = Result<L, LE>> + 'static,
|
||||
RF: Future<Output = Result<R, RE>> + 'static,
|
||||
LE: Into<Error>,
|
||||
RE: Into<Error>,
|
||||
{
|
||||
type Output = Result<Either<L, R>, EitherExtractError<LE, RE>>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let mut this = self.project();
|
||||
let ready = loop {
|
||||
let next = match this.state.as_mut().project() {
|
||||
EitherExtractProj::Bytes { bytes } => {
|
||||
let res = ready!(bytes.poll(cx));
|
||||
match res {
|
||||
Ok(bytes) => {
|
||||
let fallback = bytes.clone();
|
||||
let left = L::from_request(this.req, &mut payload_from_bytes(bytes));
|
||||
EitherExtractState::Left { left, fallback }
|
||||
}
|
||||
Err(err) => break Err(EitherExtractError::Bytes(err)),
|
||||
}
|
||||
}
|
||||
EitherExtractProj::Left { left, fallback } => {
|
||||
let res = ready!(left.poll(cx));
|
||||
match res {
|
||||
Ok(extracted) => break Ok(Either::Left(extracted)),
|
||||
Err(left_err) => {
|
||||
let right = R::from_request(
|
||||
this.req,
|
||||
&mut payload_from_bytes(mem::take(fallback)),
|
||||
);
|
||||
EitherExtractState::Right {
|
||||
left_err: Some(left_err),
|
||||
right,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EitherExtractProj::Right { right, left_err } => {
|
||||
let res = ready!(right.poll(cx));
|
||||
match res {
|
||||
Ok(data) => break Ok(Either::Right(data)),
|
||||
Err(err) => {
|
||||
break Err(EitherExtractError::Extract(left_err.take().unwrap(), err));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
this.state.set(next);
|
||||
};
|
||||
Poll::Ready(ready)
|
||||
}
|
||||
}
|
||||
|
||||
fn payload_from_bytes(bytes: Bytes) -> dev::Payload {
|
||||
let (_, mut h1_payload) = actix_http::h1::Payload::create(true);
|
||||
h1_payload.unread_data(bytes);
|
||||
|
@ -13,7 +13,7 @@ use std::{
|
||||
use actix_http::Payload;
|
||||
use bytes::BytesMut;
|
||||
use encoding_rs::{Encoding, UTF_8};
|
||||
use futures_core::{future::LocalBoxFuture, ready};
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use futures_util::{FutureExt as _, StreamExt as _};
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
@ -126,51 +126,21 @@ where
|
||||
T: DeserializeOwned + 'static,
|
||||
{
|
||||
type Error = Error;
|
||||
type Future = FormExtractFut<T>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||
let FormConfig { limit, err_handler } = FormConfig::from_req(req).clone();
|
||||
async fn from_request(req: &HttpRequest, payload: &mut Payload) -> Result<Self, Self::Error> {
|
||||
let FormConfig { limit, err_handler } = FormConfig::from_req(req);
|
||||
|
||||
FormExtractFut {
|
||||
fut: UrlEncoded::new(req, payload).limit(limit),
|
||||
req: req.clone(),
|
||||
err_handler,
|
||||
match UrlEncoded::new(req, payload).limit(*limit).await {
|
||||
Ok(form) => Ok(Form(form)),
|
||||
Err(err) => Err(match err_handler {
|
||||
Some(err_handler) => (err_handler)(err, req),
|
||||
None => err.into(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type FormErrHandler = Option<Rc<dyn Fn(UrlencodedError, &HttpRequest) -> Error>>;
|
||||
|
||||
pub struct FormExtractFut<T> {
|
||||
fut: UrlEncoded<T>,
|
||||
err_handler: FormErrHandler,
|
||||
req: HttpRequest,
|
||||
}
|
||||
|
||||
impl<T> Future for FormExtractFut<T>
|
||||
where
|
||||
T: DeserializeOwned + 'static,
|
||||
{
|
||||
type Output = Result<Form<T>, Error>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.get_mut();
|
||||
|
||||
let res = ready!(Pin::new(&mut this.fut).poll(cx));
|
||||
|
||||
let res = match res {
|
||||
Err(err) => match &this.err_handler {
|
||||
Some(err_handler) => Err((err_handler)(err, &this.req)),
|
||||
None => Err(err.into()),
|
||||
},
|
||||
Ok(item) => Ok(Form(item)),
|
||||
};
|
||||
|
||||
Poll::Ready(res)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: fmt::Display> fmt::Display for Form<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
@ -198,6 +168,8 @@ impl<T: Serialize> Responder for Form<T> {
|
||||
}
|
||||
}
|
||||
|
||||
type FormErrHandler = Option<Rc<dyn Fn(UrlencodedError, &HttpRequest) -> Error>>;
|
||||
|
||||
/// [`Form`] extractor configuration.
|
||||
///
|
||||
/// ```
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
use std::{fmt, ops};
|
||||
|
||||
use actix_utils::future::{ready, Ready};
|
||||
|
||||
use crate::{
|
||||
dev::Payload, error::ParseError, extract::FromRequest, http::header::Header as ParseHeader,
|
||||
HttpRequest,
|
||||
@ -61,13 +59,12 @@ where
|
||||
T: ParseHeader,
|
||||
{
|
||||
type Error = ParseError;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
match ParseHeader::parse(req) {
|
||||
Ok(header) => ready(Ok(Header(header))),
|
||||
Err(err) => ready(Err(err)),
|
||||
Ok(header) => Ok(Header(header)),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,10 +138,8 @@ impl<T: Serialize> Responder for Json<T> {
|
||||
/// See [here](#extractor) for example of usage as an extractor.
|
||||
impl<T: DeserializeOwned> FromRequest for Json<T> {
|
||||
type Error = Error;
|
||||
type Future = JsonExtractFut<T>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||
async fn from_request(req: &HttpRequest, payload: &mut Payload) -> Result<Self, Self::Error> {
|
||||
let config = JsonConfig::from_req(req);
|
||||
|
||||
let limit = config.limit;
|
||||
@ -149,52 +147,30 @@ impl<T: DeserializeOwned> FromRequest for Json<T> {
|
||||
let ctype_fn = config.content_type.as_deref();
|
||||
let err_handler = config.err_handler.clone();
|
||||
|
||||
JsonExtractFut {
|
||||
req: Some(req.clone()),
|
||||
fut: JsonBody::new(req, payload, ctype_fn, ctype_required).limit(limit),
|
||||
err_handler,
|
||||
match JsonBody::new(req, payload, ctype_fn, ctype_required)
|
||||
.limit(limit)
|
||||
.await
|
||||
{
|
||||
Ok(data) => Ok(Json(data)),
|
||||
Err(err) => {
|
||||
log::debug!(
|
||||
"Failed to deserialize Json<{}> from payload. \
|
||||
Request path: {}",
|
||||
std::any::type_name::<T>(),
|
||||
req.path(),
|
||||
);
|
||||
|
||||
Err(match err_handler.as_ref() {
|
||||
Some(err_handler) => (err_handler)(err, req),
|
||||
None => err.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type JsonErrorHandler = Option<Arc<dyn Fn(JsonPayloadError, &HttpRequest) -> Error + Send + Sync>>;
|
||||
|
||||
pub struct JsonExtractFut<T> {
|
||||
req: Option<HttpRequest>,
|
||||
fut: JsonBody<T>,
|
||||
err_handler: JsonErrorHandler,
|
||||
}
|
||||
|
||||
impl<T: DeserializeOwned> Future for JsonExtractFut<T> {
|
||||
type Output = Result<Json<T>, Error>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.get_mut();
|
||||
|
||||
let res = ready!(Pin::new(&mut this.fut).poll(cx));
|
||||
|
||||
let res = match res {
|
||||
Err(err) => {
|
||||
let req = this.req.take().unwrap();
|
||||
log::debug!(
|
||||
"Failed to deserialize Json from payload. \
|
||||
Request path: {}",
|
||||
req.path()
|
||||
);
|
||||
|
||||
if let Some(err_handler) = this.err_handler.as_ref() {
|
||||
Err((*err_handler)(err, &req))
|
||||
} else {
|
||||
Err(err.into())
|
||||
}
|
||||
}
|
||||
Ok(data) => Ok(Json(data)),
|
||||
};
|
||||
|
||||
Poll::Ready(res)
|
||||
}
|
||||
}
|
||||
|
||||
/// `Json` extractor configuration.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -3,7 +3,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_router::PathDeserializer;
|
||||
use actix_utils::future::{ready, Ready};
|
||||
use derive_more::{AsRef, Deref, DerefMut, Display, From};
|
||||
use serde::de;
|
||||
|
||||
@ -69,33 +68,29 @@ where
|
||||
T: de::DeserializeOwned,
|
||||
{
|
||||
type Error = Error;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
let error_handler = req
|
||||
.app_data::<PathConfig>()
|
||||
.or_else(|| req.app_data::<Data<PathConfig>>().map(Data::get_ref))
|
||||
.and_then(|c| c.err_handler.clone());
|
||||
|
||||
ready(
|
||||
de::Deserialize::deserialize(PathDeserializer::new(req.match_info()))
|
||||
.map(Path)
|
||||
.map_err(move |err| {
|
||||
log::debug!(
|
||||
"Failed during Path extractor deserialization. \
|
||||
de::Deserialize::deserialize(PathDeserializer::new(req.match_info()))
|
||||
.map(Path)
|
||||
.map_err(move |err| {
|
||||
log::debug!(
|
||||
"Failed during Path extractor deserialization. \
|
||||
Request path: {:?}",
|
||||
req.path()
|
||||
);
|
||||
req.path()
|
||||
);
|
||||
|
||||
if let Some(error_handler) = error_handler {
|
||||
let e = PathError::Deserialize(err);
|
||||
(error_handler)(e, req)
|
||||
} else {
|
||||
ErrorNotFound(err)
|
||||
}
|
||||
}),
|
||||
)
|
||||
if let Some(error_handler) = error_handler {
|
||||
let e = PathError::Deserialize(err);
|
||||
(error_handler)(e, req)
|
||||
} else {
|
||||
ErrorNotFound(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,8 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_http::error::PayloadError;
|
||||
use actix_utils::future::{ready, Either, Ready};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use encoding_rs::{Encoding, UTF_8};
|
||||
use encoding_rs::Encoding;
|
||||
use futures_core::{ready, stream::Stream};
|
||||
use mime::Mime;
|
||||
|
||||
@ -131,11 +130,13 @@ impl Stream for Payload {
|
||||
/// See [here](#Examples) for example of usage as an extractor.
|
||||
impl FromRequest for Payload {
|
||||
type Error = Error;
|
||||
type Future = Ready<Result<Self, Self::Error>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(_: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||
ready(Ok(Payload(payload.take())))
|
||||
async fn from_request(
|
||||
_: &HttpRequest,
|
||||
payload: &mut dev::Payload,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(Payload(payload.take()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,33 +158,21 @@ impl FromRequest for Payload {
|
||||
/// ```
|
||||
impl FromRequest for Bytes {
|
||||
type Error = Error;
|
||||
type Future = Either<BytesExtractFut, Ready<Result<Bytes, Error>>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||
async fn from_request(
|
||||
req: &HttpRequest,
|
||||
payload: &mut dev::Payload,
|
||||
) -> Result<Self, Self::Error> {
|
||||
// allow both Config and Data<Config>
|
||||
let cfg = PayloadConfig::from_req(req);
|
||||
|
||||
if let Err(err) = cfg.check_mimetype(req) {
|
||||
return Either::right(ready(Err(err)));
|
||||
}
|
||||
// check content-type
|
||||
cfg.check_mimetype(req)?;
|
||||
|
||||
Either::left(BytesExtractFut {
|
||||
body_fut: HttpMessageBody::new(req, payload).limit(cfg.limit),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Future for `Bytes` extractor.
|
||||
pub struct BytesExtractFut {
|
||||
body_fut: HttpMessageBody,
|
||||
}
|
||||
|
||||
impl Future for BytesExtractFut {
|
||||
type Output = Result<Bytes, Error>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Pin::new(&mut self.body_fut).poll(cx).map_err(Into::into)
|
||||
HttpMessageBody::new(req, payload)
|
||||
.limit(cfg.limit)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,49 +193,29 @@ impl Future for BytesExtractFut {
|
||||
/// }
|
||||
impl FromRequest for String {
|
||||
type Error = Error;
|
||||
type Future = Either<StringExtractFut, Ready<Result<String, Error>>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||
async fn from_request(
|
||||
req: &HttpRequest,
|
||||
payload: &mut dev::Payload,
|
||||
) -> Result<Self, Self::Error> {
|
||||
let cfg = PayloadConfig::from_req(req);
|
||||
|
||||
// check content-type
|
||||
if let Err(err) = cfg.check_mimetype(req) {
|
||||
return Either::right(ready(Err(err)));
|
||||
}
|
||||
cfg.check_mimetype(req)?;
|
||||
|
||||
// check charset
|
||||
let encoding = match req.encoding() {
|
||||
Ok(enc) => enc,
|
||||
Err(err) => return Either::right(ready(Err(err.into()))),
|
||||
};
|
||||
let encoding = req.encoding()?;
|
||||
let limit = cfg.limit;
|
||||
let body_fut = HttpMessageBody::new(req, payload).limit(limit);
|
||||
|
||||
Either::left(StringExtractFut { body_fut, encoding })
|
||||
}
|
||||
}
|
||||
let body = HttpMessageBody::new(req, payload).limit(limit).await?;
|
||||
|
||||
/// Future for `String` extractor.
|
||||
pub struct StringExtractFut {
|
||||
body_fut: HttpMessageBody,
|
||||
encoding: &'static Encoding,
|
||||
}
|
||||
|
||||
impl Future for StringExtractFut {
|
||||
type Output = Result<String, Error>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let encoding = self.encoding;
|
||||
|
||||
Pin::new(&mut self.body_fut).poll(cx).map(|out| {
|
||||
let body = out?;
|
||||
bytes_to_string(body, encoding)
|
||||
})
|
||||
bytes_to_string(body, encoding)
|
||||
}
|
||||
}
|
||||
|
||||
fn bytes_to_string(body: Bytes, encoding: &'static Encoding) -> Result<String, Error> {
|
||||
use encoding_rs::UTF_8;
|
||||
|
||||
if encoding == UTF_8 {
|
||||
Ok(str::from_utf8(body.as_ref())
|
||||
.map_err(|_| ErrorBadRequest("Can not decode body"))?
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
use std::{fmt, ops, sync::Arc};
|
||||
|
||||
use actix_utils::future::{err, ok, Ready};
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use crate::{dev::Payload, error::QueryPayloadError, Error, FromRequest, HttpRequest};
|
||||
@ -108,32 +107,27 @@ impl<T: fmt::Display> fmt::Display for Query<T> {
|
||||
/// See [here](#Examples) for example of usage as an extractor.
|
||||
impl<T: DeserializeOwned> FromRequest for Query<T> {
|
||||
type Error = Error;
|
||||
type Future = Ready<Result<Self, Error>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
async fn from_request(req: &HttpRequest, _: &mut Payload) -> Result<Self, Self::Error> {
|
||||
let error_handler = req
|
||||
.app_data::<QueryConfig>()
|
||||
.and_then(|c| c.err_handler.clone());
|
||||
|
||||
serde_urlencoded::from_str::<T>(req.query_string())
|
||||
.map(|val| ok(Query(val)))
|
||||
.map(|val| Ok(Query(val)))
|
||||
.unwrap_or_else(move |e| {
|
||||
let e = QueryPayloadError::Deserialize(e);
|
||||
let err = QueryPayloadError::Deserialize(e);
|
||||
|
||||
log::debug!(
|
||||
"Failed during Query extractor deserialization. \
|
||||
Request path: {:?}",
|
||||
Request path: {}",
|
||||
req.path()
|
||||
);
|
||||
|
||||
let e = if let Some(error_handler) = error_handler {
|
||||
(error_handler)(e, req)
|
||||
} else {
|
||||
e.into()
|
||||
};
|
||||
|
||||
err(e)
|
||||
Err(match error_handler {
|
||||
Some(error_handler) => (error_handler)(err, req),
|
||||
None => err.into(),
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -743,7 +743,7 @@ mod plus_rustls {
|
||||
.map(char::from)
|
||||
.collect::<String>();
|
||||
|
||||
let srv = actix_test::start_with(actix_test::config().rustls_0_21(tls_config()), || {
|
||||
let srv = actix_test::start_with(actix_test::config().rustls_021(tls_config()), || {
|
||||
App::new().service(web::resource("/").route(web::to(|bytes: Bytes| async {
|
||||
// echo decompressed request body back in response
|
||||
HttpResponse::Ok()
|
||||
|
@ -2,13 +2,6 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 3.4.0
|
||||
|
||||
- Add `rustls-0_22-webpki-roots` and `rustls-0_22-native-roots` crate feature.
|
||||
- Add `awc::Connector::rustls_0_22()` method.
|
||||
|
||||
## 3.3.0
|
||||
|
||||
- Update `trust-dns-resolver` dependency to `0.23`.
|
||||
- Updated `zstd` dependency to `0.13`.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "awc"
|
||||
version = "3.4.0"
|
||||
version = "3.2.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
description = "Async HTTP and WebSocket client library"
|
||||
keywords = ["actix", "http", "framework", "async", "web"]
|
||||
@ -20,17 +20,8 @@ name = "awc"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
features = [
|
||||
"cookies",
|
||||
"openssl",
|
||||
"rustls-0_20",
|
||||
"rustls-0_21",
|
||||
"rustls-0_22-webpki-roots",
|
||||
"compress-brotli",
|
||||
"compress-gzip",
|
||||
"compress-zstd",
|
||||
]
|
||||
# features that docs.rs will build with
|
||||
features = ["openssl", "rustls-0_20", "rustls-0_21", "compress-brotli", "compress-gzip", "compress-zstd", "cookies"]
|
||||
|
||||
[features]
|
||||
default = ["compress-brotli", "compress-gzip", "compress-zstd", "cookies"]
|
||||
@ -44,10 +35,6 @@ rustls = ["rustls-0_20"]
|
||||
rustls-0_20 = ["tls-rustls-0_20", "actix-tls/rustls-0_20"]
|
||||
# TLS via Rustls v0.21
|
||||
rustls-0_21 = ["tls-rustls-0_21", "actix-tls/rustls-0_21"]
|
||||
# TLS via Rustls v0.22 (WebPKI roots)
|
||||
rustls-0_22-webpki-roots = ["tls-rustls-0_22", "actix-tls/rustls-0_22-webpki-roots"]
|
||||
# TLS via Rustls v0.22 (Native roots)
|
||||
rustls-0_22-native-roots = ["tls-rustls-0_22", "actix-tls/rustls-0_22-native-roots"]
|
||||
|
||||
# Brotli algorithm content-encoding support
|
||||
compress-brotli = ["actix-http/compress-brotli", "__compress"]
|
||||
@ -74,9 +61,9 @@ dangerous-h2c = []
|
||||
[dependencies]
|
||||
actix-codec = "0.5"
|
||||
actix-service = "2"
|
||||
actix-http = { version = "3.6", features = ["http2", "ws"] }
|
||||
actix-http = { version = "3.4", features = ["http2", "ws"] }
|
||||
actix-rt = { version = "2.1", default-features = false }
|
||||
actix-tls = { version = "3.3", features = ["connect", "uri"] }
|
||||
actix-tls = { version = "3.1", features = ["connect", "uri"] }
|
||||
actix-utils = "3"
|
||||
|
||||
base64 = "0.21"
|
||||
@ -85,7 +72,7 @@ cfg-if = "1"
|
||||
derive_more = "0.99.5"
|
||||
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.24"
|
||||
h2 = "0.3.17"
|
||||
http = "0.2.7"
|
||||
itoa = "1"
|
||||
log =" 0.4"
|
||||
@ -103,16 +90,15 @@ cookie = { version = "0.16", features = ["percent-encode"], optional = true }
|
||||
tls-openssl = { package = "openssl", version = "0.10.55", optional = true }
|
||||
tls-rustls-0_20 = { package = "rustls", version = "0.20", optional = true, features = ["dangerous_configuration"] }
|
||||
tls-rustls-0_21 = { package = "rustls", version = "0.21", optional = true, features = ["dangerous_configuration"] }
|
||||
tls-rustls-0_22 = { package = "rustls", version = "0.22", optional = true }
|
||||
|
||||
trust-dns-resolver = { version = "0.23", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-http = { version = "3.6", features = ["openssl"] }
|
||||
actix-http = { version = "3.4", features = ["openssl"] }
|
||||
actix-http-test = { version = "3", features = ["openssl"] }
|
||||
actix-server = "2"
|
||||
actix-test = { version = "0.1", features = ["openssl", "rustls-0_22"] }
|
||||
actix-tls = { version = "3.3", features = ["openssl", "rustls-0_22"] }
|
||||
actix-test = { version = "0.1", features = ["openssl", "rustls-0_21"] }
|
||||
actix-tls = { version = "3", features = ["openssl", "rustls-0_21"] }
|
||||
actix-utils = "3"
|
||||
actix-web = { version = "4", features = ["openssl"] }
|
||||
|
||||
@ -122,11 +108,11 @@ env_logger = "0.10"
|
||||
flate2 = "1.0.13"
|
||||
futures-util = { version = "0.3.17", default-features = false }
|
||||
static_assertions = "1.1"
|
||||
rcgen = "0.12"
|
||||
rustls-pemfile = "2"
|
||||
rcgen = "0.11"
|
||||
rustls-pemfile = "1"
|
||||
tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros"] }
|
||||
zstd = "0.13"
|
||||
|
||||
[[example]]
|
||||
name = "client"
|
||||
required-features = ["rustls-0_22-webpki-roots"]
|
||||
required-features = ["rustls-0_21"]
|
||||
|
@ -1,17 +1,13 @@
|
||||
# `awc` (Actix Web Client)
|
||||
# awc (Actix Web Client)
|
||||
|
||||
> Async HTTP and WebSocket client library.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/awc)
|
||||
[](https://docs.rs/awc/3.4.0)
|
||||
[](https://docs.rs/awc/3.2.0)
|
||||

|
||||
[](https://deps.rs/crate/awc/3.4.0)
|
||||
[](https://deps.rs/crate/awc/3.2.0)
|
||||
[](https://discord.gg/NWpN5mmg3x)
|
||||
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Documentation & Resources
|
||||
|
||||
- [API Documentation](https://docs.rs/awc)
|
||||
|
@ -40,23 +40,14 @@ enum OurTlsConnector {
|
||||
/// Provided because building the OpenSSL context on newer versions can be very slow.
|
||||
/// This prevents unnecessary calls to `.build()` while constructing the client connector.
|
||||
#[cfg(feature = "openssl")]
|
||||
#[allow(dead_code)] // false positive; used in build_tls
|
||||
#[allow(dead_code)] // false positive; used in build_ssl
|
||||
OpensslBuilder(actix_tls::connect::openssl::reexports::SslConnectorBuilder),
|
||||
|
||||
#[cfg(feature = "rustls-0_20")]
|
||||
#[allow(dead_code)] // false positive; used in build_tls
|
||||
Rustls020(std::sync::Arc<actix_tls::connect::rustls_0_20::reexports::ClientConfig>),
|
||||
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
#[allow(dead_code)] // false positive; used in build_tls
|
||||
Rustls021(std::sync::Arc<actix_tls::connect::rustls_0_21::reexports::ClientConfig>),
|
||||
|
||||
#[cfg(any(
|
||||
feature = "rustls-0_22-webpki-roots",
|
||||
feature = "rustls-0_22-native-roots",
|
||||
))]
|
||||
#[allow(dead_code)] // false positive; used in build_tls
|
||||
Rustls022(std::sync::Arc<actix_tls::connect::rustls_0_22::reexports::ClientConfig>),
|
||||
}
|
||||
|
||||
/// Manages HTTP client network connectivity.
|
||||
@ -95,83 +86,67 @@ impl Connector<()> {
|
||||
}
|
||||
}
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(any(feature = "rustls-0_22-webpki-roots", feature = "rustls-0_22-webpki-roots"))] {
|
||||
/// Build TLS connector with Rustls v0.22, based on supplied ALPN protocols.
|
||||
///
|
||||
/// Note that if other TLS crate features are enabled, Rustls v0.22 will be used.
|
||||
fn build_tls(protocols: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
use actix_tls::connect::rustls_0_22::{self, reexports::ClientConfig};
|
||||
/// Provides an empty TLS connector when no TLS feature is enabled.
|
||||
#[cfg(not(any(feature = "openssl", feature = "rustls-0_20", feature = "rustls-0_21")))]
|
||||
fn build_tls(_: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
OurTlsConnector::None
|
||||
}
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "rustls-0_22-webpki-roots")] {
|
||||
let certs = rustls_0_22::webpki_roots_cert_store();
|
||||
} else if #[cfg(feature = "rustls-0_22-native-roots")] {
|
||||
let certs = rustls_0_22::native_roots_cert_store();
|
||||
}
|
||||
}
|
||||
/// Build TLS connector with Rustls v0.21, based on supplied ALPN protocols
|
||||
///
|
||||
/// Note that if other TLS crate features are enabled, Rustls v0.21 will be used.
|
||||
#[cfg(feature = "rustls-0_21")]
|
||||
fn build_tls(protocols: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
use actix_tls::connect::rustls_0_21::{reexports::ClientConfig, webpki_roots_cert_store};
|
||||
|
||||
let mut config = ClientConfig::builder()
|
||||
.with_root_certificates(certs)
|
||||
.with_no_client_auth();
|
||||
let mut config = ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(webpki_roots_cert_store())
|
||||
.with_no_client_auth();
|
||||
|
||||
config.alpn_protocols = protocols;
|
||||
config.alpn_protocols = protocols;
|
||||
|
||||
OurTlsConnector::Rustls022(std::sync::Arc::new(config))
|
||||
}
|
||||
} else if #[cfg(feature = "rustls-0_21")] {
|
||||
/// Build TLS connector with Rustls v0.21, based on supplied ALPN protocols.
|
||||
fn build_tls(protocols: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
use actix_tls::connect::rustls_0_21::{reexports::ClientConfig, webpki_roots_cert_store};
|
||||
OurTlsConnector::Rustls021(std::sync::Arc::new(config))
|
||||
}
|
||||
|
||||
let mut config = ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(webpki_roots_cert_store())
|
||||
.with_no_client_auth();
|
||||
/// Build TLS connector with Rustls v0.20, based on supplied ALPN protocols
|
||||
///
|
||||
/// Note that if other TLS crate features are enabled, Rustls v0.21 will be used.
|
||||
#[cfg(all(feature = "rustls-0_20", not(feature = "rustls-0_21")))]
|
||||
fn build_tls(protocols: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
use actix_tls::connect::rustls_0_20::{reexports::ClientConfig, webpki_roots_cert_store};
|
||||
|
||||
config.alpn_protocols = protocols;
|
||||
let mut config = ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(webpki_roots_cert_store())
|
||||
.with_no_client_auth();
|
||||
|
||||
OurTlsConnector::Rustls021(std::sync::Arc::new(config))
|
||||
}
|
||||
} else if #[cfg(feature = "rustls-0_20")] {
|
||||
/// Build TLS connector with Rustls v0.20, based on supplied ALPN protocols.
|
||||
fn build_tls(protocols: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
use actix_tls::connect::rustls_0_20::{reexports::ClientConfig, webpki_roots_cert_store};
|
||||
config.alpn_protocols = protocols;
|
||||
|
||||
let mut config = ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(webpki_roots_cert_store())
|
||||
.with_no_client_auth();
|
||||
OurTlsConnector::Rustls020(std::sync::Arc::new(config))
|
||||
}
|
||||
|
||||
config.alpn_protocols = protocols;
|
||||
/// Build TLS connector with OpenSSL, based on supplied ALPN protocols
|
||||
#[cfg(all(
|
||||
feature = "openssl",
|
||||
not(any(feature = "rustls-0_20", feature = "rustls-0_21")),
|
||||
))]
|
||||
fn build_tls(protocols: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
use actix_tls::connect::openssl::reexports::{SslConnector, SslMethod};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
|
||||
OurTlsConnector::Rustls020(std::sync::Arc::new(config))
|
||||
}
|
||||
} else if #[cfg(feature = "openssl")] {
|
||||
/// Build TLS connector with OpenSSL, based on supplied ALPN protocols.
|
||||
fn build_tls(protocols: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
use actix_tls::connect::openssl::reexports::{SslConnector, SslMethod};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
|
||||
let mut alpn = BytesMut::with_capacity(20);
|
||||
for proto in &protocols {
|
||||
alpn.put_u8(proto.len() as u8);
|
||||
alpn.put(proto.as_slice());
|
||||
}
|
||||
|
||||
let mut ssl = SslConnector::builder(SslMethod::tls()).unwrap();
|
||||
if let Err(err) = ssl.set_alpn_protos(&alpn) {
|
||||
log::error!("Can not set ALPN protocol: {err:?}");
|
||||
}
|
||||
|
||||
OurTlsConnector::OpensslBuilder(ssl)
|
||||
}
|
||||
} else {
|
||||
/// Provides an empty TLS connector when no TLS feature is enabled.
|
||||
fn build_tls(_: Vec<Vec<u8>>) -> OurTlsConnector {
|
||||
OurTlsConnector::None
|
||||
}
|
||||
let mut alpn = BytesMut::with_capacity(20);
|
||||
for proto in &protocols {
|
||||
alpn.put_u8(proto.len() as u8);
|
||||
alpn.put(proto.as_slice());
|
||||
}
|
||||
|
||||
let mut ssl = SslConnector::builder(SslMethod::tls()).unwrap();
|
||||
if let Err(err) = ssl.set_alpn_protos(&alpn) {
|
||||
log::error!("Can not set ALPN protocol: {:?}", err);
|
||||
}
|
||||
|
||||
OurTlsConnector::OpensslBuilder(ssl)
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,19 +240,6 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets custom Rustls v0.22 `ClientConfig` instance.
|
||||
#[cfg(any(
|
||||
feature = "rustls-0_22-webpki-roots",
|
||||
feature = "rustls-0_22-native-roots",
|
||||
))]
|
||||
pub fn rustls_0_22(
|
||||
mut self,
|
||||
connector: std::sync::Arc<actix_tls::connect::rustls_0_22::reexports::ClientConfig>,
|
||||
) -> Self {
|
||||
self.tls = OurTlsConnector::Rustls022(connector);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets maximum supported HTTP major version.
|
||||
///
|
||||
/// Supported versions are HTTP/1.1 and HTTP/2.
|
||||
@ -547,42 +509,6 @@ where
|
||||
|
||||
Some(actix_service::boxed::rc_service(tls_service))
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
feature = "rustls-0_22-webpki-roots",
|
||||
feature = "rustls-0_22-native-roots",
|
||||
))]
|
||||
OurTlsConnector::Rustls022(tls) => {
|
||||
const H2: &[u8] = b"h2";
|
||||
|
||||
use actix_tls::connect::rustls_0_22::{reexports::AsyncTlsStream, TlsConnector};
|
||||
|
||||
impl<Io: ConnectionIo> IntoConnectionIo for TcpConnection<Uri, AsyncTlsStream<Io>> {
|
||||
fn into_connection_io(self) -> (Box<dyn ConnectionIo>, Protocol) {
|
||||
let sock = self.into_parts().0;
|
||||
let h2 = sock
|
||||
.get_ref()
|
||||
.1
|
||||
.alpn_protocol()
|
||||
.map_or(false, |protos| protos.windows(2).any(|w| w == H2));
|
||||
if h2 {
|
||||
(Box::new(sock), Protocol::Http2)
|
||||
} else {
|
||||
(Box::new(sock), Protocol::Http1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let handshake_timeout = self.config.handshake_timeout;
|
||||
|
||||
let tls_service = TlsConnectorService {
|
||||
tcp_service: tcp_service_inner,
|
||||
tls_service: TlsConnector::service(tls),
|
||||
timeout: handshake_timeout,
|
||||
};
|
||||
|
||||
Some(actix_service::boxed::rc_service(tls_service))
|
||||
}
|
||||
};
|
||||
|
||||
let tcp_config = self.config.no_disconnect_timeout();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![cfg(feature = "rustls-0_22-webpki-roots")]
|
||||
#![cfg(feature = "rustls-0_21")]
|
||||
|
||||
extern crate tls_rustls_0_22 as rustls;
|
||||
extern crate tls_rustls_0_21 as rustls;
|
||||
|
||||
use std::{
|
||||
io::BufReader,
|
||||
@ -8,17 +8,18 @@ use std::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc,
|
||||
},
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
use actix_http::HttpService;
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{fn_service, map_config, ServiceFactoryExt};
|
||||
use actix_tls::connect::rustls_0_22::webpki_roots_cert_store;
|
||||
use actix_tls::connect::rustls_0_21::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,
|
||||
client::{ServerCertVerified, ServerCertVerifier},
|
||||
Certificate, ClientConfig, PrivateKey, ServerConfig, ServerName,
|
||||
};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
|
||||
@ -30,62 +31,36 @@ fn tls_config() -> ServerConfig {
|
||||
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 = certs(cert_file)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(Certificate)
|
||||
.collect();
|
||||
let mut keys = pkcs8_private_keys(key_file).unwrap();
|
||||
|
||||
ServerConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(cert_chain, PrivateKeyDer::Pkcs8(keys.remove(0)))
|
||||
.with_single_cert(cert_chain, PrivateKey(keys.remove(0)))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
mod danger {
|
||||
use rustls::{
|
||||
client::danger::{ServerCertVerified, ServerCertVerifier},
|
||||
pki_types::UnixTime,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NoCertificateVerification;
|
||||
|
||||
impl ServerCertVerifier for NoCertificateVerification {
|
||||
fn verify_server_cert(
|
||||
&self,
|
||||
_end_entity: &CertificateDer<'_>,
|
||||
_intermediates: &[CertificateDer<'_>],
|
||||
_server_name: &ServerName<'_>,
|
||||
_end_entity: &Certificate,
|
||||
_intermediates: &[Certificate],
|
||||
_server_name: &ServerName,
|
||||
_scts: &mut dyn Iterator<Item = &[u8]>,
|
||||
_ocsp_response: &[u8],
|
||||
_now: UnixTime,
|
||||
_now: SystemTime,
|
||||
) -> Result<ServerCertVerified, rustls::Error> {
|
||||
Ok(rustls::client::danger::ServerCertVerified::assertion())
|
||||
}
|
||||
|
||||
fn verify_tls12_signature(
|
||||
&self,
|
||||
_message: &[u8],
|
||||
_cert: &CertificateDer<'_>,
|
||||
_dss: &rustls::DigitallySignedStruct,
|
||||
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> {
|
||||
Ok(rustls::client::danger::HandshakeSignatureValid::assertion())
|
||||
}
|
||||
|
||||
fn verify_tls13_signature(
|
||||
&self,
|
||||
_message: &[u8],
|
||||
_cert: &CertificateDer<'_>,
|
||||
_dss: &rustls::DigitallySignedStruct,
|
||||
) -> Result<rustls::client::danger::HandshakeSignatureValid, rustls::Error> {
|
||||
Ok(rustls::client::danger::HandshakeSignatureValid::assertion())
|
||||
}
|
||||
|
||||
fn supported_verify_schemes(&self) -> Vec<rustls::SignatureScheme> {
|
||||
rustls::crypto::ring::default_provider()
|
||||
.signature_verification_algorithms
|
||||
.supported_schemes()
|
||||
Ok(ServerCertVerified::assertion())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,13 +82,14 @@ async fn test_connection_reuse_h2() {
|
||||
App::new().service(web::resource("/").route(web::to(HttpResponse::Ok))),
|
||||
|_| AppConfig::default(),
|
||||
))
|
||||
.rustls_0_22(tls_config())
|
||||
.rustls_021(tls_config())
|
||||
.map_err(|_| ()),
|
||||
)
|
||||
})
|
||||
.await;
|
||||
|
||||
let mut config = ClientConfig::builder()
|
||||
.with_safe_defaults()
|
||||
.with_root_certificates(webpki_roots_cert_store())
|
||||
.with_no_client_auth();
|
||||
|
||||
@ -126,7 +102,7 @@ async fn test_connection_reuse_h2() {
|
||||
.set_certificate_verifier(Arc::new(danger::NoCertificateVerification));
|
||||
|
||||
let client = awc::Client::builder()
|
||||
.connector(awc::Connector::new().rustls_0_22(Arc::new(config)))
|
||||
.connector(awc::Connector::new().rustls_021(Arc::new(config)))
|
||||
.finish();
|
||||
|
||||
// req 1
|
||||
|
10
justfile
10
justfile
@ -1,11 +1,6 @@
|
||||
_list:
|
||||
@just --list
|
||||
|
||||
# Format workspace.
|
||||
fmt:
|
||||
cargo +nightly fmt
|
||||
npx -y prettier --write $(fd --type=file --hidden --extension=md --extension=yml)
|
||||
|
||||
# Document crates in workspace.
|
||||
doc:
|
||||
RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc --no-deps --workspace --features=rustls,openssl
|
||||
@ -14,8 +9,3 @@ doc:
|
||||
doc-watch:
|
||||
RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc --no-deps --workspace --features=rustls,openssl --open
|
||||
cargo watch -- RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc --no-deps --workspace --features=rustls,openssl
|
||||
|
||||
# Update READMEs from crate root documentation.
|
||||
update-readmes: && fmt
|
||||
cd ./actix-files && cargo rdme --force
|
||||
cd ./actix-router && cargo rdme --force
|
||||
|
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
@ -0,0 +1 @@
|
||||
nightly
|
18
scripts/bump
18
scripts/bump
@ -5,7 +5,7 @@
|
||||
|
||||
# requires github cli tool for automatic release draft creation
|
||||
|
||||
set -eEuo pipefail
|
||||
set -euo pipefail
|
||||
|
||||
DIR=$1
|
||||
|
||||
@ -113,23 +113,16 @@ read -p "Update all references: (y/N) " UPDATE_REFERENCES
|
||||
UPDATE_REFERENCES="${UPDATE_REFERENCES:-n}"
|
||||
|
||||
if [ "$UPDATE_REFERENCES" = 'y' ] || [ "$UPDATE_REFERENCES" = 'Y' ]; then
|
||||
if [[ $NEW_VERSION == *".0.0" ]]; then
|
||||
NEW_VERSION_SPEC="${NEW_VERSION%.0.0}"
|
||||
elif [[ $NEW_VERSION == *".0" ]]; then
|
||||
NEW_VERSION_SPEC="${NEW_VERSION%.0}"
|
||||
else
|
||||
NEW_VERSION_SPEC="$NEW_VERSION"
|
||||
fi
|
||||
|
||||
for f in $(fd Cargo.toml); do
|
||||
sed -i.bak -E \
|
||||
"s/^(${PACKAGE_NAME} ?= ?\")[^\"]+(\")$/\1${NEW_VERSION_SPEC}\2/g" $f
|
||||
"s/^(${PACKAGE_NAME} ?= ?\")[^\"]+(\")$/\1${NEW_VERSION}\2/g" $f
|
||||
sed -i.bak -E \
|
||||
"s/^(${PACKAGE_NAME} ?=.*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
||||
"s/^(${PACKAGE_NAME} ?=.*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION}\2/g" $f
|
||||
sed -i.bak -E \
|
||||
"s/^(.*package ?= ?\"${PACKAGE_NAME}\".*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
||||
"s/^(.*package ?= ?\"${PACKAGE_NAME}\".*version ?= ?\")[^\"]+(\".*)$/\1${NEW_VERSION}\2/g" $f
|
||||
sed -i.bak -E \
|
||||
"s/^(.*version ?= ?\")[^\"]+(\".*package ?= ?\"${PACKAGE_NAME}\".*)$/\1${NEW_VERSION_SPEC}\2/g" $f
|
||||
"s/^(.*version ?= ?\")[^\"]+(\".*package ?= ?\"${PACKAGE_NAME}\".*)$/\1${NEW_VERSION}\2/g" $f
|
||||
|
||||
# remove backup file
|
||||
rm -f $f.bak
|
||||
@ -139,7 +132,6 @@ fi
|
||||
|
||||
if [ $MACOS ]; then
|
||||
printf "chore($PACKAGE_NAME): prepare release $NEW_VERSION" | pbcopy
|
||||
echo "placed the recommended commit message on the clipboard"
|
||||
else
|
||||
echo
|
||||
echo "commit message:"
|
||||
|
Reference in New Issue
Block a user