mirror of https://github.com/fafhrd91/actix-web
Merge branch 'main' into feature/mgdlvh/capture_match_info
This commit is contained in:
commit
03262ffa6e
|
|
@ -3,6 +3,6 @@ disallowed-names = [
|
||||||
"e", # no single letter error bindings
|
"e", # no single letter error bindings
|
||||||
]
|
]
|
||||||
disallowed-methods = [
|
disallowed-methods = [
|
||||||
{ path = "std::cell::RefCell::default()", reason = "prefer explicit inner type default" },
|
{ path = "std::cell::RefCell::default()", reason = "prefer explicit inner type default (remove allow-invalid when rust-lang/rust-clippy/#8581 is fixed)", allow-invalid = true },
|
||||||
{ path = "std::rc::Rc::default()", reason = "prefer explicit inner type default" },
|
{ path = "std::rc::Rc::default()", reason = "prefer explicit inner type default (remove allow-invalid when rust-lang/rust-clippy/#8581 is fixed)", allow-invalid = true },
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,14 @@ version: "0.2"
|
||||||
words:
|
words:
|
||||||
- actix
|
- actix
|
||||||
- addrs
|
- addrs
|
||||||
|
- ALPN
|
||||||
- bytestring
|
- bytestring
|
||||||
- httparse
|
- httparse
|
||||||
- msrv
|
- MSRV
|
||||||
- realip
|
- realip
|
||||||
- rustls
|
- rustls
|
||||||
- rustup
|
- rustup
|
||||||
- serde
|
- serde
|
||||||
|
- uring
|
||||||
|
- webpki
|
||||||
- zstd
|
- zstd
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
# These are supported funding model platforms
|
# These are supported funding model platforms
|
||||||
|
|
||||||
github: [robjtede]
|
github: [robjtede, JohnTitor]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
A-files:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-files/**
|
||||||
|
|
||||||
|
A-http:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-http/**
|
||||||
|
|
||||||
|
A-http-test:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-http-test/**
|
||||||
|
|
||||||
|
A-multipart:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-multipart/**
|
||||||
|
|
||||||
|
A-multipart-derive:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-multipart-derive/**
|
||||||
|
|
||||||
|
A-router:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-router/**
|
||||||
|
|
||||||
|
A-test:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-test/**
|
||||||
|
|
||||||
|
A-web:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-web/**
|
||||||
|
|
||||||
|
A-web-actors:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-web-actors/**
|
||||||
|
|
||||||
|
A-web-codegen:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: actix-web-codegen/**
|
||||||
|
|
||||||
|
A-awc:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: awc/**
|
||||||
|
|
@ -2,7 +2,7 @@ name: Benchmark
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [master]
|
branches: [main]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
@ -16,7 +16,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ name: CI (post-merge)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [master]
|
branches: [main]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
@ -28,11 +28,11 @@ jobs:
|
||||||
runs-on: ${{ matrix.target.os }}
|
runs-on: ${{ matrix.target.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install nasm
|
- name: Install nasm
|
||||||
if: matrix.target.os == 'windows-latest'
|
if: matrix.target.os == 'windows-latest'
|
||||||
uses: ilammy/setup-nasm@v1.5.2
|
uses: ilammy/setup-nasm@72793074d3c8cdda771dba85f6deafe00623038b # v1.5.2
|
||||||
|
|
||||||
- name: Install OpenSSL
|
- name: Install OpenSSL
|
||||||
if: matrix.target.os == 'windows-latest'
|
if: matrix.target.os == 'windows-latest'
|
||||||
|
|
@ -44,12 +44,12 @@ jobs:
|
||||||
echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
|
echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Install Rust (${{ matrix.version.name }})
|
- name: Install Rust (${{ matrix.version.name }})
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ matrix.version.version }}
|
toolchain: ${{ matrix.version.version }}
|
||||||
|
|
||||||
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
||||||
uses: taiki-e/install-action@v2.51.2
|
uses: taiki-e/install-action@81a2f66614862089b24532663f669a485d79c889 # v2.67.10
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
||||||
|
|
||||||
|
|
@ -71,19 +71,19 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Free Disk Space
|
- name: Free Disk Space
|
||||||
run: ./scripts/free-disk-space.sh
|
run: ./scripts/free-disk-space.sh
|
||||||
|
|
||||||
- name: Setup mold linker
|
- name: Setup mold linker
|
||||||
uses: rui314/setup-mold@v1
|
uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
|
|
||||||
- name: Install just, cargo-hack
|
- name: Install just, cargo-hack
|
||||||
uses: taiki-e/install-action@v2.51.2
|
uses: taiki-e/install-action@81a2f66614862089b24532663f669a485d79c889 # v2.67.10
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-hack
|
tool: just,cargo-hack
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ on:
|
||||||
merge_group:
|
merge_group:
|
||||||
types: [checks_requested]
|
types: [checks_requested]
|
||||||
push:
|
push:
|
||||||
branches: [master]
|
branches: [main]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
@ -18,7 +18,7 @@ concurrency:
|
||||||
jobs:
|
jobs:
|
||||||
read_msrv:
|
read_msrv:
|
||||||
name: Read MSRV
|
name: Read MSRV
|
||||||
uses: actions-rust-lang/msrv/.github/workflows/msrv.yml@v0.1.0
|
uses: actions-rust-lang/msrv/.github/workflows/msrv.yml@8b553824444060021f2843d7b4d803f3624d15e5 # v0.1.0
|
||||||
|
|
||||||
build_and_test:
|
build_and_test:
|
||||||
needs: read_msrv
|
needs: read_msrv
|
||||||
|
|
@ -39,11 +39,11 @@ jobs:
|
||||||
runs-on: ${{ matrix.target.os }}
|
runs-on: ${{ matrix.target.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install nasm
|
- name: Install nasm
|
||||||
if: matrix.target.os == 'windows-latest'
|
if: matrix.target.os == 'windows-latest'
|
||||||
uses: ilammy/setup-nasm@v1.5.2
|
uses: ilammy/setup-nasm@72793074d3c8cdda771dba85f6deafe00623038b # v1.5.2
|
||||||
|
|
||||||
- name: Install OpenSSL
|
- name: Install OpenSSL
|
||||||
if: matrix.target.os == 'windows-latest'
|
if: matrix.target.os == 'windows-latest'
|
||||||
|
|
@ -56,15 +56,15 @@ jobs:
|
||||||
|
|
||||||
- name: Setup mold linker
|
- name: Setup mold linker
|
||||||
if: matrix.target.os == 'ubuntu-latest'
|
if: matrix.target.os == 'ubuntu-latest'
|
||||||
uses: rui314/setup-mold@v1
|
uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
|
||||||
|
|
||||||
- name: Install Rust (${{ matrix.version.name }})
|
- name: Install Rust (${{ matrix.version.name }})
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ matrix.version.version }}
|
toolchain: ${{ matrix.version.version }}
|
||||||
|
|
||||||
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
- name: Install just, cargo-hack, cargo-nextest, cargo-ci-cache-clean
|
||||||
uses: taiki-e/install-action@v2.51.2
|
uses: taiki-e/install-action@81a2f66614862089b24532663f669a485d79c889 # v2.67.10
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
tool: just,cargo-hack,cargo-nextest,cargo-ci-cache-clean
|
||||||
|
|
||||||
|
|
@ -85,14 +85,18 @@ jobs:
|
||||||
- name: CI cache clean
|
- name: CI cache clean
|
||||||
run: cargo-ci-cache-clean
|
run: cargo-ci-cache-clean
|
||||||
|
|
||||||
|
- name: deny check
|
||||||
|
if: matrix.version.name == 'stable' && matrix.target.os == 'ubuntu-latest'
|
||||||
|
uses: EmbarkStudios/cargo-deny-action@3fd3802e88374d3fe9159b834c7714ec57d6c979 # v2.0.15
|
||||||
|
|
||||||
io-uring:
|
io-uring:
|
||||||
name: io-uring tests
|
name: io-uring tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
|
|
||||||
|
|
@ -105,15 +109,15 @@ jobs:
|
||||||
name: doc tests
|
name: doc tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install Rust (nightly)
|
- name: Install Rust (nightly)
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
|
|
||||||
- name: Install just
|
- name: Install just
|
||||||
uses: taiki-e/install-action@v2.51.2
|
uses: taiki-e/install-action@81a2f66614862089b24532663f669a485d79c889 # v2.67.10
|
||||||
with:
|
with:
|
||||||
tool: just
|
tool: just
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ name: Coverage
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [master]
|
branches: [main]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
@ -15,16 +15,16 @@ jobs:
|
||||||
coverage:
|
coverage:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install Rust (nightly)
|
- name: Install Rust (nightly)
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
components: llvm-tools
|
components: llvm-tools
|
||||||
|
|
||||||
- name: Install just, cargo-llvm-cov, cargo-nextest
|
- name: Install just, cargo-llvm-cov, cargo-nextest
|
||||||
uses: taiki-e/install-action@v2.51.2
|
uses: taiki-e/install-action@81a2f66614862089b24532663f669a485d79c889 # v2.67.10
|
||||||
with:
|
with:
|
||||||
tool: just,cargo-llvm-cov,cargo-nextest
|
tool: just,cargo-llvm-cov,cargo-nextest
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ jobs:
|
||||||
run: just test-coverage-codecov
|
run: just test-coverage-codecov
|
||||||
|
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v5.4.3
|
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
|
||||||
with:
|
with:
|
||||||
files: codecov.json
|
files: codecov.json
|
||||||
fail_ci_if_error: true
|
fail_ci_if_error: true
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
name: Labeler
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
labeler:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
- uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
|
||||||
|
|
@ -15,10 +15,10 @@ jobs:
|
||||||
fmt:
|
fmt:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install Rust (nightly)
|
- name: Install Rust (nightly)
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
|
|
@ -33,15 +33,15 @@ jobs:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
components: clippy
|
components: clippy
|
||||||
|
|
||||||
- name: Check with Clippy
|
- name: Check with Clippy
|
||||||
uses: giraffate/clippy-action@v1.0.1
|
uses: giraffate/clippy-action@13b9d32482f25d29ead141b79e7e04e7900281e0 # v1.0.1
|
||||||
with:
|
with:
|
||||||
reporter: github-pr-check
|
reporter: github-pr-check
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
@ -52,10 +52,10 @@ jobs:
|
||||||
lint-docs:
|
lint-docs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install Rust (nightly)
|
- name: Install Rust (nightly)
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
components: rust-docs
|
components: rust-docs
|
||||||
|
|
@ -69,20 +69,20 @@ jobs:
|
||||||
if: false # rustdoc mismatch currently
|
if: false # rustdoc mismatch currently
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Install Rust (${{ vars.RUST_VERSION_EXTERNAL_TYPES }})
|
- name: Install Rust (${{ vars.RUST_VERSION_EXTERNAL_TYPES }})
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1.12.0
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
toolchain: ${{ vars.RUST_VERSION_EXTERNAL_TYPES }}
|
||||||
|
|
||||||
- name: Install just
|
- name: Install just
|
||||||
uses: taiki-e/install-action@v2.51.2
|
uses: taiki-e/install-action@81a2f66614862089b24532663f669a485d79c889 # v2.67.10
|
||||||
with:
|
with:
|
||||||
tool: just
|
tool: just
|
||||||
|
|
||||||
- name: Install cargo-check-external-types
|
- name: Install cargo-check-external-types
|
||||||
uses: taiki-e/cache-cargo-install-action@v2.1.1
|
uses: taiki-e/cache-cargo-install-action@34ce5120836e5f9f1508d8713d7fdea0e8facd6f # v3.0.1
|
||||||
with:
|
with:
|
||||||
tool: cargo-check-external-types
|
tool: cargo-check-external-types
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
name: Semver Labeler
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: [CI]
|
||||||
|
types: [completed]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
semver-label:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: read
|
||||||
|
env:
|
||||||
|
ACTIONS_STEP_DEBUG: true
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
ref: ${{ github.event.workflow_run.head_sha }}
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1.15.2
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- uses: JohnTitor/cargo-semver-checks@3b76737b550e48ad0bd5912e2757e80eee6294b0 # v0.2.1
|
||||||
|
with:
|
||||||
|
label-prefix: B-semver-
|
||||||
|
label-strategy: skip-if-human
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -19,7 +19,7 @@ homepage = "https://actix.rs"
|
||||||
repository = "https://github.com/actix/actix-web"
|
repository = "https://github.com/actix/actix-web"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.75"
|
rust-version = "1.88"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
# Disabling debug info speeds up builds a bunch and we don't rely on it for debugging that much.
|
# Disabling debug info speeds up builds a bunch and we don't rely on it for debugging that much.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,20 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
|
## 0.6.9
|
||||||
|
|
||||||
|
- Correct `derive_more` dependency feature requirements.
|
||||||
|
|
||||||
|
## 0.6.8
|
||||||
|
|
||||||
|
- Add `Files::with_permanent_redirect()` method.
|
||||||
|
- Change default redirect status code to 307 Temporary Redirect.
|
||||||
|
|
||||||
|
## 0.6.7
|
||||||
|
|
||||||
|
- Add `{Files, NamedFile}::read_mode_threshold()` methods to allow faster synchronous reads of small files.
|
||||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
- Minimum supported Rust version (MSRV) is now 1.75.
|
||||||
|
|
||||||
## 0.6.6
|
## 0.6.6
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-files"
|
name = "actix-files"
|
||||||
version = "0.6.6"
|
version = "0.6.9"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
||||||
description = "Static file serving for Actix Web"
|
description = "Static file serving for Actix Web"
|
||||||
keywords = ["actix", "http", "async", "futures"]
|
keywords = ["actix", "http", "async", "futures"]
|
||||||
|
|
@ -24,7 +24,7 @@ actix-web = { version = "4", default-features = false }
|
||||||
|
|
||||||
bitflags = "2"
|
bitflags = "2"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
derive_more = { version = "2", features = ["display", "error", "from"] }
|
derive_more = { version = "2", features = ["deref", "deref_mut", "display", "error", "from"] }
|
||||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||||
http-range = "0.1.4"
|
http-range = "0.1.4"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
@ -37,7 +37,7 @@ v_htmlescape = "0.15.5"
|
||||||
# experimental-io-uring
|
# experimental-io-uring
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
tokio-uring = { version = "0.5", optional = true, features = ["bytes"] }
|
tokio-uring = { version = "0.5", optional = true, features = ["bytes"] }
|
||||||
actix-server = { version = "2.4", optional = true } # ensure matching tokio-uring versions
|
actix-server = { version = "2.4", optional = true } # ensure matching tokio-uring versions
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "2.7"
|
actix-rt = "2.7"
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-files)
|
[](https://crates.io/crates/actix-files)
|
||||||
[](https://docs.rs/actix-files/0.6.6)
|
[](https://docs.rs/actix-files/0.6.9)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-files/0.6.6)
|
[](https://deps.rs/crate/actix-files/0.6.9)
|
||||||
[](https://crates.io/crates/actix-files)
|
[](https://crates.io/crates/actix-files)
|
||||||
[](https://discord.gg/NWpN5mmg3x)
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,12 @@ use pin_project_lite::pin_project;
|
||||||
|
|
||||||
use super::named::File;
|
use super::named::File;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub(crate) enum ReadMode {
|
||||||
|
Sync,
|
||||||
|
Async,
|
||||||
|
}
|
||||||
|
|
||||||
pin_project! {
|
pin_project! {
|
||||||
/// Adapter to read a `std::file::File` in chunks.
|
/// Adapter to read a `std::file::File` in chunks.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|
@ -24,6 +30,7 @@ pin_project! {
|
||||||
state: ChunkedReadFileState<Fut>,
|
state: ChunkedReadFileState<Fut>,
|
||||||
counter: u64,
|
counter: u64,
|
||||||
callback: F,
|
callback: F,
|
||||||
|
read_mode: ReadMode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,6 +64,7 @@ pub(crate) fn new_chunked_read(
|
||||||
size: u64,
|
size: u64,
|
||||||
offset: u64,
|
offset: u64,
|
||||||
file: File,
|
file: File,
|
||||||
|
read_mode_threshold: u64,
|
||||||
) -> impl Stream<Item = Result<Bytes, Error>> {
|
) -> impl Stream<Item = Result<Bytes, Error>> {
|
||||||
ChunkedReadFile {
|
ChunkedReadFile {
|
||||||
size,
|
size,
|
||||||
|
|
@ -69,31 +77,50 @@ pub(crate) fn new_chunked_read(
|
||||||
},
|
},
|
||||||
counter: 0,
|
counter: 0,
|
||||||
callback: chunked_read_file_callback,
|
callback: chunked_read_file_callback,
|
||||||
|
read_mode: if size < read_mode_threshold {
|
||||||
|
ReadMode::Sync
|
||||||
|
} else {
|
||||||
|
ReadMode::Async
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "experimental-io-uring"))]
|
#[cfg(not(feature = "experimental-io-uring"))]
|
||||||
async fn chunked_read_file_callback(
|
fn chunked_read_file_callback_sync(
|
||||||
mut file: File,
|
mut file: File,
|
||||||
offset: u64,
|
offset: u64,
|
||||||
max_bytes: usize,
|
max_bytes: usize,
|
||||||
) -> Result<(File, Bytes), Error> {
|
) -> Result<(File, Bytes), io::Error> {
|
||||||
use io::{Read as _, Seek as _};
|
use io::{Read as _, Seek as _};
|
||||||
|
|
||||||
let res = actix_web::web::block(move || {
|
let mut buf = Vec::with_capacity(max_bytes);
|
||||||
let mut buf = Vec::with_capacity(max_bytes);
|
|
||||||
|
|
||||||
file.seek(io::SeekFrom::Start(offset))?;
|
file.seek(io::SeekFrom::Start(offset))?;
|
||||||
|
|
||||||
let n_bytes = file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?;
|
let n_bytes = file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?;
|
||||||
|
|
||||||
if n_bytes == 0 {
|
if n_bytes == 0 {
|
||||||
Err(io::Error::from(io::ErrorKind::UnexpectedEof))
|
Err(io::Error::from(io::ErrorKind::UnexpectedEof))
|
||||||
} else {
|
} else {
|
||||||
Ok((file, Bytes::from(buf)))
|
Ok((file, Bytes::from(buf)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "experimental-io-uring"))]
|
||||||
|
#[inline]
|
||||||
|
async fn chunked_read_file_callback(
|
||||||
|
file: File,
|
||||||
|
offset: u64,
|
||||||
|
max_bytes: usize,
|
||||||
|
read_mode: ReadMode,
|
||||||
|
) -> Result<(File, Bytes), Error> {
|
||||||
|
let res = match read_mode {
|
||||||
|
ReadMode::Sync => chunked_read_file_callback_sync(file, offset, max_bytes)?,
|
||||||
|
ReadMode::Async => {
|
||||||
|
actix_web::web::block(move || chunked_read_file_callback_sync(file, offset, max_bytes))
|
||||||
|
.await??
|
||||||
}
|
}
|
||||||
})
|
};
|
||||||
.await??;
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +198,7 @@ where
|
||||||
#[cfg(not(feature = "experimental-io-uring"))]
|
#[cfg(not(feature = "experimental-io-uring"))]
|
||||||
impl<F, Fut> Stream for ChunkedReadFile<F, Fut>
|
impl<F, Fut> Stream for ChunkedReadFile<F, Fut>
|
||||||
where
|
where
|
||||||
F: Fn(File, u64, usize) -> Fut,
|
F: Fn(File, u64, usize, ReadMode) -> Fut,
|
||||||
Fut: Future<Output = Result<(File, Bytes), Error>>,
|
Fut: Future<Output = Result<(File, Bytes), Error>>,
|
||||||
{
|
{
|
||||||
type Item = Result<Bytes, Error>;
|
type Item = Result<Bytes, Error>;
|
||||||
|
|
@ -193,7 +220,7 @@ where
|
||||||
.take()
|
.take()
|
||||||
.expect("ChunkedReadFile polled after completion");
|
.expect("ChunkedReadFile polled after completion");
|
||||||
|
|
||||||
let fut = (this.callback)(file, offset, max_bytes);
|
let fut = (this.callback)(file, offset, max_bytes, *this.read_mode);
|
||||||
|
|
||||||
this.state
|
this.state
|
||||||
.project_replace(ChunkedReadFileState::Future { fut });
|
.project_replace(ChunkedReadFileState::Future { fut });
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ pub struct Files {
|
||||||
index: Option<String>,
|
index: Option<String>,
|
||||||
show_index: bool,
|
show_index: bool,
|
||||||
redirect_to_slash: bool,
|
redirect_to_slash: bool,
|
||||||
|
with_permanent_redirect: bool,
|
||||||
default: Rc<RefCell<Option<Rc<HttpNewService>>>>,
|
default: Rc<RefCell<Option<Rc<HttpNewService>>>>,
|
||||||
renderer: Rc<DirectoryRenderer>,
|
renderer: Rc<DirectoryRenderer>,
|
||||||
mime_override: Option<Rc<MimeOverride>>,
|
mime_override: Option<Rc<MimeOverride>>,
|
||||||
|
|
@ -49,6 +50,7 @@ pub struct Files {
|
||||||
use_guards: Option<Rc<dyn Guard>>,
|
use_guards: Option<Rc<dyn Guard>>,
|
||||||
guards: Vec<Rc<dyn Guard>>,
|
guards: Vec<Rc<dyn Guard>>,
|
||||||
hidden_files: bool,
|
hidden_files: bool,
|
||||||
|
read_mode_threshold: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Files {
|
impl fmt::Debug for Files {
|
||||||
|
|
@ -64,6 +66,7 @@ impl Clone for Files {
|
||||||
index: self.index.clone(),
|
index: self.index.clone(),
|
||||||
show_index: self.show_index,
|
show_index: self.show_index,
|
||||||
redirect_to_slash: self.redirect_to_slash,
|
redirect_to_slash: self.redirect_to_slash,
|
||||||
|
with_permanent_redirect: self.with_permanent_redirect,
|
||||||
default: self.default.clone(),
|
default: self.default.clone(),
|
||||||
renderer: self.renderer.clone(),
|
renderer: self.renderer.clone(),
|
||||||
file_flags: self.file_flags,
|
file_flags: self.file_flags,
|
||||||
|
|
@ -73,6 +76,7 @@ impl Clone for Files {
|
||||||
use_guards: self.use_guards.clone(),
|
use_guards: self.use_guards.clone(),
|
||||||
guards: self.guards.clone(),
|
guards: self.guards.clone(),
|
||||||
hidden_files: self.hidden_files,
|
hidden_files: self.hidden_files,
|
||||||
|
read_mode_threshold: self.read_mode_threshold,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +115,7 @@ impl Files {
|
||||||
index: None,
|
index: None,
|
||||||
show_index: false,
|
show_index: false,
|
||||||
redirect_to_slash: false,
|
redirect_to_slash: false,
|
||||||
|
with_permanent_redirect: false,
|
||||||
default: Rc::new(RefCell::new(None)),
|
default: Rc::new(RefCell::new(None)),
|
||||||
renderer: Rc::new(directory_listing),
|
renderer: Rc::new(directory_listing),
|
||||||
mime_override: None,
|
mime_override: None,
|
||||||
|
|
@ -119,6 +124,7 @@ impl Files {
|
||||||
use_guards: None,
|
use_guards: None,
|
||||||
guards: Vec::new(),
|
guards: Vec::new(),
|
||||||
hidden_files: false,
|
hidden_files: false,
|
||||||
|
read_mode_threshold: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,6 +147,14 @@ impl Files {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Redirect with permanent redirect status code (308).
|
||||||
|
///
|
||||||
|
/// By default redirect with temporary redirect status code (307).
|
||||||
|
pub fn with_permanent_redirect(mut self) -> Self {
|
||||||
|
self.with_permanent_redirect = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set custom directory renderer.
|
/// Set custom directory renderer.
|
||||||
pub fn files_listing_renderer<F>(mut self, f: F) -> Self
|
pub fn files_listing_renderer<F>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
|
|
@ -204,6 +218,23 @@ impl Files {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the size threshold that determines file read mode (sync/async).
|
||||||
|
///
|
||||||
|
/// When a file is smaller than the threshold (bytes), the reader will switch from synchronous
|
||||||
|
/// (blocking) file-reads to async reads to avoid blocking the main-thread when processing large
|
||||||
|
/// files.
|
||||||
|
///
|
||||||
|
/// Tweaking this value according to your expected usage may lead to signifiant performance
|
||||||
|
/// gains (or losses in other handlers, if `size` is too high).
|
||||||
|
///
|
||||||
|
/// When the `experimental-io-uring` crate feature is enabled, file reads are always async.
|
||||||
|
///
|
||||||
|
/// Default is 0, meaning all files are read asynchronously.
|
||||||
|
pub fn read_mode_threshold(mut self, size: u64) -> Self {
|
||||||
|
self.read_mode_threshold = size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Specifies whether to use ETag or not.
|
/// Specifies whether to use ETag or not.
|
||||||
///
|
///
|
||||||
/// Default is true.
|
/// Default is true.
|
||||||
|
|
@ -367,6 +398,8 @@ impl ServiceFactory<ServiceRequest> for Files {
|
||||||
file_flags: self.file_flags,
|
file_flags: self.file_flags,
|
||||||
guards: self.use_guards.clone(),
|
guards: self.use_guards.clone(),
|
||||||
hidden_files: self.hidden_files,
|
hidden_files: self.hidden_files,
|
||||||
|
size_threshold: self.read_mode_threshold,
|
||||||
|
with_permanent_redirect: self.with_permanent_redirect,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ref default) = *self.default.borrow() {
|
if let Some(ref default) = *self.default.borrow() {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
#![warn(missing_docs, missing_debug_implementations)]
|
#![warn(missing_docs, missing_debug_implementations)]
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
|
@ -736,7 +736,21 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
let req = TestRequest::with_uri("/tests").to_request();
|
let req = TestRequest::with_uri("/tests").to_request();
|
||||||
let resp = test::call_service(&srv, req).await;
|
let resp = test::call_service(&srv, req).await;
|
||||||
assert_eq!(resp.status(), StatusCode::FOUND);
|
assert_eq!(resp.status(), StatusCode::TEMPORARY_REDIRECT);
|
||||||
|
|
||||||
|
// should redirect if index present with permanent redirect
|
||||||
|
let srv = test::init_service(
|
||||||
|
App::new().service(
|
||||||
|
Files::new("/", ".")
|
||||||
|
.index_file("test.png")
|
||||||
|
.redirect_to_slash_directory()
|
||||||
|
.with_permanent_redirect(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let req = TestRequest::with_uri("/tests").to_request();
|
||||||
|
let resp = test::call_service(&srv, req).await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::PERMANENT_REDIRECT);
|
||||||
|
|
||||||
// should redirect if files listing is enabled
|
// should redirect if files listing is enabled
|
||||||
let srv = test::init_service(
|
let srv = test::init_service(
|
||||||
|
|
@ -749,7 +763,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
let req = TestRequest::with_uri("/tests").to_request();
|
let req = TestRequest::with_uri("/tests").to_request();
|
||||||
let resp = test::call_service(&srv, req).await;
|
let resp = test::call_service(&srv, req).await;
|
||||||
assert_eq!(resp.status(), StatusCode::FOUND);
|
assert_eq!(resp.status(), StatusCode::TEMPORARY_REDIRECT);
|
||||||
|
|
||||||
// should not redirect if the path is wrong
|
// should not redirect if the path is wrong
|
||||||
let req = TestRequest::with_uri("/not_existing").to_request();
|
let req = TestRequest::with_uri("/not_existing").to_request();
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ pub struct NamedFile {
|
||||||
pub(crate) content_type: Mime,
|
pub(crate) content_type: Mime,
|
||||||
pub(crate) content_disposition: ContentDisposition,
|
pub(crate) content_disposition: ContentDisposition,
|
||||||
pub(crate) encoding: Option<ContentEncoding>,
|
pub(crate) encoding: Option<ContentEncoding>,
|
||||||
|
pub(crate) read_mode_threshold: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "experimental-io-uring"))]
|
#[cfg(not(feature = "experimental-io-uring"))]
|
||||||
|
|
@ -200,6 +201,7 @@ impl NamedFile {
|
||||||
encoding,
|
encoding,
|
||||||
status_code: StatusCode::OK,
|
status_code: StatusCode::OK,
|
||||||
flags: Flags::default(),
|
flags: Flags::default(),
|
||||||
|
read_mode_threshold: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,6 +355,23 @@ impl NamedFile {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the size threshold that determines file read mode (sync/async).
|
||||||
|
///
|
||||||
|
/// When a file is smaller than the threshold (bytes), the reader will switch from synchronous
|
||||||
|
/// (blocking) file-reads to async reads to avoid blocking the main-thread when processing large
|
||||||
|
/// files.
|
||||||
|
///
|
||||||
|
/// Tweaking this value according to your expected usage may lead to signifiant performance
|
||||||
|
/// gains (or losses in other handlers, if `size` is too high).
|
||||||
|
///
|
||||||
|
/// When the `experimental-io-uring` crate feature is enabled, file reads are always async.
|
||||||
|
///
|
||||||
|
/// Default is 0, meaning all files are read asynchronously.
|
||||||
|
pub fn read_mode_threshold(mut self, size: u64) -> Self {
|
||||||
|
self.read_mode_threshold = size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Specifies whether to return `ETag` header in response.
|
/// Specifies whether to return `ETag` header in response.
|
||||||
///
|
///
|
||||||
/// Default is true.
|
/// Default is true.
|
||||||
|
|
@ -440,7 +459,8 @@ impl NamedFile {
|
||||||
res.insert_header((header::CONTENT_ENCODING, current_encoding.as_str()));
|
res.insert_header((header::CONTENT_ENCODING, current_encoding.as_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let reader = chunked::new_chunked_read(self.md.len(), 0, self.file);
|
let reader =
|
||||||
|
chunked::new_chunked_read(self.md.len(), 0, self.file, self.read_mode_threshold);
|
||||||
|
|
||||||
return res.streaming(reader);
|
return res.streaming(reader);
|
||||||
}
|
}
|
||||||
|
|
@ -577,7 +597,7 @@ impl NamedFile {
|
||||||
.map_into_boxed_body();
|
.map_into_boxed_body();
|
||||||
}
|
}
|
||||||
|
|
||||||
let reader = chunked::new_chunked_read(length, offset, self.file);
|
let reader = chunked::new_chunked_read(length, offset, self.file, self.read_mode_threshold);
|
||||||
|
|
||||||
if offset != 0 || length != self.md.len() {
|
if offset != 0 || length != self.md.len() {
|
||||||
res.status(StatusCode::PARTIAL_CONTENT);
|
res.status(StatusCode::PARTIAL_CONTENT);
|
||||||
|
|
|
||||||
|
|
@ -294,16 +294,11 @@ mod tests {
|
||||||
|
|
||||||
let res = HttpRange::parse(header, size);
|
let res = HttpRange::parse(header, size);
|
||||||
|
|
||||||
if res.is_err() {
|
if let Err(err) = res {
|
||||||
if expected.is_empty() {
|
if expected.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
panic!(
|
panic!("parse({header}, {size}) returned error {err:?}");
|
||||||
"parse({}, {}) returned error {:?}",
|
|
||||||
header,
|
|
||||||
size,
|
|
||||||
res.unwrap_err()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ pub struct FilesServiceInner {
|
||||||
pub(crate) file_flags: named::Flags,
|
pub(crate) file_flags: named::Flags,
|
||||||
pub(crate) guards: Option<Rc<dyn Guard>>,
|
pub(crate) guards: Option<Rc<dyn Guard>>,
|
||||||
pub(crate) hidden_files: bool,
|
pub(crate) hidden_files: bool,
|
||||||
|
pub(crate) size_threshold: u64,
|
||||||
|
pub(crate) with_permanent_redirect: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for FilesServiceInner {
|
impl fmt::Debug for FilesServiceInner {
|
||||||
|
|
@ -70,7 +72,9 @@ impl FilesService {
|
||||||
named_file.flags = self.file_flags;
|
named_file.flags = self.file_flags;
|
||||||
|
|
||||||
let (req, _) = req.into_parts();
|
let (req, _) = req.into_parts();
|
||||||
let res = named_file.into_response(&req);
|
let res = named_file
|
||||||
|
.read_mode_threshold(self.size_threshold)
|
||||||
|
.into_response(&req);
|
||||||
ServiceResponse::new(req, res)
|
ServiceResponse::new(req, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,11 +149,15 @@ impl Service<ServiceRequest> for FilesService {
|
||||||
{
|
{
|
||||||
let redirect_to = format!("{}/", req.path());
|
let redirect_to = format!("{}/", req.path());
|
||||||
|
|
||||||
return Ok(req.into_response(
|
let response = if this.with_permanent_redirect {
|
||||||
HttpResponse::Found()
|
HttpResponse::PermanentRedirect()
|
||||||
.insert_header((header::LOCATION, redirect_to))
|
} else {
|
||||||
.finish(),
|
HttpResponse::TemporaryRedirect()
|
||||||
));
|
}
|
||||||
|
.insert_header((header::LOCATION, redirect_to))
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
return Ok(req.into_response(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
match this.index {
|
match this.index {
|
||||||
|
|
@ -169,17 +177,7 @@ impl Service<ServiceRequest> for FilesService {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match NamedFile::open_async(&path).await {
|
match NamedFile::open_async(&path).await {
|
||||||
Ok(mut named_file) => {
|
Ok(named_file) => Ok(this.serve_named_file(req, named_file)),
|
||||||
if let Some(ref mime_override) = this.mime_override {
|
|
||||||
let new_disposition = mime_override(&named_file.content_type.type_());
|
|
||||||
named_file.content_disposition.disposition = new_disposition;
|
|
||||||
}
|
|
||||||
named_file.flags = this.file_flags;
|
|
||||||
|
|
||||||
let (req, _) = req.into_parts();
|
|
||||||
let res = named_file.into_response(&req);
|
|
||||||
Ok(ServiceResponse::new(req, res))
|
|
||||||
}
|
|
||||||
Err(err) => this.handle_err(err, req).await,
|
Err(err) => this.handle_err(err, req).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.72.
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
## 3.2.0
|
## 3.2.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ serde = "1"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
serde_urlencoded = "0.7"
|
serde_urlencoded = "0.7"
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
socket2 = "0.5"
|
socket2 = "0.6"
|
||||||
tls-openssl = { version = "0.10.55", package = "openssl", optional = true }
|
tls-openssl = { version = "0.10.55", package = "openssl", optional = true }
|
||||||
tokio = { version = "1.38.2", features = ["sync"] }
|
tokio = { version = "1.38.2", features = ["sync"] }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-http-test)
|
[](https://crates.io/crates/actix-http-test)
|
||||||
[](https://docs.rs/actix-http-test/3.2.0)
|
[](https://docs.rs/actix-http-test/3.2.0)
|
||||||

|

|
||||||

|

|
||||||
<br>
|
<br>
|
||||||
[](https://deps.rs/crate/actix-http-test/3.2.0)
|
[](https://deps.rs/crate/actix-http-test/3.2.0)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
extern crate tls_openssl as openssl;
|
extern crate tls_openssl as openssl;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,21 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
|
## 3.11.2
|
||||||
|
|
||||||
|
- Properly wake Payload receivers when feeding errors or EOF.
|
||||||
|
- Add `ServiceConfigBuilder` type to facilitate future configuration extensions.
|
||||||
|
- Add a configuration option to allow/disallow half closed connections in HTTP/1. This defaults to allow, reverting the change made in 3.11.1.
|
||||||
|
- Shutdown connections when HTTP Responses are written without reading full Requests.
|
||||||
|
|
||||||
|
## 3.11.1
|
||||||
|
|
||||||
|
- Prevent more hangs after client disconnects.
|
||||||
|
- More malformed WebSocket frames are now gracefully rejected.
|
||||||
|
- Using `TestRequest::set_payload()` now sets a Content-Length header.
|
||||||
|
|
||||||
## 3.11.0
|
## 3.11.0
|
||||||
|
|
||||||
- Update `brotli` dependency to `8`.
|
- Update `brotli` dependency to `8`.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-http"
|
name = "actix-http"
|
||||||
version = "3.11.0"
|
version = "3.11.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
||||||
description = "HTTP types and services for the Actix ecosystem"
|
description = "HTTP types and services for the Actix ecosystem"
|
||||||
keywords = ["actix", "http", "framework", "async", "futures"]
|
keywords = ["actix", "http", "framework", "async", "futures"]
|
||||||
|
|
@ -17,7 +17,6 @@ edition.workspace = true
|
||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
|
||||||
features = [
|
features = [
|
||||||
"http2",
|
"http2",
|
||||||
"ws",
|
"ws",
|
||||||
|
|
@ -119,7 +118,7 @@ tokio-util = { version = "0.7", features = ["io", "codec"] }
|
||||||
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||||
|
|
||||||
# http2
|
# http2
|
||||||
h2 = { version = "0.3.26", optional = true }
|
h2 = { version = "0.3.27", optional = true }
|
||||||
|
|
||||||
# websockets
|
# websockets
|
||||||
base64 = { version = "0.22", optional = true }
|
base64 = { version = "0.22", optional = true }
|
||||||
|
|
@ -150,14 +149,14 @@ memchr = "2.4"
|
||||||
once_cell = "1.21"
|
once_cell = "1.21"
|
||||||
rcgen = "0.13"
|
rcgen = "0.13"
|
||||||
regex = "1.3"
|
regex = "1.3"
|
||||||
rustls-pemfile = "2"
|
rustls-pki-types = "1.13.1"
|
||||||
rustversion = "1"
|
rustversion = "1"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
static_assertions = "1"
|
static_assertions = "1"
|
||||||
tls-openssl = { package = "openssl", version = "0.10.55" }
|
tls-openssl = { package = "openssl", version = "0.10.55" }
|
||||||
tls-rustls_023 = { package = "rustls", version = "0.23" }
|
tls-rustls_023 = { package = "rustls", version = "0.23" }
|
||||||
tokio = { version = "1.38.2", features = ["net", "rt", "macros"] }
|
tokio = { version = "1.38.2", features = ["net", "rt", "macros", "sync"] }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-http)
|
[](https://crates.io/crates/actix-http)
|
||||||
[](https://docs.rs/actix-http/3.11.0)
|
[](https://docs.rs/actix-http/3.11.2)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-http/3.11.0)
|
[](https://deps.rs/crate/actix-http/3.11.2)
|
||||||
[](https://crates.io/crates/actix-http)
|
[](https://crates.io/crates/actix-http)
|
||||||
[](https://discord.gg/NWpN5mmg3x)
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,25 +45,14 @@ async fn main() -> io::Result<()> {
|
||||||
fn rustls_config() -> rustls::ServerConfig {
|
fn rustls_config() -> rustls::ServerConfig {
|
||||||
let rcgen::CertifiedKey { cert, key_pair } =
|
let rcgen::CertifiedKey { cert, key_pair } =
|
||||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||||
let cert_file = cert.pem();
|
let cert_chain = vec![cert.der().clone()];
|
||||||
let key_file = key_pair.serialize_pem();
|
let key_der = rustls_pki_types::PrivateKeyDer::Pkcs8(
|
||||||
|
rustls_pki_types::PrivatePkcs8KeyDer::from(key_pair.serialize_der()),
|
||||||
let cert_file = &mut io::BufReader::new(cert_file.as_bytes());
|
);
|
||||||
let key_file = &mut io::BufReader::new(key_file.as_bytes());
|
|
||||||
|
|
||||||
let cert_chain = rustls_pemfile::certs(cert_file)
|
|
||||||
.collect::<Result<Vec<_>, _>>()
|
|
||||||
.unwrap();
|
|
||||||
let mut keys = rustls_pemfile::pkcs8_private_keys(key_file)
|
|
||||||
.collect::<Result<Vec<_>, _>>()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut config = rustls::ServerConfig::builder()
|
let mut config = rustls::ServerConfig::builder()
|
||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_single_cert(
|
.with_single_cert(cert_chain, key_der)
|
||||||
cert_chain,
|
|
||||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
const H1_ALPN: &[u8] = b"http/1.1";
|
const H1_ALPN: &[u8] = b"http/1.1";
|
||||||
|
|
|
||||||
|
|
@ -82,29 +82,16 @@ impl Stream for Heartbeat {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tls_config() -> rustls::ServerConfig {
|
fn tls_config() -> rustls::ServerConfig {
|
||||||
use std::io::BufReader;
|
|
||||||
|
|
||||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
|
||||||
|
|
||||||
let rcgen::CertifiedKey { cert, key_pair } =
|
let rcgen::CertifiedKey { cert, key_pair } =
|
||||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||||
let cert_file = cert.pem();
|
let cert_chain = vec![cert.der().clone()];
|
||||||
let key_file = key_pair.serialize_pem();
|
let key_der = rustls_pki_types::PrivateKeyDer::Pkcs8(
|
||||||
|
rustls_pki_types::PrivatePkcs8KeyDer::from(key_pair.serialize_der()),
|
||||||
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 mut config = rustls::ServerConfig::builder()
|
let mut config = rustls::ServerConfig::builder()
|
||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_single_cert(
|
.with_single_cert(cert_chain, key_der)
|
||||||
cert_chain,
|
|
||||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
config.alpn_protocols.push(b"http/1.1".to_vec());
|
config.alpn_protocols.push(b"http/1.1".to_vec());
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
body::{BoxBody, MessageBody},
|
body::{BoxBody, MessageBody},
|
||||||
h1::{self, ExpectHandler, H1Service, UpgradeHandler},
|
h1::{self, ExpectHandler, H1Service, UpgradeHandler},
|
||||||
service::HttpService,
|
service::HttpService,
|
||||||
ConnectCallback, Extensions, KeepAlive, Request, Response, ServiceConfig,
|
ConnectCallback, Extensions, KeepAlive, Request, Response, ServiceConfigBuilder,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An HTTP service builder.
|
/// An HTTP service builder.
|
||||||
|
|
@ -19,6 +19,7 @@ pub struct HttpServiceBuilder<T, S, X = ExpectHandler, U = UpgradeHandler> {
|
||||||
client_disconnect_timeout: Duration,
|
client_disconnect_timeout: Duration,
|
||||||
secure: bool,
|
secure: bool,
|
||||||
local_addr: Option<net::SocketAddr>,
|
local_addr: Option<net::SocketAddr>,
|
||||||
|
h1_allow_half_closed: bool,
|
||||||
expect: X,
|
expect: X,
|
||||||
upgrade: Option<U>,
|
upgrade: Option<U>,
|
||||||
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
|
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
|
||||||
|
|
@ -40,6 +41,7 @@ where
|
||||||
client_disconnect_timeout: Duration::ZERO,
|
client_disconnect_timeout: Duration::ZERO,
|
||||||
secure: false,
|
secure: false,
|
||||||
local_addr: None,
|
local_addr: None,
|
||||||
|
h1_allow_half_closed: true,
|
||||||
|
|
||||||
// dispatcher parts
|
// dispatcher parts
|
||||||
expect: ExpectHandler,
|
expect: ExpectHandler,
|
||||||
|
|
@ -124,6 +126,18 @@ where
|
||||||
self.client_disconnect_timeout(dur)
|
self.client_disconnect_timeout(dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets whether HTTP/1 connections should support half-closures.
|
||||||
|
///
|
||||||
|
/// Clients can choose to shutdown their writer-side of the connection after completing their
|
||||||
|
/// request and while waiting for the server response. Setting this to `false` will cause the
|
||||||
|
/// server to abort the connection handling as soon as it detects an EOF from the client.
|
||||||
|
///
|
||||||
|
/// The default behavior is to allow, i.e. `true`
|
||||||
|
pub fn h1_allow_half_closed(mut self, allow: bool) -> Self {
|
||||||
|
self.h1_allow_half_closed = allow;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Provide service for `EXPECT: 100-Continue` support.
|
/// Provide service for `EXPECT: 100-Continue` support.
|
||||||
///
|
///
|
||||||
/// Service get called with request that contains `EXPECT` header.
|
/// Service get called with request that contains `EXPECT` header.
|
||||||
|
|
@ -142,6 +156,7 @@ where
|
||||||
client_disconnect_timeout: self.client_disconnect_timeout,
|
client_disconnect_timeout: self.client_disconnect_timeout,
|
||||||
secure: self.secure,
|
secure: self.secure,
|
||||||
local_addr: self.local_addr,
|
local_addr: self.local_addr,
|
||||||
|
h1_allow_half_closed: self.h1_allow_half_closed,
|
||||||
expect: expect.into_factory(),
|
expect: expect.into_factory(),
|
||||||
upgrade: self.upgrade,
|
upgrade: self.upgrade,
|
||||||
on_connect_ext: self.on_connect_ext,
|
on_connect_ext: self.on_connect_ext,
|
||||||
|
|
@ -166,6 +181,7 @@ where
|
||||||
client_disconnect_timeout: self.client_disconnect_timeout,
|
client_disconnect_timeout: self.client_disconnect_timeout,
|
||||||
secure: self.secure,
|
secure: self.secure,
|
||||||
local_addr: self.local_addr,
|
local_addr: self.local_addr,
|
||||||
|
h1_allow_half_closed: self.h1_allow_half_closed,
|
||||||
expect: self.expect,
|
expect: self.expect,
|
||||||
upgrade: Some(upgrade.into_factory()),
|
upgrade: Some(upgrade.into_factory()),
|
||||||
on_connect_ext: self.on_connect_ext,
|
on_connect_ext: self.on_connect_ext,
|
||||||
|
|
@ -195,13 +211,14 @@ where
|
||||||
S::InitError: fmt::Debug,
|
S::InitError: fmt::Debug,
|
||||||
S::Response: Into<Response<B>>,
|
S::Response: Into<Response<B>>,
|
||||||
{
|
{
|
||||||
let cfg = ServiceConfig::new(
|
let cfg = ServiceConfigBuilder::new()
|
||||||
self.keep_alive,
|
.keep_alive(self.keep_alive)
|
||||||
self.client_request_timeout,
|
.client_request_timeout(self.client_request_timeout)
|
||||||
self.client_disconnect_timeout,
|
.client_disconnect_timeout(self.client_disconnect_timeout)
|
||||||
self.secure,
|
.secure(self.secure)
|
||||||
self.local_addr,
|
.local_addr(self.local_addr)
|
||||||
);
|
.h1_allow_half_closed(self.h1_allow_half_closed)
|
||||||
|
.build();
|
||||||
|
|
||||||
H1Service::with_config(cfg, service.into_factory())
|
H1Service::with_config(cfg, service.into_factory())
|
||||||
.expect(self.expect)
|
.expect(self.expect)
|
||||||
|
|
@ -220,13 +237,14 @@ where
|
||||||
|
|
||||||
B: MessageBody + 'static,
|
B: MessageBody + 'static,
|
||||||
{
|
{
|
||||||
let cfg = ServiceConfig::new(
|
let cfg = ServiceConfigBuilder::new()
|
||||||
self.keep_alive,
|
.keep_alive(self.keep_alive)
|
||||||
self.client_request_timeout,
|
.client_request_timeout(self.client_request_timeout)
|
||||||
self.client_disconnect_timeout,
|
.client_disconnect_timeout(self.client_disconnect_timeout)
|
||||||
self.secure,
|
.secure(self.secure)
|
||||||
self.local_addr,
|
.local_addr(self.local_addr)
|
||||||
);
|
.h1_allow_half_closed(self.h1_allow_half_closed)
|
||||||
|
.build();
|
||||||
|
|
||||||
crate::h2::H2Service::with_config(cfg, service.into_factory())
|
crate::h2::H2Service::with_config(cfg, service.into_factory())
|
||||||
.on_connect_ext(self.on_connect_ext)
|
.on_connect_ext(self.on_connect_ext)
|
||||||
|
|
@ -242,13 +260,14 @@ where
|
||||||
|
|
||||||
B: MessageBody + 'static,
|
B: MessageBody + 'static,
|
||||||
{
|
{
|
||||||
let cfg = ServiceConfig::new(
|
let cfg = ServiceConfigBuilder::new()
|
||||||
self.keep_alive,
|
.keep_alive(self.keep_alive)
|
||||||
self.client_request_timeout,
|
.client_request_timeout(self.client_request_timeout)
|
||||||
self.client_disconnect_timeout,
|
.client_disconnect_timeout(self.client_disconnect_timeout)
|
||||||
self.secure,
|
.secure(self.secure)
|
||||||
self.local_addr,
|
.local_addr(self.local_addr)
|
||||||
);
|
.h1_allow_half_closed(self.h1_allow_half_closed)
|
||||||
|
.build();
|
||||||
|
|
||||||
HttpService::with_config(cfg, service.into_factory())
|
HttpService::with_config(cfg, service.into_factory())
|
||||||
.expect(self.expect)
|
.expect(self.expect)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
net,
|
net::SocketAddr,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
@ -8,8 +8,76 @@ use bytes::BytesMut;
|
||||||
|
|
||||||
use crate::{date::DateService, KeepAlive};
|
use crate::{date::DateService, KeepAlive};
|
||||||
|
|
||||||
|
/// A builder for creating a [`ServiceConfig`]
|
||||||
|
#[derive(Default, Debug)]
|
||||||
|
pub struct ServiceConfigBuilder {
|
||||||
|
inner: Inner,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ServiceConfigBuilder {
|
||||||
|
/// Creates a new, default, [`ServiceConfigBuilder`]
|
||||||
|
///
|
||||||
|
/// It uses the following default values:
|
||||||
|
///
|
||||||
|
/// - [`KeepAlive::default`] for the connection keep-alive setting
|
||||||
|
/// - 5 seconds for the client request timeout
|
||||||
|
/// - 0 seconds for the client shutdown timeout
|
||||||
|
/// - secure value of `false`
|
||||||
|
/// - [`None`] for the local address setting
|
||||||
|
/// - Allow for half closed HTTP/1 connections
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the `secure` attribute for this configuration
|
||||||
|
pub fn secure(mut self, secure: bool) -> Self {
|
||||||
|
self.inner.secure = secure;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the local address for this configuration
|
||||||
|
pub fn local_addr(mut self, local_addr: Option<SocketAddr>) -> Self {
|
||||||
|
self.inner.local_addr = local_addr;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets connection keep-alive setting
|
||||||
|
pub fn keep_alive(mut self, keep_alive: KeepAlive) -> Self {
|
||||||
|
self.inner.keep_alive = keep_alive;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the timeout for the client to finish sending the head of its first request
|
||||||
|
pub fn client_request_timeout(mut self, timeout: Duration) -> Self {
|
||||||
|
self.inner.client_request_timeout = timeout;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the timeout for cleanly disconnecting from the client after connection shutdown has
|
||||||
|
/// started
|
||||||
|
pub fn client_disconnect_timeout(mut self, timeout: Duration) -> Self {
|
||||||
|
self.inner.client_disconnect_timeout = timeout;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets whether HTTP/1 connections should support half-closures.
|
||||||
|
///
|
||||||
|
/// Clients can choose to shutdown their writer-side of the connection after completing their
|
||||||
|
/// request and while waiting for the server response. Setting this to `false` will cause the
|
||||||
|
/// server to abort the connection handling as soon as it detects an EOF from the client
|
||||||
|
pub fn h1_allow_half_closed(mut self, allow: bool) -> Self {
|
||||||
|
self.inner.h1_allow_half_closed = allow;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds a [`ServiceConfig`] from this [`ServiceConfigBuilder`] instance
|
||||||
|
pub fn build(self) -> ServiceConfig {
|
||||||
|
ServiceConfig(Rc::new(self.inner))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// HTTP service configuration.
|
/// HTTP service configuration.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ServiceConfig(Rc<Inner>);
|
pub struct ServiceConfig(Rc<Inner>);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -18,19 +86,22 @@ struct Inner {
|
||||||
client_request_timeout: Duration,
|
client_request_timeout: Duration,
|
||||||
client_disconnect_timeout: Duration,
|
client_disconnect_timeout: Duration,
|
||||||
secure: bool,
|
secure: bool,
|
||||||
local_addr: Option<std::net::SocketAddr>,
|
local_addr: Option<SocketAddr>,
|
||||||
date_service: DateService,
|
date_service: DateService,
|
||||||
|
h1_allow_half_closed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ServiceConfig {
|
impl Default for Inner {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new(
|
Self {
|
||||||
KeepAlive::default(),
|
keep_alive: KeepAlive::default(),
|
||||||
Duration::from_secs(5),
|
client_request_timeout: Duration::from_secs(5),
|
||||||
Duration::ZERO,
|
client_disconnect_timeout: Duration::ZERO,
|
||||||
false,
|
secure: false,
|
||||||
None,
|
local_addr: None,
|
||||||
)
|
date_service: DateService::new(),
|
||||||
|
h1_allow_half_closed: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,7 +112,7 @@ impl ServiceConfig {
|
||||||
client_request_timeout: Duration,
|
client_request_timeout: Duration,
|
||||||
client_disconnect_timeout: Duration,
|
client_disconnect_timeout: Duration,
|
||||||
secure: bool,
|
secure: bool,
|
||||||
local_addr: Option<net::SocketAddr>,
|
local_addr: Option<SocketAddr>,
|
||||||
) -> ServiceConfig {
|
) -> ServiceConfig {
|
||||||
ServiceConfig(Rc::new(Inner {
|
ServiceConfig(Rc::new(Inner {
|
||||||
keep_alive: keep_alive.normalize(),
|
keep_alive: keep_alive.normalize(),
|
||||||
|
|
@ -50,6 +121,7 @@ impl ServiceConfig {
|
||||||
secure,
|
secure,
|
||||||
local_addr,
|
local_addr,
|
||||||
date_service: DateService::new(),
|
date_service: DateService::new(),
|
||||||
|
h1_allow_half_closed: true,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +135,7 @@ impl ServiceConfig {
|
||||||
///
|
///
|
||||||
/// Returns `None` for connections via UDS (Unix Domain Socket).
|
/// Returns `None` for connections via UDS (Unix Domain Socket).
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn local_addr(&self) -> Option<net::SocketAddr> {
|
pub fn local_addr(&self) -> Option<SocketAddr> {
|
||||||
self.0.local_addr
|
self.0.local_addr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,6 +172,15 @@ impl ServiceConfig {
|
||||||
(timeout != Duration::ZERO).then(|| self.now() + timeout)
|
(timeout != Duration::ZERO).then(|| self.now() + timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether HTTP/1 connections should support half-closures.
|
||||||
|
///
|
||||||
|
/// Clients can choose to shutdown their writer-side of the connection after completing their
|
||||||
|
/// request and while waiting for the server response. If this configuration is `false`, the
|
||||||
|
/// server will abort the connection handling as soon as it detects an EOF from the client
|
||||||
|
pub fn h1_allow_half_closed(&self) -> bool {
|
||||||
|
self.0.h1_allow_half_closed
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn now(&self) -> Instant {
|
pub(crate) fn now(&self) -> Instant {
|
||||||
self.0.date_service.now()
|
self.0.date_service.now()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -386,7 +386,14 @@ where
|
||||||
let mut this = self.project();
|
let mut this = self.project();
|
||||||
this.state.set(match size {
|
this.state.set(match size {
|
||||||
BodySize::None | BodySize::Sized(0) => {
|
BodySize::None | BodySize::Sized(0) => {
|
||||||
this.flags.insert(Flags::FINISHED);
|
let payload_unfinished = this.payload.is_some();
|
||||||
|
|
||||||
|
if payload_unfinished {
|
||||||
|
this.flags.insert(Flags::SHUTDOWN | Flags::FINISHED);
|
||||||
|
} else {
|
||||||
|
this.flags.insert(Flags::FINISHED);
|
||||||
|
}
|
||||||
|
|
||||||
State::None
|
State::None
|
||||||
}
|
}
|
||||||
_ => State::SendPayload { body },
|
_ => State::SendPayload { body },
|
||||||
|
|
@ -404,7 +411,14 @@ where
|
||||||
let mut this = self.project();
|
let mut this = self.project();
|
||||||
this.state.set(match size {
|
this.state.set(match size {
|
||||||
BodySize::None | BodySize::Sized(0) => {
|
BodySize::None | BodySize::Sized(0) => {
|
||||||
this.flags.insert(Flags::FINISHED);
|
let payload_unfinished = this.payload.is_some();
|
||||||
|
|
||||||
|
if payload_unfinished {
|
||||||
|
this.flags.insert(Flags::SHUTDOWN | Flags::FINISHED);
|
||||||
|
} else {
|
||||||
|
this.flags.insert(Flags::FINISHED);
|
||||||
|
}
|
||||||
|
|
||||||
State::None
|
State::None
|
||||||
}
|
}
|
||||||
_ => State::SendErrorPayload { body },
|
_ => State::SendErrorPayload { body },
|
||||||
|
|
@ -503,10 +517,22 @@ where
|
||||||
Poll::Ready(None) => {
|
Poll::Ready(None) => {
|
||||||
this.codec.encode(Message::Chunk(None), this.write_buf)?;
|
this.codec.encode(Message::Chunk(None), this.write_buf)?;
|
||||||
|
|
||||||
|
// if we have not yet pipelined to the next request, then
|
||||||
|
// this.payload was the payload for the request we just finished
|
||||||
|
// responding to. We can check to see if we finished reading it
|
||||||
|
// yet, and if not, shutdown the connection.
|
||||||
|
let payload_unfinished = this.payload.is_some();
|
||||||
|
let not_pipelined = this.messages.is_empty();
|
||||||
|
|
||||||
// payload stream finished.
|
// payload stream finished.
|
||||||
// set state to None and handle next message
|
// set state to None and handle next message
|
||||||
this.state.set(State::None);
|
this.state.set(State::None);
|
||||||
this.flags.insert(Flags::FINISHED);
|
|
||||||
|
if not_pipelined && payload_unfinished {
|
||||||
|
this.flags.insert(Flags::SHUTDOWN | Flags::FINISHED);
|
||||||
|
} else {
|
||||||
|
this.flags.insert(Flags::FINISHED);
|
||||||
|
}
|
||||||
|
|
||||||
continue 'res;
|
continue 'res;
|
||||||
}
|
}
|
||||||
|
|
@ -542,10 +568,22 @@ where
|
||||||
Poll::Ready(None) => {
|
Poll::Ready(None) => {
|
||||||
this.codec.encode(Message::Chunk(None), this.write_buf)?;
|
this.codec.encode(Message::Chunk(None), this.write_buf)?;
|
||||||
|
|
||||||
// payload stream finished
|
// if we have not yet pipelined to the next request, then
|
||||||
|
// this.payload was the payload for the request we just finished
|
||||||
|
// responding to. We can check to see if we finished reading it
|
||||||
|
// yet, and if not, shutdown the connection.
|
||||||
|
let payload_unfinished = this.payload.is_some();
|
||||||
|
let not_pipelined = this.messages.is_empty();
|
||||||
|
|
||||||
|
// payload stream finished.
|
||||||
// set state to None and handle next message
|
// set state to None and handle next message
|
||||||
this.state.set(State::None);
|
this.state.set(State::None);
|
||||||
this.flags.insert(Flags::FINISHED);
|
|
||||||
|
if not_pipelined && payload_unfinished {
|
||||||
|
this.flags.insert(Flags::SHUTDOWN | Flags::FINISHED);
|
||||||
|
} else {
|
||||||
|
this.flags.insert(Flags::FINISHED);
|
||||||
|
}
|
||||||
|
|
||||||
continue 'res;
|
continue 'res;
|
||||||
}
|
}
|
||||||
|
|
@ -1181,8 +1219,16 @@ where
|
||||||
let inner_p = inner.as_mut().project();
|
let inner_p = inner.as_mut().project();
|
||||||
let state_is_none = inner_p.state.is_none();
|
let state_is_none = inner_p.state.is_none();
|
||||||
|
|
||||||
// read half is closed; we do not process any responses
|
// If the read-half is closed, we start the shutdown procedure if either is
|
||||||
if inner_p.flags.contains(Flags::READ_DISCONNECT) && state_is_none {
|
// true:
|
||||||
|
//
|
||||||
|
// - state is [`State::None`], which means that we're done with request
|
||||||
|
// processing, so if the client closed its writer-side it means that it won't
|
||||||
|
// send more requests.
|
||||||
|
// - The user requested to not allow half-closures
|
||||||
|
if inner_p.flags.contains(Flags::READ_DISCONNECT)
|
||||||
|
&& (!inner_p.config.h1_allow_half_closed() || state_is_none)
|
||||||
|
{
|
||||||
trace!("read half closed; start shutdown");
|
trace!("read half closed; start shutdown");
|
||||||
inner_p.flags.insert(Flags::SHUTDOWN);
|
inner_p.flags.insert(Flags::SHUTDOWN);
|
||||||
}
|
}
|
||||||
|
|
@ -1216,6 +1262,9 @@ where
|
||||||
inner_p.shutdown_timer,
|
inner_p.shutdown_timer,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if inner_p.flags.contains(Flags::SHUTDOWN) {
|
||||||
|
cx.waker().wake_by_ref();
|
||||||
|
}
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,10 @@
|
||||||
use std::{future::Future, str, task::Poll, time::Duration};
|
use std::{
|
||||||
|
future::Future,
|
||||||
|
pin::Pin,
|
||||||
|
str,
|
||||||
|
task::{Context, Poll},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use actix_codec::Framed;
|
use actix_codec::Framed;
|
||||||
use actix_rt::{pin, time::sleep};
|
use actix_rt::{pin, time::sleep};
|
||||||
|
|
@ -9,7 +15,7 @@ use futures_util::future::lazy;
|
||||||
|
|
||||||
use super::dispatcher::{Dispatcher, DispatcherState, DispatcherStateProj, Flags};
|
use super::dispatcher::{Dispatcher, DispatcherState, DispatcherStateProj, Flags};
|
||||||
use crate::{
|
use crate::{
|
||||||
body::MessageBody,
|
body::{BoxBody, MessageBody},
|
||||||
config::ServiceConfig,
|
config::ServiceConfig,
|
||||||
h1::{Codec, ExpectHandler, UpgradeHandler},
|
h1::{Codec, ExpectHandler, UpgradeHandler},
|
||||||
service::HttpFlow,
|
service::HttpFlow,
|
||||||
|
|
@ -17,6 +23,26 @@ use crate::{
|
||||||
Error, HttpMessage, KeepAlive, Method, OnConnectData, Request, Response, StatusCode,
|
Error, HttpMessage, KeepAlive, Method, OnConnectData, Request, Response, StatusCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct YieldService;
|
||||||
|
|
||||||
|
impl Service<Request> for YieldService {
|
||||||
|
type Response = Response<BoxBody>;
|
||||||
|
type Error = Response<BoxBody>;
|
||||||
|
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
|
||||||
|
|
||||||
|
actix_service::always_ready!();
|
||||||
|
|
||||||
|
fn call(&self, _: Request) -> Self::Future {
|
||||||
|
Box::pin(async {
|
||||||
|
// Yield twice because the dispatcher can poll the service twice per dispatcher's poll:
|
||||||
|
// once in `handle_request` and another in `poll_response`
|
||||||
|
actix_rt::task::yield_now().await;
|
||||||
|
actix_rt::task::yield_now().await;
|
||||||
|
Ok(Response::ok())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn find_slice(haystack: &[u8], needle: &[u8], from: usize) -> Option<usize> {
|
fn find_slice(haystack: &[u8], needle: &[u8], from: usize) -> Option<usize> {
|
||||||
memchr::memmem::find(&haystack[from..], needle)
|
memchr::memmem::find(&haystack[from..], needle)
|
||||||
}
|
}
|
||||||
|
|
@ -509,6 +535,73 @@ async fn pipelining_ok_then_ok() {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn early_response_with_payload_closes_connection() {
|
||||||
|
lazy(|cx| {
|
||||||
|
let buf = TestBuffer::new(
|
||||||
|
"\
|
||||||
|
GET /unfinished HTTP/1.1\r\n\
|
||||||
|
Content-Length: 2\r\n\
|
||||||
|
\r\n\
|
||||||
|
",
|
||||||
|
);
|
||||||
|
|
||||||
|
let cfg = ServiceConfig::new(
|
||||||
|
KeepAlive::Os,
|
||||||
|
Duration::from_millis(1),
|
||||||
|
Duration::from_millis(1),
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
|
let services = HttpFlow::new(echo_path_service(), ExpectHandler, None);
|
||||||
|
|
||||||
|
let h1 = Dispatcher::<_, _, _, _, UpgradeHandler>::new(
|
||||||
|
buf.clone(),
|
||||||
|
services,
|
||||||
|
cfg,
|
||||||
|
None,
|
||||||
|
OnConnectData::default(),
|
||||||
|
);
|
||||||
|
|
||||||
|
pin!(h1);
|
||||||
|
|
||||||
|
assert!(matches!(&h1.inner, DispatcherState::Normal { .. }));
|
||||||
|
|
||||||
|
match h1.as_mut().poll(cx) {
|
||||||
|
Poll::Pending => panic!("Should have shut down"),
|
||||||
|
Poll::Ready(res) => assert!(res.is_ok()),
|
||||||
|
}
|
||||||
|
|
||||||
|
// polls: initial => shutdown
|
||||||
|
assert_eq!(h1.poll_count, 2);
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut res = buf.write_buf_slice_mut();
|
||||||
|
stabilize_date_header(&mut res);
|
||||||
|
let res = &res[..];
|
||||||
|
|
||||||
|
let exp = b"\
|
||||||
|
HTTP/1.1 200 OK\r\n\
|
||||||
|
content-length: 11\r\n\
|
||||||
|
date: Thu, 01 Jan 1970 12:34:56 UTC\r\n\r\n\
|
||||||
|
/unfinished\
|
||||||
|
";
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
exp,
|
||||||
|
"\nexpected response not in write buffer:\n\
|
||||||
|
response: {:?}\n\
|
||||||
|
expected: {:?}",
|
||||||
|
String::from_utf8_lossy(res),
|
||||||
|
String::from_utf8_lossy(exp)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn pipelining_ok_then_bad() {
|
async fn pipelining_ok_then_bad() {
|
||||||
lazy(|cx| {
|
lazy(|cx| {
|
||||||
|
|
@ -924,6 +1017,91 @@ async fn handler_drop_payload() {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn allow_half_closed() {
|
||||||
|
let buf = TestSeqBuffer::new(http_msg("GET / HTTP/1.1"));
|
||||||
|
buf.close_read();
|
||||||
|
let services = HttpFlow::new(YieldService, ExpectHandler, None::<UpgradeHandler>);
|
||||||
|
|
||||||
|
let mut cx = Context::from_waker(futures_util::task::noop_waker_ref());
|
||||||
|
let disptacher = Dispatcher::new(
|
||||||
|
buf.clone(),
|
||||||
|
services,
|
||||||
|
ServiceConfig::default(),
|
||||||
|
None,
|
||||||
|
OnConnectData::default(),
|
||||||
|
);
|
||||||
|
pin!(disptacher);
|
||||||
|
|
||||||
|
assert!(disptacher.as_mut().poll(&mut cx).is_pending());
|
||||||
|
assert_eq!(disptacher.poll_count, 1);
|
||||||
|
|
||||||
|
assert!(disptacher.as_mut().poll(&mut cx).is_ready());
|
||||||
|
assert_eq!(disptacher.poll_count, 3);
|
||||||
|
|
||||||
|
let mut res = BytesMut::from(buf.take_write_buf().as_ref());
|
||||||
|
stabilize_date_header(&mut res);
|
||||||
|
let exp = http_msg(
|
||||||
|
r"
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
content-length: 0
|
||||||
|
date: Thu, 01 Jan 1970 12:34:56 UTC
|
||||||
|
",
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
exp,
|
||||||
|
"\nexpected response not in write buffer:\n\
|
||||||
|
response: {:?}\n\
|
||||||
|
expected: {:?}",
|
||||||
|
String::from_utf8_lossy(&res),
|
||||||
|
String::from_utf8_lossy(&exp)
|
||||||
|
);
|
||||||
|
|
||||||
|
let DispatcherStateProj::Normal { inner } = disptacher.as_mut().project().inner.project()
|
||||||
|
else {
|
||||||
|
panic!("End dispatcher state should be Normal");
|
||||||
|
};
|
||||||
|
assert!(inner.state.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn disallow_half_closed() {
|
||||||
|
use crate::{config::ServiceConfigBuilder, h1::dispatcher::State};
|
||||||
|
|
||||||
|
let buf = TestSeqBuffer::new(http_msg("GET / HTTP/1.1"));
|
||||||
|
buf.close_read();
|
||||||
|
let services = HttpFlow::new(YieldService, ExpectHandler, None::<UpgradeHandler>);
|
||||||
|
let config = ServiceConfigBuilder::new()
|
||||||
|
.h1_allow_half_closed(false)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
let mut cx = Context::from_waker(futures_util::task::noop_waker_ref());
|
||||||
|
let disptacher = Dispatcher::new(
|
||||||
|
buf.clone(),
|
||||||
|
services,
|
||||||
|
config,
|
||||||
|
None,
|
||||||
|
OnConnectData::default(),
|
||||||
|
);
|
||||||
|
pin!(disptacher);
|
||||||
|
|
||||||
|
assert!(disptacher.as_mut().poll(&mut cx).is_pending());
|
||||||
|
assert_eq!(disptacher.poll_count, 1);
|
||||||
|
|
||||||
|
assert!(disptacher.as_mut().poll(&mut cx).is_ready());
|
||||||
|
assert_eq!(disptacher.poll_count, 2);
|
||||||
|
|
||||||
|
let res = BytesMut::from(buf.take_write_buf().as_ref());
|
||||||
|
assert!(res.is_empty());
|
||||||
|
|
||||||
|
let DispatcherStateProj::Normal { inner } = disptacher.as_mut().project().inner.project()
|
||||||
|
else {
|
||||||
|
panic!("End dispatcher state should be Normal");
|
||||||
|
};
|
||||||
|
assert!(matches!(inner.state, State::ServiceCall { .. }))
|
||||||
|
}
|
||||||
|
|
||||||
fn http_msg(msg: impl AsRef<str>) -> BytesMut {
|
fn http_msg(msg: impl AsRef<str>) -> BytesMut {
|
||||||
let mut msg = msg
|
let mut msg = msg
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
|
||||||
|
|
@ -176,11 +176,7 @@ impl Inner {
|
||||||
/// Register future waiting data from payload.
|
/// Register future waiting data from payload.
|
||||||
/// Waker would be used in `Inner::wake`
|
/// Waker would be used in `Inner::wake`
|
||||||
fn register(&mut self, cx: &Context<'_>) {
|
fn register(&mut self, cx: &Context<'_>) {
|
||||||
if self
|
if self.task.as_ref().is_none_or(|w| !cx.waker().will_wake(w)) {
|
||||||
.task
|
|
||||||
.as_ref()
|
|
||||||
.map_or(true, |w| !cx.waker().will_wake(w))
|
|
||||||
{
|
|
||||||
self.task = Some(cx.waker().clone());
|
self.task = Some(cx.waker().clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +187,7 @@ impl Inner {
|
||||||
if self
|
if self
|
||||||
.io_task
|
.io_task
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(true, |w| !cx.waker().will_wake(w))
|
.is_none_or(|w| !cx.waker().will_wake(w))
|
||||||
{
|
{
|
||||||
self.io_task = Some(cx.waker().clone());
|
self.io_task = Some(cx.waker().clone());
|
||||||
}
|
}
|
||||||
|
|
@ -200,11 +196,13 @@ impl Inner {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn set_error(&mut self, err: PayloadError) {
|
fn set_error(&mut self, err: PayloadError) {
|
||||||
self.err = Some(err);
|
self.err = Some(err);
|
||||||
|
self.wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn feed_eof(&mut self) {
|
fn feed_eof(&mut self) {
|
||||||
self.eof = true;
|
self.eof = true;
|
||||||
|
self.wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -253,8 +251,13 @@ impl Inner {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::{task::Poll, time::Duration};
|
||||||
|
|
||||||
|
use actix_rt::time::timeout;
|
||||||
use actix_utils::future::poll_fn;
|
use actix_utils::future::poll_fn;
|
||||||
|
use futures_util::{FutureExt, StreamExt};
|
||||||
use static_assertions::{assert_impl_all, assert_not_impl_any};
|
use static_assertions::{assert_impl_all, assert_not_impl_any};
|
||||||
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
@ -263,6 +266,67 @@ mod tests {
|
||||||
|
|
||||||
assert_impl_all!(Inner: Unpin, Send, Sync);
|
assert_impl_all!(Inner: Unpin, Send, Sync);
|
||||||
|
|
||||||
|
const WAKE_TIMEOUT: Duration = Duration::from_secs(2);
|
||||||
|
|
||||||
|
fn prepare_waking_test(
|
||||||
|
mut payload: Payload,
|
||||||
|
expected: Option<Result<(), ()>>,
|
||||||
|
) -> (oneshot::Receiver<()>, actix_rt::task::JoinHandle<()>) {
|
||||||
|
let (tx, rx) = oneshot::channel();
|
||||||
|
|
||||||
|
let handle = actix_rt::spawn(async move {
|
||||||
|
// Make sure to poll once to set the waker
|
||||||
|
poll_fn(|cx| {
|
||||||
|
assert!(payload.poll_next_unpin(cx).is_pending());
|
||||||
|
Poll::Ready(())
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
tx.send(()).unwrap();
|
||||||
|
|
||||||
|
// actix-rt is single-threaded, so this won't race with `rx.await`
|
||||||
|
let mut pend_once = false;
|
||||||
|
poll_fn(|_| {
|
||||||
|
if pend_once {
|
||||||
|
Poll::Ready(())
|
||||||
|
} else {
|
||||||
|
// Return pending without storing wakers, we already did on the previous
|
||||||
|
// `poll_fn`, now this task will only continue if the `sender` wakes us
|
||||||
|
pend_once = true;
|
||||||
|
Poll::Pending
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let got = payload.next().now_or_never().unwrap();
|
||||||
|
match expected {
|
||||||
|
Some(Ok(_)) => assert!(got.unwrap().is_ok()),
|
||||||
|
Some(Err(_)) => assert!(got.unwrap().is_err()),
|
||||||
|
None => assert!(got.is_none()),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
(rx, handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn wake_on_error() {
|
||||||
|
let (mut sender, payload) = Payload::create(false);
|
||||||
|
let (rx, handle) = prepare_waking_test(payload, Some(Err(())));
|
||||||
|
|
||||||
|
rx.await.unwrap();
|
||||||
|
sender.set_error(PayloadError::Incomplete(None));
|
||||||
|
timeout(WAKE_TIMEOUT, handle).await.unwrap().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn wake_on_eof() {
|
||||||
|
let (mut sender, payload) = Payload::create(false);
|
||||||
|
let (rx, handle) = prepare_waking_test(payload, None);
|
||||||
|
|
||||||
|
rx.await.unwrap();
|
||||||
|
sender.feed_eof();
|
||||||
|
timeout(WAKE_TIMEOUT, handle).await.unwrap().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_unread_data() {
|
async fn test_unread_data() {
|
||||||
let (_, mut payload) = Payload::create(false);
|
let (_, mut payload) = Payload::create(false);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
)]
|
)]
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
pub use http::{uri, uri::Uri, Method, StatusCode, Version};
|
pub use http::{uri, uri::Uri, Method, StatusCode, Version};
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ pub use self::payload::PayloadStream;
|
||||||
pub use self::service::TlsAcceptorConfig;
|
pub use self::service::TlsAcceptorConfig;
|
||||||
pub use self::{
|
pub use self::{
|
||||||
builder::HttpServiceBuilder,
|
builder::HttpServiceBuilder,
|
||||||
config::ServiceConfig,
|
config::{ServiceConfig, ServiceConfigBuilder},
|
||||||
error::Error,
|
error::Error,
|
||||||
extensions::Extensions,
|
extensions::Extensions,
|
||||||
header::ContentEncoding,
|
header::ContentEncoding,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use std::{
|
||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite, ReadBuf};
|
use actix_codec::{AsyncRead, AsyncWrite, ReadBuf};
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use http::{Method, Uri, Version};
|
use http::{header, Method, Uri, Version};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
header::{HeaderMap, TryIntoHeaderPair},
|
header::{HeaderMap, TryIntoHeaderPair},
|
||||||
|
|
@ -98,9 +98,13 @@ impl TestRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set request payload.
|
/// Set request payload.
|
||||||
|
///
|
||||||
|
/// This sets the `Content-Length` header with the size of `data`.
|
||||||
pub fn set_payload(&mut self, data: impl Into<Bytes>) -> &mut Self {
|
pub fn set_payload(&mut self, data: impl Into<Bytes>) -> &mut Self {
|
||||||
let mut payload = crate::h1::Payload::empty();
|
let mut payload = crate::h1::Payload::empty();
|
||||||
payload.unread_data(data.into());
|
let bytes = data.into();
|
||||||
|
self.insert_header((header::CONTENT_LENGTH, bytes.len()));
|
||||||
|
payload.unread_data(bytes);
|
||||||
parts(&mut self.0).payload = Some(payload.into());
|
parts(&mut self.0).payload = Some(payload.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
@ -271,6 +275,7 @@ impl TestSeqBuffer {
|
||||||
{
|
{
|
||||||
Self(Rc::new(RefCell::new(TestSeqInner {
|
Self(Rc::new(RefCell::new(TestSeqInner {
|
||||||
read_buf: data.into(),
|
read_buf: data.into(),
|
||||||
|
read_closed: false,
|
||||||
write_buf: BytesMut::new(),
|
write_buf: BytesMut::new(),
|
||||||
err: None,
|
err: None,
|
||||||
})))
|
})))
|
||||||
|
|
@ -289,36 +294,59 @@ impl TestSeqBuffer {
|
||||||
Ref::map(self.0.borrow(), |inner| &inner.write_buf)
|
Ref::map(self.0.borrow(), |inner| &inner.write_buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn take_write_buf(&self) -> Bytes {
|
||||||
|
self.0.borrow_mut().write_buf.split().freeze()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn err(&self) -> Ref<'_, Option<io::Error>> {
|
pub fn err(&self) -> Ref<'_, Option<io::Error>> {
|
||||||
Ref::map(self.0.borrow(), |inner| &inner.err)
|
Ref::map(self.0.borrow(), |inner| &inner.err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add data to read buffer.
|
/// Add data to read buffer.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if called after [`TestSeqBuffer::close_read`] has been called
|
||||||
pub fn extend_read_buf<T: AsRef<[u8]>>(&mut self, data: T) {
|
pub fn extend_read_buf<T: AsRef<[u8]>>(&mut self, data: T) {
|
||||||
self.0
|
let mut inner = self.0.borrow_mut();
|
||||||
.borrow_mut()
|
if inner.read_closed {
|
||||||
.read_buf
|
panic!("Tried to extend the read buffer after calling close_read");
|
||||||
.extend_from_slice(data.as_ref())
|
}
|
||||||
|
|
||||||
|
inner.read_buf.extend_from_slice(data.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Closes the [`AsyncRead`]/[`Read`] part of this test buffer.
|
||||||
|
///
|
||||||
|
/// The current data in the buffer will still be returned by a call to read/poll_read, however,
|
||||||
|
/// after the buffer is empty, it will return `Ok(0)` to signify the EOF condition
|
||||||
|
pub fn close_read(&self) {
|
||||||
|
self.0.borrow_mut().read_closed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestSeqInner {
|
pub struct TestSeqInner {
|
||||||
read_buf: BytesMut,
|
read_buf: BytesMut,
|
||||||
|
read_closed: bool,
|
||||||
write_buf: BytesMut,
|
write_buf: BytesMut,
|
||||||
err: Option<io::Error>,
|
err: Option<io::Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl io::Read for TestSeqBuffer {
|
impl io::Read for TestSeqBuffer {
|
||||||
fn read(&mut self, dst: &mut [u8]) -> Result<usize, io::Error> {
|
fn read(&mut self, dst: &mut [u8]) -> Result<usize, io::Error> {
|
||||||
if self.0.borrow().read_buf.is_empty() {
|
let mut inner = self.0.borrow_mut();
|
||||||
if self.0.borrow().err.is_some() {
|
|
||||||
Err(self.0.borrow_mut().err.take().unwrap())
|
if inner.read_buf.is_empty() {
|
||||||
|
if let Some(err) = inner.err.take() {
|
||||||
|
Err(err)
|
||||||
|
} else if inner.read_closed {
|
||||||
|
Ok(0)
|
||||||
} else {
|
} else {
|
||||||
Err(io::Error::new(io::ErrorKind::WouldBlock, ""))
|
Err(io::Error::new(io::ErrorKind::WouldBlock, ""))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let size = std::cmp::min(self.0.borrow().read_buf.len(), dst.len());
|
let size = std::cmp::min(inner.read_buf.len(), dst.len());
|
||||||
let b = self.0.borrow_mut().read_buf.split_to(size);
|
let b = inner.read_buf.split_to(size);
|
||||||
dst[..size].copy_from_slice(&b);
|
dst[..size].copy_from_slice(&b);
|
||||||
Ok(size)
|
Ok(size)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,11 +94,21 @@ impl Parser {
|
||||||
Some(res) => res,
|
Some(res) => res,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let frame_len = match idx.checked_add(length) {
|
||||||
|
Some(len) => len,
|
||||||
|
None => return Err(ProtocolError::Overflow),
|
||||||
|
};
|
||||||
|
|
||||||
// not enough data
|
// not enough data
|
||||||
if src.len() < idx + length {
|
if src.len() < frame_len {
|
||||||
let min_length = min(length, max_size);
|
let min_length = min(length, max_size);
|
||||||
if src.capacity() < idx + min_length {
|
let required_cap = match idx.checked_add(min_length) {
|
||||||
src.reserve(idx + min_length - src.capacity());
|
Some(cap) => cap,
|
||||||
|
None => return Err(ProtocolError::Overflow),
|
||||||
|
};
|
||||||
|
|
||||||
|
if src.capacity() < required_cap {
|
||||||
|
src.reserve(required_cap - src.capacity());
|
||||||
}
|
}
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
@ -402,4 +412,14 @@ mod tests {
|
||||||
Parser::write_close(&mut buf, None, false);
|
Parser::write_close(&mut buf, None, false);
|
||||||
assert_eq!(&buf[..], &vec![0x88, 0x00][..]);
|
assert_eq!(&buf[..], &vec![0x88, 0x00][..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_length_overflow() {
|
||||||
|
let buf: [u8; 14] = [
|
||||||
|
0x0a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xeb, 0x0e, 0x8f,
|
||||||
|
];
|
||||||
|
let mut buf = BytesMut::from(&buf[..]);
|
||||||
|
let result = Parser::parse(&mut buf, true, 65536);
|
||||||
|
assert!(matches!(result, Err(ProtocolError::Overflow)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ extern crate tls_rustls_023 as rustls;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
io::{self, BufReader, Write},
|
io::{self, Write},
|
||||||
net::{SocketAddr, TcpStream as StdTcpStream},
|
net::{SocketAddr, TcpStream as StdTcpStream},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
task::Poll,
|
task::Poll,
|
||||||
|
|
@ -27,7 +27,7 @@ use derive_more::{Display, Error};
|
||||||
use futures_core::{ready, Stream};
|
use futures_core::{ready, Stream};
|
||||||
use futures_util::stream::once;
|
use futures_util::stream::once;
|
||||||
use rustls::{pki_types::ServerName, ServerConfig as RustlsServerConfig};
|
use rustls::{pki_types::ServerName, ServerConfig as RustlsServerConfig};
|
||||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
use rustls_pki_types::{PrivateKeyDer, PrivatePkcs8KeyDer};
|
||||||
|
|
||||||
async fn load_body<S>(stream: S) -> Result<BytesMut, PayloadError>
|
async fn load_body<S>(stream: S) -> Result<BytesMut, PayloadError>
|
||||||
where
|
where
|
||||||
|
|
@ -54,23 +54,12 @@ where
|
||||||
fn tls_config() -> RustlsServerConfig {
|
fn tls_config() -> RustlsServerConfig {
|
||||||
let rcgen::CertifiedKey { cert, key_pair } =
|
let rcgen::CertifiedKey { cert, key_pair } =
|
||||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||||
let cert_file = cert.pem();
|
let cert_chain = vec![cert.der().clone()];
|
||||||
let key_file = key_pair.serialize_pem();
|
let key_der = PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key_pair.serialize_der()));
|
||||||
|
|
||||||
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 mut config = RustlsServerConfig::builder()
|
let mut config = RustlsServerConfig::builder()
|
||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_single_cert(
|
.with_single_cert(cert_chain, key_der)
|
||||||
cert_chain,
|
|
||||||
rustls::pki_types::PrivateKeyDer::Pkcs8(keys.remove(0)),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
config.alpn_protocols.push(HTTP1_1_ALPN_PROTOCOL.to_vec());
|
config.alpn_protocols.push(HTTP1_1_ALPN_PROTOCOL.to_vec());
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
## 0.7.0
|
## 0.7.0
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.72.
|
- Minimum supported Rust version (MSRV) is now 1.72.
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ edition.workspace = true
|
||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
|
||||||
all-features = true
|
all-features = true
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-multipart-derive)
|
[](https://crates.io/crates/actix-multipart-derive)
|
||||||
[](https://docs.rs/actix-multipart-derive/0.7.0)
|
[](https://docs.rs/actix-multipart-derive/0.7.0)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-multipart-derive/0.7.0)
|
[](https://deps.rs/crate/actix-multipart-derive/0.7.0)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
#![allow(clippy::disallowed_names)] // false positives in some macro expansions
|
#![allow(clippy::disallowed_names)] // false positives in some macro expansions
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
@ -16,19 +16,14 @@ use proc_macro2::Ident;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{parse_macro_input, Type};
|
use syn::{parse_macro_input, Type};
|
||||||
|
|
||||||
#[derive(FromMeta)]
|
#[derive(Default, FromMeta)]
|
||||||
enum DuplicateField {
|
enum DuplicateField {
|
||||||
|
#[default]
|
||||||
Ignore,
|
Ignore,
|
||||||
Deny,
|
Deny,
|
||||||
Replace,
|
Replace,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DuplicateField {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(FromDeriveInput, Default)]
|
#[derive(FromDeriveInput, Default)]
|
||||||
#[darling(attributes(multipart), default)]
|
#[darling(attributes(multipart), default)]
|
||||||
struct MultipartFormAttrs {
|
struct MultipartFormAttrs {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
error: Could not parse size limit `2 bytes`: couldn't parse "bytes" into a known SI unit, couldn't parse unit of "bytes"
|
error: Could not parse size limit `2 bytes`: couldn't parse "bytes" into a known SI unit, Failed to parse unit "byt..."
|
||||||
--> tests/trybuild/size-limit-parse-fail.rs:6:5
|
--> tests/trybuild/size-limit-parse-fail.rs:6:5
|
||||||
|
|
|
|
||||||
6 | description: Text<String>,
|
6 | description: Text<String>,
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
error: Could not parse size limit `2 megabytes`: couldn't parse "megabytes" into a known SI unit, couldn't parse unit of "megabytes"
|
error: Could not parse size limit `2 megabytes`: couldn't parse "megabytes" into a known SI unit, Failed to parse unit "meg..."
|
||||||
--> tests/trybuild/size-limit-parse-fail.rs:12:5
|
--> tests/trybuild/size-limit-parse-fail.rs:12:5
|
||||||
|
|
|
|
||||||
12 | description: Text<String>,
|
12 | description: Text<String>,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
- Minimum supported Rust version (MSRV) is now 1.75.
|
- Add `MultipartForm` support for `Option<Vec<T>>` fields. [#3577]
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
|
[#3577]: https://github.com/actix/actix-web/pull/3577
|
||||||
|
|
||||||
## 0.7.2
|
## 0.7.2
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ license.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
|
||||||
all-features = true
|
all-features = true
|
||||||
|
|
||||||
[package.metadata.cargo_check_external_types]
|
[package.metadata.cargo_check_external_types]
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-multipart)
|
[](https://crates.io/crates/actix-multipart)
|
||||||
[](https://docs.rs/actix-multipart/0.7.2)
|
[](https://docs.rs/actix-multipart/0.7.2)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-multipart/0.7.2)
|
[](https://deps.rs/crate/actix-multipart/0.7.2)
|
||||||
|
|
@ -24,9 +24,10 @@ Due to additional requirements for `multipart/form-data` requests, the higher le
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use actix_web::{post, App, HttpServer, Responder};
|
use actix_multipart::form::{
|
||||||
|
json::Json as MpJson, tempfile::TempFile, MultipartForm, MultipartFormConfig,
|
||||||
use actix_multipart::form::{json::Json as MpJson, tempfile::TempFile, MultipartForm};
|
};
|
||||||
|
use actix_web::{middleware::Logger, post, App, HttpServer, Responder};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
@ -36,25 +37,37 @@ struct Metadata {
|
||||||
|
|
||||||
#[derive(Debug, MultipartForm)]
|
#[derive(Debug, MultipartForm)]
|
||||||
struct UploadForm {
|
struct UploadForm {
|
||||||
|
// Note: the form is also subject to the global limits configured using `MultipartFormConfig`.
|
||||||
#[multipart(limit = "100MB")]
|
#[multipart(limit = "100MB")]
|
||||||
file: TempFile,
|
file: TempFile,
|
||||||
json: MpJson<Metadata>,
|
json: MpJson<Metadata>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/videos")]
|
#[post("/videos")]
|
||||||
pub async fn post_video(MultipartForm(form): MultipartForm<UploadForm>) -> impl Responder {
|
async fn post_video(MultipartForm(form): MultipartForm<UploadForm>) -> impl Responder {
|
||||||
format!(
|
format!(
|
||||||
"Uploaded file {}, with size: {}",
|
"Uploaded file {}, with size: {}\ntemporary file ({}) was deleted\n",
|
||||||
form.json.name, form.file.size
|
form.json.name,
|
||||||
|
form.file.size,
|
||||||
|
form.file.file.path().display(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(move || App::new().service(post_video))
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
.bind(("127.0.0.1", 8080))?
|
|
||||||
.run()
|
HttpServer::new(move || {
|
||||||
.await
|
App::new()
|
||||||
|
.service(post_video)
|
||||||
|
.wrap(Logger::default())
|
||||||
|
// Also increase the global total limit to 100MiB.
|
||||||
|
.app_data(MultipartFormConfig::default().total_limit(100 * 1024 * 1024))
|
||||||
|
})
|
||||||
|
.workers(2)
|
||||||
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -71,4 +84,4 @@ curl -v --request POST \
|
||||||
|
|
||||||
<!-- cargo-rdme end -->
|
<!-- cargo-rdme end -->
|
||||||
|
|
||||||
[More available in the examples repo →](https://github.com/actix/examples/tree/master/forms/multipart)
|
[More available in the examples repo →](https://github.com/actix/examples/tree/main/forms/multipart)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
use actix_multipart::form::{json::Json as MpJson, tempfile::TempFile, MultipartForm};
|
use actix_multipart::form::{
|
||||||
|
json::Json as MpJson, tempfile::TempFile, MultipartForm, MultipartFormConfig,
|
||||||
|
};
|
||||||
use actix_web::{middleware::Logger, post, App, HttpServer, Responder};
|
use actix_web::{middleware::Logger, post, App, HttpServer, Responder};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
@ -9,6 +11,7 @@ struct Metadata {
|
||||||
|
|
||||||
#[derive(Debug, MultipartForm)]
|
#[derive(Debug, MultipartForm)]
|
||||||
struct UploadForm {
|
struct UploadForm {
|
||||||
|
// Note: the form is also subject to the global limits configured using `MultipartFormConfig`.
|
||||||
#[multipart(limit = "100MB")]
|
#[multipart(limit = "100MB")]
|
||||||
file: TempFile,
|
file: TempFile,
|
||||||
json: MpJson<Metadata>,
|
json: MpJson<Metadata>,
|
||||||
|
|
@ -28,9 +31,15 @@ async fn post_video(MultipartForm(form): MultipartForm<UploadForm>) -> impl Resp
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
|
|
||||||
HttpServer::new(move || App::new().service(post_video).wrap(Logger::default()))
|
HttpServer::new(move || {
|
||||||
.workers(2)
|
App::new()
|
||||||
.bind(("127.0.0.1", 8080))?
|
.service(post_video)
|
||||||
.run()
|
.wrap(Logger::default())
|
||||||
.await
|
// Also increase the global total limit to 100MiB.
|
||||||
|
.app_data(MultipartFormConfig::default().total_limit(100 * 1024 * 1024))
|
||||||
|
})
|
||||||
|
.workers(2)
|
||||||
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,45 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'t, T> FieldGroupReader<'t> for Option<Vec<T>>
|
||||||
|
where
|
||||||
|
T: FieldReader<'t>,
|
||||||
|
{
|
||||||
|
type Future = LocalBoxFuture<'t, Result<(), MultipartError>>;
|
||||||
|
|
||||||
|
fn handle_field(
|
||||||
|
req: &'t HttpRequest,
|
||||||
|
field: Field,
|
||||||
|
limits: &'t mut Limits,
|
||||||
|
state: &'t mut State,
|
||||||
|
_duplicate_field: DuplicateField,
|
||||||
|
) -> Self::Future {
|
||||||
|
let field_name = field.name().unwrap().to_string();
|
||||||
|
|
||||||
|
Box::pin(async move {
|
||||||
|
let vec = state
|
||||||
|
.entry(field_name)
|
||||||
|
.or_insert_with(|| Box::<Vec<T>>::default())
|
||||||
|
.downcast_mut::<Vec<T>>()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let item = T::read_field(req, field, limits).await?;
|
||||||
|
vec.push(item);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_state(name: &str, state: &'t mut State) -> Result<Self, MultipartError> {
|
||||||
|
if let Some(boxed_vec) = state.remove(name) {
|
||||||
|
let vec = *boxed_vec.downcast::<Vec<T>>().unwrap();
|
||||||
|
Ok(Some(vec))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Trait that allows a type to be used in the [`struct@MultipartForm`] extractor.
|
/// Trait that allows a type to be used in the [`struct@MultipartForm`] extractor.
|
||||||
///
|
///
|
||||||
/// You should use the [`macro@MultipartForm`] macro to derive this for your struct.
|
/// You should use the [`macro@MultipartForm`] macro to derive this for your struct.
|
||||||
|
|
@ -506,6 +545,40 @@ mod tests {
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test `Option<Vec>` fields.
|
||||||
|
#[derive(MultipartForm)]
|
||||||
|
struct TestOptionVec {
|
||||||
|
list1: Option<Vec<Text<String>>>,
|
||||||
|
list2: Option<Vec<Text<String>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn test_option_vec_route(form: MultipartForm<TestOptionVec>) -> impl Responder {
|
||||||
|
let form = form.into_inner();
|
||||||
|
let strings = form
|
||||||
|
.list1
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| s.into_inner())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
assert_eq!(strings, vec!["value1", "value2", "value3"]);
|
||||||
|
assert!(form.list2.is_none());
|
||||||
|
HttpResponse::Ok().finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_option_vec() {
|
||||||
|
let srv =
|
||||||
|
actix_test::start(|| App::new().route("/", web::post().to(test_option_vec_route)));
|
||||||
|
|
||||||
|
let mut form = multipart::Form::default();
|
||||||
|
form.add_text("list1", "value1");
|
||||||
|
form.add_text("list1", "value2");
|
||||||
|
form.add_text("list1", "value3");
|
||||||
|
|
||||||
|
let response = send_form(&srv, form, "/").await;
|
||||||
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
|
}
|
||||||
|
|
||||||
/// Test the `rename` field attribute.
|
/// Test the `rename` field attribute.
|
||||||
#[derive(MultipartForm)]
|
#[derive(MultipartForm)]
|
||||||
struct TestFieldRenaming {
|
struct TestFieldRenaming {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use actix_web::{post, App, HttpServer, Responder};
|
//! use actix_web::{post, App, HttpServer, Responder};
|
||||||
//!
|
//!
|
||||||
//! use actix_multipart::form::{json::Json as MpJson, tempfile::TempFile, MultipartForm};
|
//! use actix_multipart::form::{json::Json as MpJson, tempfile::TempFile, MultipartForm, MultipartFormConfig};
|
||||||
//! use serde::Deserialize;
|
//! use serde::Deserialize;
|
||||||
//!
|
//!
|
||||||
//! #[derive(Debug, Deserialize)]
|
//! #[derive(Debug, Deserialize)]
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
//!
|
//!
|
||||||
//! #[derive(Debug, MultipartForm)]
|
//! #[derive(Debug, MultipartForm)]
|
||||||
//! struct UploadForm {
|
//! struct UploadForm {
|
||||||
|
//! // Note: the form is also subject to the global limits configured using `MultipartFormConfig`.
|
||||||
//! #[multipart(limit = "100MB")]
|
//! #[multipart(limit = "100MB")]
|
||||||
//! file: TempFile,
|
//! file: TempFile,
|
||||||
//! json: MpJson<Metadata>,
|
//! json: MpJson<Metadata>,
|
||||||
|
|
@ -38,10 +39,15 @@
|
||||||
//!
|
//!
|
||||||
//! #[actix_web::main]
|
//! #[actix_web::main]
|
||||||
//! async fn main() -> std::io::Result<()> {
|
//! async fn main() -> std::io::Result<()> {
|
||||||
//! HttpServer::new(move || App::new().service(post_video))
|
//! HttpServer::new(move || {
|
||||||
//! .bind(("127.0.0.1", 8080))?
|
//! App::new()
|
||||||
//! .run()
|
//! .service(post_video)
|
||||||
//! .await
|
//! // Also increase the global total limit to 100MiB.
|
||||||
|
//! .app_data(MultipartFormConfig::default().total_limit(100 * 1024 * 1024))
|
||||||
|
//! })
|
||||||
|
//! .bind(("127.0.0.1", 8080))?
|
||||||
|
//! .run()
|
||||||
|
//! .await
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
|
@ -58,7 +64,7 @@
|
||||||
|
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
// This allows us to use the actix_multipart_derive within this crate's tests
|
// This allows us to use the actix_multipart_derive within this crate's tests
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Refactor capture_match_info_fn by splitting it into three distinct functions: capture_match_info(), resolve_path_if_match(), and resolve().
|
- Refactor `capture_match_info_fn` by splitting it into three distinct functions: `capture_match_info()`, `resolve_path_if_match()`, and `resolve()`.
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
## 0.5.3
|
## 0.5.3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-router)
|
[](https://crates.io/crates/actix-router)
|
||||||
[](https://docs.rs/actix-router/0.5.3)
|
[](https://docs.rs/actix-router/0.5.3)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-router/0.5.3)
|
[](https://deps.rs/crate/actix-router/0.5.3)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ macro_rules! register {
|
||||||
register!(finish => "(.*)", "(.*)", "(.*)", "(.*)")
|
register!(finish => "(.*)", "(.*)", "(.*)", "(.*)")
|
||||||
}};
|
}};
|
||||||
(finish => $p1:literal, $p2:literal, $p3:literal, $p4:literal) => {{
|
(finish => $p1:literal, $p2:literal, $p3:literal, $p4:literal) => {{
|
||||||
|
#[expect(clippy::useless_concat)]
|
||||||
let arr = [
|
let arr = [
|
||||||
concat!("/authorizations"),
|
concat!("/authorizations"),
|
||||||
concat!("/authorizations/", $p1),
|
concat!("/authorizations/", $p1),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
mod de;
|
mod de;
|
||||||
mod path;
|
mod path;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
## 0.1.5
|
## 0.1.5
|
||||||
|
|
||||||
- Add `TestServerConfig::listen_address()` method.
|
- Add `TestServerConfig::listen_address()` method.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-test)
|
[](https://crates.io/crates/actix-test)
|
||||||
[](https://docs.rs/actix-test/0.1.5)
|
[](https://docs.rs/actix-test/0.1.5)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-test/0.1.5)
|
[](https://deps.rs/crate/actix-test/0.1.5)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
#[cfg(feature = "openssl")]
|
#[cfg(feature = "openssl")]
|
||||||
extern crate tls_openssl as openssl;
|
extern crate tls_openssl as openssl;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
## 4.3.1 <!-- v4.3.1+deprecated -->
|
## 4.3.1 <!-- v4.3.1+deprecated -->
|
||||||
|
|
||||||
- Reduce memory usage by `take`-ing (rather than `split`-ing) the encoded buffer when yielding bytes in the response stream.
|
- Reduce memory usage by `take`-ing (rather than `split`-ing) the encoded buffer when yielding bytes in the response stream.
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ allowed_external_types = [
|
||||||
actix = { version = ">=0.12, <0.14", default-features = false }
|
actix = { version = ">=0.12, <0.14", default-features = false }
|
||||||
actix-codec = "0.5"
|
actix-codec = "0.5"
|
||||||
actix-http = "3"
|
actix-http = "3"
|
||||||
actix-web = { version = "4", default-features = false }
|
actix-web = { version = "4", default-features = false, features = ["ws"] }
|
||||||
|
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
bytestring = "1"
|
bytestring = "1"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-web-actors)
|
[](https://crates.io/crates/actix-web-actors)
|
||||||
[](https://docs.rs/actix-web-actors/4.3.1)
|
[](https://docs.rs/actix-web-actors/4.3.1)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||

|

|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@
|
||||||
|
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
mod context;
|
mod context;
|
||||||
pub mod ws;
|
pub mod ws;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
## 4.3.0
|
## 4.3.0
|
||||||
|
|
||||||
- Add `#[scope]` macro.
|
- Add `#[scope]` macro.
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-web-codegen)
|
[](https://crates.io/crates/actix-web-codegen)
|
||||||
[](https://docs.rs/actix-web-codegen/4.3.0)
|
[](https://docs.rs/actix-web-codegen/4.3.0)
|
||||||

|

|
||||||

|

|
||||||
<br />
|
<br />
|
||||||
[](https://deps.rs/crate/actix-web-codegen/4.3.0)
|
[](https://deps.rs/crate/actix-web-codegen/4.3.0)
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@
|
||||||
#![recursion_limit = "512"]
|
#![recursion_limit = "512"]
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ macro_rules! standard_method_type {
|
||||||
(
|
(
|
||||||
$($variant:ident, $upper:ident, $lower:ident,)+
|
$($variant:ident, $upper:ident, $lower:ident,)+
|
||||||
) => {
|
) => {
|
||||||
|
#[doc(hidden)]
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum MethodType {
|
pub enum MethodType {
|
||||||
$(
|
$(
|
||||||
|
|
@ -466,7 +467,7 @@ impl ToTokens for Route {
|
||||||
|
|
||||||
let stream = quote! {
|
let stream = quote! {
|
||||||
#(#doc_attributes)*
|
#(#doc_attributes)*
|
||||||
#[allow(non_camel_case_types, missing_docs)]
|
#[allow(non_camel_case_types)]
|
||||||
#vis struct #name;
|
#vis struct #name;
|
||||||
|
|
||||||
impl ::actix_web::dev::HttpServiceFactory for #name {
|
impl ::actix_web::dev::HttpServiceFactory for #name {
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
= help: the following other types implement trait `HttpServiceFactory`:
|
= help: the following other types implement trait `HttpServiceFactory`:
|
||||||
Resource<T>
|
|
||||||
actix_web::Scope<T>
|
|
||||||
Vec<T>
|
|
||||||
Redirect
|
|
||||||
(A,)
|
|
||||||
(A, B)
|
(A, B)
|
||||||
(A, B, C)
|
(A, B, C)
|
||||||
(A, B, C, D)
|
(A, B, C, D)
|
||||||
|
(A, B, C, D, E)
|
||||||
|
(A, B, C, D, E, F)
|
||||||
|
(A, B, C, D, E, F, G)
|
||||||
|
(A, B, C, D, E, F, G, H)
|
||||||
|
(A, B, C, D, E, F, G, H, I)
|
||||||
and $N others
|
and $N others
|
||||||
note: required by a bound in `App::<T>::service`
|
note: required by a bound in `App::<T>::service`
|
||||||
--> $WORKSPACE/actix-web/src/app.rs
|
--> $WORKSPACE/actix-web/src/app.rs
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
= help: the following other types implement trait `HttpServiceFactory`:
|
= help: the following other types implement trait `HttpServiceFactory`:
|
||||||
Resource<T>
|
|
||||||
actix_web::Scope<T>
|
|
||||||
Vec<T>
|
|
||||||
Redirect
|
|
||||||
(A,)
|
|
||||||
(A, B)
|
(A, B)
|
||||||
(A, B, C)
|
(A, B, C)
|
||||||
(A, B, C, D)
|
(A, B, C, D)
|
||||||
|
(A, B, C, D, E)
|
||||||
|
(A, B, C, D, E, F)
|
||||||
|
(A, B, C, D, E, F, G)
|
||||||
|
(A, B, C, D, E, F, G, H)
|
||||||
|
(A, B, C, D, E, F, G, H, I)
|
||||||
and $N others
|
and $N others
|
||||||
note: required by a bound in `App::<T>::service`
|
note: required by a bound in `App::<T>::service`
|
||||||
--> $WORKSPACE/actix-web/src/app.rs
|
--> $WORKSPACE/actix-web/src/app.rs
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
= help: the following other types implement trait `HttpServiceFactory`:
|
= help: the following other types implement trait `HttpServiceFactory`:
|
||||||
Resource<T>
|
|
||||||
actix_web::Scope<T>
|
|
||||||
Vec<T>
|
|
||||||
Redirect
|
|
||||||
(A,)
|
|
||||||
(A, B)
|
(A, B)
|
||||||
(A, B, C)
|
(A, B, C)
|
||||||
(A, B, C, D)
|
(A, B, C, D)
|
||||||
|
(A, B, C, D, E)
|
||||||
|
(A, B, C, D, E, F)
|
||||||
|
(A, B, C, D, E, F, G)
|
||||||
|
(A, B, C, D, E, F, G, H)
|
||||||
|
(A, B, C, D, E, F, G, H, I)
|
||||||
and $N others
|
and $N others
|
||||||
note: required by a bound in `App::<T>::service`
|
note: required by a bound in `App::<T>::service`
|
||||||
--> $WORKSPACE/actix-web/src/app.rs
|
--> $WORKSPACE/actix-web/src/app.rs
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
= help: the following other types implement trait `HttpServiceFactory`:
|
= help: the following other types implement trait `HttpServiceFactory`:
|
||||||
Resource<T>
|
|
||||||
actix_web::Scope<T>
|
|
||||||
Vec<T>
|
|
||||||
Redirect
|
|
||||||
(A,)
|
|
||||||
(A, B)
|
(A, B)
|
||||||
(A, B, C)
|
(A, B, C)
|
||||||
(A, B, C, D)
|
(A, B, C, D)
|
||||||
|
(A, B, C, D, E)
|
||||||
|
(A, B, C, D, E, F)
|
||||||
|
(A, B, C, D, E, F, G)
|
||||||
|
(A, B, C, D, E, F, G, H)
|
||||||
|
(A, B, C, D, E, F, G, H, I)
|
||||||
and $N others
|
and $N others
|
||||||
note: required by a bound in `App::<T>::service`
|
note: required by a bound in `App::<T>::service`
|
||||||
--> $WORKSPACE/actix-web/src/app.rs
|
--> $WORKSPACE/actix-web/src/app.rs
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,14 @@ error[E0277]: the trait bound `fn() -> impl std::future::Future<Output = String>
|
||||||
| required by a bound introduced by this call
|
| required by a bound introduced by this call
|
||||||
|
|
|
|
||||||
= help: the following other types implement trait `HttpServiceFactory`:
|
= help: the following other types implement trait `HttpServiceFactory`:
|
||||||
Resource<T>
|
|
||||||
actix_web::Scope<T>
|
|
||||||
Vec<T>
|
|
||||||
Redirect
|
|
||||||
(A,)
|
|
||||||
(A, B)
|
(A, B)
|
||||||
(A, B, C)
|
(A, B, C)
|
||||||
(A, B, C, D)
|
(A, B, C, D)
|
||||||
|
(A, B, C, D, E)
|
||||||
|
(A, B, C, D, E, F)
|
||||||
|
(A, B, C, D, E, F, G)
|
||||||
|
(A, B, C, D, E, F, G, H)
|
||||||
|
(A, B, C, D, E, F, G, H, I)
|
||||||
and $N others
|
and $N others
|
||||||
note: required by a bound in `App::<T>::service`
|
note: required by a bound in `App::<T>::service`
|
||||||
--> $WORKSPACE/actix-web/src/app.rs
|
--> $WORKSPACE/actix-web/src/app.rs
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,22 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
- Add `HttpRequest::url_for_map` and `HttpRequest::url_for_iter` methods for named URL parameters. [#3895]
|
||||||
|
|
||||||
|
[#3895]: https://github.com/actix/actix-web/pull/3895
|
||||||
|
|
||||||
|
## 4.12.1
|
||||||
|
|
||||||
|
- Correct `actix-http` dependency requirement.
|
||||||
|
|
||||||
|
## 4.12.0
|
||||||
|
|
||||||
|
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now sets `Content-Type` to `application/octet-stream` if `Content-Type` does not exist.
|
||||||
|
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now calls `actix_web::response::builder::HttpResponseBuilder::no_chunking()` and returns `SizedStream` if `Content-Length` is set by user.
|
||||||
|
- Add `ws` crate feature (on-by-default) which forwards to `actix-http` and guards some of its `ResponseError` impls.
|
||||||
|
- Add public export for `EitherExtractError` in `error` module.
|
||||||
|
|
||||||
## 4.11.0
|
## 4.11.0
|
||||||
|
|
||||||
- Add `Logger::log_level()` method.
|
- Add `Logger::log_level()` method.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "4.11.0"
|
version = "4.12.1"
|
||||||
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
||||||
keywords = ["actix", "http", "web", "framework", "async"]
|
keywords = ["actix", "http", "web", "framework", "async"]
|
||||||
|
|
@ -17,7 +17,6 @@ edition.workspace = true
|
||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
|
||||||
features = [
|
features = [
|
||||||
"macros",
|
"macros",
|
||||||
"openssl",
|
"openssl",
|
||||||
|
|
@ -53,7 +52,6 @@ allowed_external_types = [
|
||||||
"serde_json::*",
|
"serde_json::*",
|
||||||
"serde_urlencoded::*",
|
"serde_urlencoded::*",
|
||||||
"serde::*",
|
"serde::*",
|
||||||
"serde::*",
|
|
||||||
"tokio::*",
|
"tokio::*",
|
||||||
"url::*",
|
"url::*",
|
||||||
]
|
]
|
||||||
|
|
@ -68,6 +66,7 @@ default = [
|
||||||
"http2",
|
"http2",
|
||||||
"unicode",
|
"unicode",
|
||||||
"compat",
|
"compat",
|
||||||
|
"ws",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Brotli algorithm content-encoding support
|
# Brotli algorithm content-encoding support
|
||||||
|
|
@ -86,9 +85,12 @@ cookies = ["dep:cookie"]
|
||||||
# Secure & signed cookies
|
# Secure & signed cookies
|
||||||
secure-cookies = ["cookies", "cookie/secure"]
|
secure-cookies = ["cookies", "cookie/secure"]
|
||||||
|
|
||||||
# HTTP/2 support (including h2c).
|
# HTTP/2 support (including h2c)
|
||||||
http2 = ["actix-http/http2"]
|
http2 = ["actix-http/http2"]
|
||||||
|
|
||||||
|
# WebSocket support
|
||||||
|
ws = ["actix-http/ws"]
|
||||||
|
|
||||||
# TLS via OpenSSL
|
# TLS via OpenSSL
|
||||||
openssl = ["__tls", "http2", "actix-http/openssl", "actix-tls/accept", "actix-tls/openssl"]
|
openssl = ["__tls", "http2", "actix-http/openssl", "actix-tls/accept", "actix-tls/openssl"]
|
||||||
|
|
||||||
|
|
@ -132,7 +134,7 @@ actix-service = "2"
|
||||||
actix-tls = { version = "3.4", default-features = false, optional = true }
|
actix-tls = { version = "3.4", default-features = false, optional = true }
|
||||||
actix-utils = "3"
|
actix-utils = "3"
|
||||||
|
|
||||||
actix-http = { version = "3.11", features = ["ws"] }
|
actix-http = "3.11.2"
|
||||||
actix-router = { version = "0.5.3", default-features = false, features = ["http"] }
|
actix-router = { version = "0.5.3", default-features = false, features = ["http"] }
|
||||||
actix-web-codegen = { version = "4.3", optional = true, default-features = false }
|
actix-web-codegen = { version = "4.3", optional = true, default-features = false }
|
||||||
|
|
||||||
|
|
@ -158,7 +160,7 @@ serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_urlencoded = "0.7"
|
serde_urlencoded = "0.7"
|
||||||
smallvec = "1.6.1"
|
smallvec = "1.6.1"
|
||||||
socket2 = "0.5"
|
socket2 = "0.6"
|
||||||
time = { version = "0.3", default-features = false, features = ["formatting"] }
|
time = { version = "0.3", default-features = false, features = ["formatting"] }
|
||||||
tracing = "0.1.30"
|
tracing = "0.1.30"
|
||||||
url = "2.5.4"
|
url = "2.5.4"
|
||||||
|
|
@ -177,7 +179,7 @@ flate2 = "1.0.13"
|
||||||
futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
|
futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
|
||||||
rand = "0.9"
|
rand = "0.9"
|
||||||
rcgen = "0.13"
|
rcgen = "0.13"
|
||||||
rustls-pemfile = "2"
|
rustls-pki-types = "1.13.1"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
static_assertions = "1"
|
static_assertions = "1"
|
||||||
tls-openssl = { package = "openssl", version = "0.10.55" }
|
tls-openssl = { package = "openssl", version = "0.10.55" }
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
- The return type for `ServiceRequest::app_data::<T>()` was changed from returning a `Data<T>` to simply a `T`. To access a `Data<T>` use `ServiceRequest::app_data::<Data<T>>()`.
|
- The return type for `ServiceRequest::app_data::<T>()` was changed from returning a `Data<T>` to simply a `T`. To access a `Data<T>` use `ServiceRequest::app_data::<Data<T>>()`.
|
||||||
|
|
||||||
- Cookie handling has been offloaded to the `cookie` crate:
|
- Cookie handling has been offloaded to the `cookie` crate:
|
||||||
|
|
||||||
- `USERINFO_ENCODE_SET` is no longer exposed. Percent-encoding is still supported; check docs.
|
- `USERINFO_ENCODE_SET` is no longer exposed. Percent-encoding is still supported; check docs.
|
||||||
- Some types now require lifetime parameters.
|
- Some types now require lifetime parameters.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ An alternative [path param type with public field but no `Deref` impl is availab
|
||||||
|
|
||||||
## Rustls Crate Upgrade
|
## Rustls Crate Upgrade
|
||||||
|
|
||||||
Actix Web now depends on version 0.20 of `rustls`. As a result, the server config builder has changed. [See the updated example project.](https://github.com/actix/examples/tree/master/https-tls/rustls/)
|
Actix Web now depends on version 0.20 of `rustls`. As a result, the server config builder has changed. [See the updated example project.](https://github.com/actix/examples/tree/main/https-tls/rustls/)
|
||||||
|
|
||||||
## Removed `awc` Client Re-export
|
## Removed `awc` Client Re-export
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
|
|
||||||
[](https://crates.io/crates/actix-web)
|
[](https://crates.io/crates/actix-web)
|
||||||
[](https://docs.rs/actix-web/4.11.0)
|
[](https://docs.rs/actix-web/4.12.1)
|
||||||

|

|
||||||

|

|
||||||
[](https://deps.rs/crate/actix-web/4.11.0)
|
[](https://deps.rs/crate/actix-web/4.12.1)
|
||||||
<br />
|
<br />
|
||||||
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
||||||
[](https://codecov.io/gh/actix/actix-web)
|
[](https://codecov.io/gh/actix/actix-web)
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
- [Website & User Guide](https://actix.rs)
|
- [Website & User Guide](https://actix.rs)
|
||||||
- [Examples Repository](https://github.com/actix/examples)
|
- [Examples Repository](https://github.com/actix/examples)
|
||||||
- [API Documentation](https://docs.rs/actix-web)
|
- [API Documentation](https://docs.rs/actix-web)
|
||||||
- [API Documentation (master branch)](https://actix.rs/actix-web/actix_web)
|
- [API Documentation (mainranch)](https://actix.rs/actix-web/actix_web)
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|
@ -78,23 +78,23 @@ async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
### More Examples
|
### More Examples
|
||||||
|
|
||||||
- [Hello World](https://github.com/actix/examples/tree/master/basics/hello-world)
|
- [Hello World](https://github.com/actix/examples/tree/main/basics/hello-world)
|
||||||
- [Basic Setup](https://github.com/actix/examples/tree/master/basics/basics)
|
- [Basic Setup](https://github.com/actix/examples/tree/main/basics/basics)
|
||||||
- [Application State](https://github.com/actix/examples/tree/master/basics/state)
|
- [Application State](https://github.com/actix/examples/tree/main/basics/state)
|
||||||
- [JSON Handling](https://github.com/actix/examples/tree/master/json/json)
|
- [JSON Handling](https://github.com/actix/examples/tree/main/json/json)
|
||||||
- [Multipart Streams](https://github.com/actix/examples/tree/master/forms/multipart)
|
- [Multipart Streams](https://github.com/actix/examples/tree/main/forms/multipart)
|
||||||
- [MongoDB Integration](https://github.com/actix/examples/tree/master/databases/mongodb)
|
- [MongoDB Integration](https://github.com/actix/examples/tree/main/databases/mongodb)
|
||||||
- [Diesel Integration](https://github.com/actix/examples/tree/master/databases/diesel)
|
- [Diesel Integration](https://github.com/actix/examples/tree/main/databases/diesel)
|
||||||
- [SQLite Integration](https://github.com/actix/examples/tree/master/databases/sqlite)
|
- [SQLite Integration](https://github.com/actix/examples/tree/main/databases/sqlite)
|
||||||
- [Postgres Integration](https://github.com/actix/examples/tree/master/databases/postgres)
|
- [Postgres Integration](https://github.com/actix/examples/tree/main/databases/postgres)
|
||||||
- [Tera Templates](https://github.com/actix/examples/tree/master/templating/tera)
|
- [Tera Templates](https://github.com/actix/examples/tree/main/templating/tera)
|
||||||
- [Askama Templates](https://github.com/actix/examples/tree/master/templating/askama)
|
- [Askama Templates](https://github.com/actix/examples/tree/main/templating/askama)
|
||||||
- [HTTPS using Rustls](https://github.com/actix/examples/tree/master/https-tls/rustls)
|
- [HTTPS using Rustls](https://github.com/actix/examples/tree/main/https-tls/rustls)
|
||||||
- [HTTPS using OpenSSL](https://github.com/actix/examples/tree/master/https-tls/openssl)
|
- [HTTPS using OpenSSL](https://github.com/actix/examples/tree/main/https-tls/openssl)
|
||||||
- [Simple WebSocket](https://github.com/actix/examples/tree/master/websockets)
|
- [Simple WebSocket](https://github.com/actix/examples/tree/main/websockets)
|
||||||
- [WebSocket Chat](https://github.com/actix/examples/tree/master/websockets/chat)
|
- [WebSocket Chat](https://github.com/actix/examples/tree/main/websockets/chat)
|
||||||
|
|
||||||
You may consider checking out [this directory](https://github.com/actix/examples/tree/master) for more examples.
|
You may consider checking out [this directory](https://github.com/actix/examples/tree/main) for more examples.
|
||||||
|
|
||||||
## Benchmarks
|
## Benchmarks
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
//! properties and pass them to a handler through request-local data.
|
//! properties and pass them to a handler through request-local data.
|
||||||
//!
|
//!
|
||||||
//! For an example of extracting a client TLS certificate, see:
|
//! For an example of extracting a client TLS certificate, see:
|
||||||
//! <https://github.com/actix/examples/tree/master/https-tls/rustls-client-cert>
|
//! <https://github.com/actix/examples/tree/main/https-tls/rustls-client-cert>
|
||||||
|
|
||||||
use std::{any::Any, io, net::SocketAddr};
|
use std::{any::Any, io, net::SocketAddr};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ mod response_error;
|
||||||
|
|
||||||
pub(crate) use self::macros::{downcast_dyn, downcast_get_type_id};
|
pub(crate) use self::macros::{downcast_dyn, downcast_get_type_id};
|
||||||
pub use self::{error::Error, internal::*, response_error::ResponseError};
|
pub use self::{error::Error, internal::*, response_error::ResponseError};
|
||||||
|
pub use crate::types::EitherExtractError;
|
||||||
|
|
||||||
/// A convenience [`Result`](std::result::Result) for Actix Web operations.
|
/// A convenience [`Result`](std::result::Result) for Actix Web operations.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ use std::{
|
||||||
io::{self, Write as _},
|
io::{self, Write as _},
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_http::Response;
|
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -126,20 +125,24 @@ impl ResponseError for actix_http::error::PayloadError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResponseError for actix_http::ws::ProtocolError {}
|
|
||||||
|
|
||||||
impl ResponseError for actix_http::error::ContentTypeError {
|
impl ResponseError for actix_http::error::ContentTypeError {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
StatusCode::BAD_REQUEST
|
StatusCode::BAD_REQUEST
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ws")]
|
||||||
impl ResponseError for actix_http::ws::HandshakeError {
|
impl ResponseError for actix_http::ws::HandshakeError {
|
||||||
fn error_response(&self) -> HttpResponse<BoxBody> {
|
fn error_response(&self) -> HttpResponse<BoxBody> {
|
||||||
Response::from(self).map_into_boxed_body().into()
|
actix_http::Response::from(self)
|
||||||
|
.map_into_boxed_body()
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ws")]
|
||||||
|
impl ResponseError for actix_http::ws::ProtocolError {}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@
|
||||||
|
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
pub use actix_http::{body, HttpMessage};
|
pub use actix_http::{body, HttpMessage};
|
||||||
#[cfg(feature = "cookies")]
|
#[cfg(feature = "cookies")]
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,79 @@
|
||||||
|
|
||||||
## What Is A Middleware?
|
## What Is A Middleware?
|
||||||
|
|
||||||
|
Middleware in Actix Web is a powerful mechanism that allows you to add additional behavior to request/response processing. It enables you to:
|
||||||
|
|
||||||
|
- Pre-process incoming requests (e.g., path normalization, authentication)
|
||||||
|
- Post-process outgoing responses (e.g., logging, compression)
|
||||||
|
- Modify application state through ServiceRequest
|
||||||
|
- Access external services (e.g., sessions, caching)
|
||||||
|
|
||||||
|
Middleware is registered for each App, Scope, or Resource and executed in the reverse order of registration. This means the last registered middleware is the first to process the request.
|
||||||
|
|
||||||
## Middleware Traits
|
## Middleware Traits
|
||||||
|
|
||||||
|
Actix Web's middleware system is built on two main traits:
|
||||||
|
|
||||||
|
1. `Transform<S, Req>`: The builder trait that creates the actual Service. It's responsible for:
|
||||||
|
- Creating new middleware instances
|
||||||
|
- Assembling the middleware chain
|
||||||
|
- Handling initialization errors
|
||||||
|
|
||||||
|
2. `Service<Req>`: The trait that represents the actual middleware functionality. It:
|
||||||
|
- Processes requests and responses
|
||||||
|
- Can modify both request and response
|
||||||
|
- Can short-circuit request processing
|
||||||
|
- Must be implemented for the middleware to work
|
||||||
|
|
||||||
## Understanding Body Types
|
## Understanding Body Types
|
||||||
|
|
||||||
|
When working with middleware, it's important to understand body types:
|
||||||
|
|
||||||
|
- Middleware can work with different body types for requests and responses
|
||||||
|
- The `MessageBody` trait is used to handle different body types
|
||||||
|
- You can use `EitherBody` when you need to handle multiple body types
|
||||||
|
- Be careful with body consumption - once a body is consumed, it cannot be read again
|
||||||
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
|
1. Keep middleware focused and single-purpose
|
||||||
|
2. Handle errors appropriately and propagate them correctly
|
||||||
|
3. Be mindful of performance impact
|
||||||
|
4. Use appropriate body types and handle them correctly
|
||||||
|
5. Consider middleware ordering carefully
|
||||||
|
6. Document your middleware's behavior and requirements
|
||||||
|
7. Test your middleware thoroughly
|
||||||
|
|
||||||
## Error Propagation
|
## Error Propagation
|
||||||
|
|
||||||
|
Proper error handling is crucial in middleware:
|
||||||
|
|
||||||
|
1. Always propagate errors from the inner service
|
||||||
|
2. Use appropriate error types
|
||||||
|
3. Handle initialization errors
|
||||||
|
4. Consider using custom error types for specific middleware errors
|
||||||
|
5. Document error conditions and handling
|
||||||
|
|
||||||
## When To (Not) Use Middleware
|
## When To (Not) Use Middleware
|
||||||
|
|
||||||
|
Use middleware when you need to:
|
||||||
|
|
||||||
|
- Add cross-cutting concerns
|
||||||
|
- Modify requests/responses globally
|
||||||
|
- Add authentication/authorization
|
||||||
|
- Add logging or monitoring
|
||||||
|
- Handle compression or caching
|
||||||
|
|
||||||
|
Avoid middleware when:
|
||||||
|
|
||||||
|
- The functionality is specific to a single route
|
||||||
|
- The operation is better handled by a service
|
||||||
|
- The overhead would be too high
|
||||||
|
- The functionality can be implemented more simply
|
||||||
|
|
||||||
## Author's References
|
## Author's References
|
||||||
|
|
||||||
- `EitherBody` + when is middleware appropriate: https://discord.com/channels/771444961383153695/952016890723729428
|
- `EitherBody` + when is middleware appropriate: https://discord.com/channels/771444961383153695/952016890723729428
|
||||||
|
- Actix Web Documentation: https://docs.rs/actix-web
|
||||||
|
- Service Trait Documentation: https://docs.rs/actix-service
|
||||||
|
- MessageBody Trait Documentation: https://docs.rs/actix-web/latest/actix_web/body/trait.MessageBody.html
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
use std::{
|
use std::{
|
||||||
cell::{Ref, RefCell, RefMut},
|
cell::{Ref, RefCell, RefMut},
|
||||||
fmt, net,
|
collections::HashMap,
|
||||||
|
fmt,
|
||||||
|
hash::{BuildHasher, Hash},
|
||||||
|
net,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
str,
|
str,
|
||||||
};
|
};
|
||||||
|
|
@ -242,6 +245,76 @@ impl HttpRequest {
|
||||||
self.resource_map().url_for(self, name, elements)
|
self.resource_map().url_for(self, name, elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates URL for a named resource using a map of dynamic segment values.
|
||||||
|
///
|
||||||
|
/// This substitutes URL parameters by name from `elements`, including parameters from parent
|
||||||
|
/// scopes.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```
|
||||||
|
/// # use std::collections::HashMap;
|
||||||
|
/// # use actix_web::{web, App, HttpRequest, HttpResponse};
|
||||||
|
/// fn index(req: HttpRequest) -> HttpResponse {
|
||||||
|
/// let mut params = HashMap::new();
|
||||||
|
/// params.insert("one", "1");
|
||||||
|
/// params.insert("two", "2");
|
||||||
|
/// let url = req.url_for_map("foo", ¶ms); // <- generate URL for "foo" resource
|
||||||
|
/// HttpResponse::Ok().into()
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// let app = App::new()
|
||||||
|
/// .service(web::resource("/test/{one}/{two}")
|
||||||
|
/// .name("foo") // <- set resource name so it can be used in `url_for_map`
|
||||||
|
/// .route(web::get().to(|| HttpResponse::Ok()))
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
pub fn url_for_map<K, V, S>(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
elements: &HashMap<K, V, S>,
|
||||||
|
) -> Result<url::Url, UrlGenerationError>
|
||||||
|
where
|
||||||
|
K: std::borrow::Borrow<str> + Eq + Hash,
|
||||||
|
V: AsRef<str>,
|
||||||
|
S: BuildHasher,
|
||||||
|
{
|
||||||
|
self.resource_map().url_for_map(self, name, elements)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates URL for a named resource using an iterator of key-value pairs.
|
||||||
|
///
|
||||||
|
/// This is a convenience wrapper around [`HttpRequest::url_for_map`].
|
||||||
|
///
|
||||||
|
/// Note: passing a borrowed map (e.g. `&HashMap<String, String>`) directly does not satisfy the
|
||||||
|
/// trait bounds because the iterator yields `(&String, &String)`. Prefer `url_for_map` for
|
||||||
|
/// borrowed maps, or map entries to `&str`:
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use std::collections::HashMap;
|
||||||
|
/// # use actix_web::{web, App, HttpRequest, HttpResponse};
|
||||||
|
/// fn index(req: HttpRequest) -> HttpResponse {
|
||||||
|
/// let mut params = HashMap::new();
|
||||||
|
/// params.insert("one".to_string(), "1".to_string());
|
||||||
|
/// params.insert("two".to_string(), "2".to_string());
|
||||||
|
///
|
||||||
|
/// let iter = params.iter().map(|(k, v)| (k.as_str(), v.as_str()));
|
||||||
|
/// let url = req.url_for_iter("foo", iter);
|
||||||
|
/// HttpResponse::Ok().into()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub fn url_for_iter<K, V, I>(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
elements: I,
|
||||||
|
) -> Result<url::Url, UrlGenerationError>
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = (K, V)>,
|
||||||
|
K: std::borrow::Borrow<str> + Eq + Hash,
|
||||||
|
V: AsRef<str>,
|
||||||
|
{
|
||||||
|
self.resource_map().url_for_iter(self, name, elements)
|
||||||
|
}
|
||||||
|
|
||||||
/// Generate URL for named resource
|
/// Generate URL for named resource
|
||||||
///
|
///
|
||||||
/// This method is similar to `HttpRequest::url_for()` but it can be used
|
/// This method is similar to `HttpRequest::url_for()` but it can be used
|
||||||
|
|
@ -550,6 +623,8 @@ impl HttpRequestPool {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -638,6 +713,59 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_url_for_map() {
|
||||||
|
let mut res = ResourceDef::new("/user/{name}.{ext}");
|
||||||
|
res.set_name("index");
|
||||||
|
|
||||||
|
let mut rmap = ResourceMap::new(ResourceDef::prefix(""));
|
||||||
|
rmap.add(&mut res, None);
|
||||||
|
|
||||||
|
let req = TestRequest::default()
|
||||||
|
.insert_header((header::HOST, "www.actix.rs"))
|
||||||
|
.rmap(rmap)
|
||||||
|
.to_http_request();
|
||||||
|
|
||||||
|
let mut params = HashMap::new();
|
||||||
|
params.insert("name", "test");
|
||||||
|
params.insert("ext", "html");
|
||||||
|
|
||||||
|
let url = req.url_for_map("index", ¶ms);
|
||||||
|
assert_eq!(
|
||||||
|
url.ok().unwrap().as_str(),
|
||||||
|
"http://www.actix.rs/user/test.html"
|
||||||
|
);
|
||||||
|
|
||||||
|
params.remove("ext");
|
||||||
|
assert_eq!(
|
||||||
|
req.url_for_map("index", ¶ms),
|
||||||
|
Err(UrlGenerationError::NotEnoughElements)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_url_for_iter() {
|
||||||
|
let mut res = ResourceDef::new("/user/{name}.{ext}");
|
||||||
|
res.set_name("index");
|
||||||
|
|
||||||
|
let mut rmap = ResourceMap::new(ResourceDef::prefix(""));
|
||||||
|
rmap.add(&mut res, None);
|
||||||
|
|
||||||
|
let req = TestRequest::default()
|
||||||
|
.insert_header((header::HOST, "www.actix.rs"))
|
||||||
|
.rmap(rmap)
|
||||||
|
.to_http_request();
|
||||||
|
|
||||||
|
let url = req.url_for_iter("index", [("ext", "html"), ("name", "test")]);
|
||||||
|
assert_eq!(
|
||||||
|
url.ok().unwrap().as_str(),
|
||||||
|
"http://www.actix.rs/user/test.html"
|
||||||
|
);
|
||||||
|
|
||||||
|
let url = req.url_for_iter("index", [("name", "test")]);
|
||||||
|
assert_eq!(url, Err(UrlGenerationError::NotEnoughElements));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_url_for_static() {
|
fn test_url_for_static() {
|
||||||
let mut rdef = ResourceDef::new("/index.html");
|
let mut rdef = ResourceDef::new("/index.html");
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use futures_core::Stream;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{BodyStream, BoxBody, MessageBody},
|
body::{BodyStream, BoxBody, MessageBody, SizedStream},
|
||||||
dev::Extensions,
|
dev::Extensions,
|
||||||
error::{Error, JsonPayloadError},
|
error::{Error, JsonPayloadError},
|
||||||
http::{
|
http::{
|
||||||
|
|
@ -318,13 +318,35 @@ impl HttpResponseBuilder {
|
||||||
/// Set a streaming body and build the `HttpResponse`.
|
/// Set a streaming body and build the `HttpResponse`.
|
||||||
///
|
///
|
||||||
/// `HttpResponseBuilder` can not be used after this call.
|
/// `HttpResponseBuilder` can not be used after this call.
|
||||||
|
///
|
||||||
|
/// If `Content-Type` is not set, then it is automatically set to `application/octet-stream`.
|
||||||
|
///
|
||||||
|
/// If `Content-Length` is set, then [`no_chunking()`](Self::no_chunking) is automatically called.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn streaming<S, E>(&mut self, stream: S) -> HttpResponse
|
pub fn streaming<S, E>(&mut self, stream: S) -> HttpResponse
|
||||||
where
|
where
|
||||||
S: Stream<Item = Result<Bytes, E>> + 'static,
|
S: Stream<Item = Result<Bytes, E>> + 'static,
|
||||||
E: Into<BoxError> + 'static,
|
E: Into<BoxError> + 'static,
|
||||||
{
|
{
|
||||||
self.body(BodyStream::new(stream))
|
// Set mime type to application/octet-stream if it is not set
|
||||||
|
if let Some(parts) = self.inner() {
|
||||||
|
if !parts.headers.contains_key(header::CONTENT_TYPE) {
|
||||||
|
self.insert_header((header::CONTENT_TYPE, mime::APPLICATION_OCTET_STREAM));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let content_length = self
|
||||||
|
.inner()
|
||||||
|
.and_then(|parts| parts.headers.get(header::CONTENT_LENGTH))
|
||||||
|
.and_then(|value| value.to_str().ok())
|
||||||
|
.and_then(|value| value.parse::<u64>().ok());
|
||||||
|
|
||||||
|
if let Some(len) = content_length {
|
||||||
|
self.no_chunking(len);
|
||||||
|
self.body(SizedStream::new(len, stream))
|
||||||
|
} else {
|
||||||
|
self.body(BodyStream::new(stream))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a JSON body and build the `HttpResponse`.
|
/// Set a JSON body and build the `HttpResponse`.
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ use crate::{HttpResponse, HttpResponseBuilder};
|
||||||
|
|
||||||
macro_rules! static_resp {
|
macro_rules! static_resp {
|
||||||
($name:ident, $status:expr) => {
|
($name:ident, $status:expr) => {
|
||||||
#[allow(non_snake_case, missing_docs)]
|
#[allow(non_snake_case)]
|
||||||
|
#[doc = concat!("Creates a new response builder with the status code `", stringify!($status), "`.")]
|
||||||
pub fn $name() -> HttpResponseBuilder {
|
pub fn $name() -> HttpResponseBuilder {
|
||||||
HttpResponseBuilder::new($status)
|
HttpResponseBuilder::new($status)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::{Borrow, Cow},
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
|
collections::HashMap,
|
||||||
fmt::Write as _,
|
fmt::Write as _,
|
||||||
|
hash::{BuildHasher, Hash},
|
||||||
rc::{Rc, Weak},
|
rc::{Rc, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -140,6 +142,56 @@ impl ResourceMap {
|
||||||
})
|
})
|
||||||
.ok_or(UrlGenerationError::NotEnoughElements)?;
|
.ok_or(UrlGenerationError::NotEnoughElements)?;
|
||||||
|
|
||||||
|
self.url_from_path(req, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generate URL for named resource using map of dynamic segment values.
|
||||||
|
///
|
||||||
|
/// Check [`HttpRequest::url_for_map`] for detailed information.
|
||||||
|
pub fn url_for_map<K, V, S>(
|
||||||
|
&self,
|
||||||
|
req: &HttpRequest,
|
||||||
|
name: &str,
|
||||||
|
elements: &HashMap<K, V, S>,
|
||||||
|
) -> Result<Url, UrlGenerationError>
|
||||||
|
where
|
||||||
|
K: Borrow<str> + Eq + Hash,
|
||||||
|
V: AsRef<str>,
|
||||||
|
S: BuildHasher,
|
||||||
|
{
|
||||||
|
let path = self
|
||||||
|
.named
|
||||||
|
.get(name)
|
||||||
|
.ok_or(UrlGenerationError::ResourceNotFound)?
|
||||||
|
.root_rmap_fn(String::with_capacity(AVG_PATH_LEN), |mut acc, node| {
|
||||||
|
node.pattern
|
||||||
|
.resource_path_from_map(&mut acc, elements)
|
||||||
|
.then_some(acc)
|
||||||
|
})
|
||||||
|
.ok_or(UrlGenerationError::NotEnoughElements)?;
|
||||||
|
|
||||||
|
self.url_from_path(req, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generate URL for named resource using an iterator of key-value pairs.
|
||||||
|
///
|
||||||
|
/// Check [`HttpRequest::url_for_iter`] for detailed information.
|
||||||
|
pub fn url_for_iter<K, V, I>(
|
||||||
|
&self,
|
||||||
|
req: &HttpRequest,
|
||||||
|
name: &str,
|
||||||
|
elements: I,
|
||||||
|
) -> Result<Url, UrlGenerationError>
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = (K, V)>,
|
||||||
|
K: Borrow<str> + Eq + Hash,
|
||||||
|
V: AsRef<str>,
|
||||||
|
{
|
||||||
|
let elements = elements.into_iter().collect::<FoldHashMap<K, V>>();
|
||||||
|
self.url_for_map(req, name, &elements)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn url_from_path(&self, req: &HttpRequest, path: String) -> Result<Url, UrlGenerationError> {
|
||||||
let (base, path): (Cow<'_, _>, _) = if path.starts_with('/') {
|
let (base, path): (Cow<'_, _>, _) = if path.starts_with('/') {
|
||||||
// build full URL from connection info parts and resource path
|
// build full URL from connection info parts and resource path
|
||||||
let conn = req.connection_info();
|
let conn = req.connection_info();
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ struct Config {
|
||||||
keep_alive: KeepAlive,
|
keep_alive: KeepAlive,
|
||||||
client_request_timeout: Duration,
|
client_request_timeout: Duration,
|
||||||
client_disconnect_timeout: Duration,
|
client_disconnect_timeout: Duration,
|
||||||
|
h1_allow_half_closed: bool,
|
||||||
#[allow(dead_code)] // only dead when no TLS features are enabled
|
#[allow(dead_code)] // only dead when no TLS features are enabled
|
||||||
tls_handshake_timeout: Option<Duration>,
|
tls_handshake_timeout: Option<Duration>,
|
||||||
}
|
}
|
||||||
|
|
@ -116,6 +117,7 @@ where
|
||||||
keep_alive: KeepAlive::default(),
|
keep_alive: KeepAlive::default(),
|
||||||
client_request_timeout: Duration::from_secs(5),
|
client_request_timeout: Duration::from_secs(5),
|
||||||
client_disconnect_timeout: Duration::from_secs(1),
|
client_disconnect_timeout: Duration::from_secs(1),
|
||||||
|
h1_allow_half_closed: true,
|
||||||
tls_handshake_timeout: None,
|
tls_handshake_timeout: None,
|
||||||
})),
|
})),
|
||||||
backlog: 1024,
|
backlog: 1024,
|
||||||
|
|
@ -257,6 +259,18 @@ where
|
||||||
self.client_disconnect_timeout(Duration::from_millis(dur))
|
self.client_disconnect_timeout(Duration::from_millis(dur))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets whether HTTP/1 connections should support half-closures.
|
||||||
|
///
|
||||||
|
/// Clients can choose to shutdown their writer-side of the connection after completing their
|
||||||
|
/// request and while waiting for the server response. Setting this to `false` will cause the
|
||||||
|
/// server to abort the connection handling as soon as it detects an EOF from the client.
|
||||||
|
///
|
||||||
|
/// The default behavior is to allow, i.e. `true`
|
||||||
|
pub fn h1_allow_half_closed(self, allow: bool) -> Self {
|
||||||
|
self.config.lock().unwrap().h1_allow_half_closed = allow;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets function that will be called once before each connection is handled.
|
/// Sets function that will be called once before each connection is handled.
|
||||||
///
|
///
|
||||||
/// It will receive a `&std::any::Any`, which contains underlying connection type and an
|
/// It will receive a `&std::any::Any`, which contains underlying connection type and an
|
||||||
|
|
@ -558,6 +572,7 @@ where
|
||||||
.keep_alive(cfg.keep_alive)
|
.keep_alive(cfg.keep_alive)
|
||||||
.client_request_timeout(cfg.client_request_timeout)
|
.client_request_timeout(cfg.client_request_timeout)
|
||||||
.client_disconnect_timeout(cfg.client_disconnect_timeout)
|
.client_disconnect_timeout(cfg.client_disconnect_timeout)
|
||||||
|
.h1_allow_half_closed(cfg.h1_allow_half_closed)
|
||||||
.local_addr(addr);
|
.local_addr(addr);
|
||||||
|
|
||||||
if let Some(handler) = on_connect_fn.clone() {
|
if let Some(handler) = on_connect_fn.clone() {
|
||||||
|
|
@ -602,6 +617,7 @@ where
|
||||||
.keep_alive(cfg.keep_alive)
|
.keep_alive(cfg.keep_alive)
|
||||||
.client_request_timeout(cfg.client_request_timeout)
|
.client_request_timeout(cfg.client_request_timeout)
|
||||||
.client_disconnect_timeout(cfg.client_disconnect_timeout)
|
.client_disconnect_timeout(cfg.client_disconnect_timeout)
|
||||||
|
.h1_allow_half_closed(cfg.h1_allow_half_closed)
|
||||||
.local_addr(addr);
|
.local_addr(addr);
|
||||||
|
|
||||||
if let Some(handler) = on_connect_fn.clone() {
|
if let Some(handler) = on_connect_fn.clone() {
|
||||||
|
|
@ -677,6 +693,7 @@ where
|
||||||
let svc = HttpService::build()
|
let svc = HttpService::build()
|
||||||
.keep_alive(c.keep_alive)
|
.keep_alive(c.keep_alive)
|
||||||
.client_request_timeout(c.client_request_timeout)
|
.client_request_timeout(c.client_request_timeout)
|
||||||
|
.h1_allow_half_closed(c.h1_allow_half_closed)
|
||||||
.client_disconnect_timeout(c.client_disconnect_timeout);
|
.client_disconnect_timeout(c.client_disconnect_timeout);
|
||||||
|
|
||||||
let svc = if let Some(handler) = on_connect_fn.clone() {
|
let svc = if let Some(handler) = on_connect_fn.clone() {
|
||||||
|
|
@ -728,6 +745,7 @@ where
|
||||||
let svc = HttpService::build()
|
let svc = HttpService::build()
|
||||||
.keep_alive(c.keep_alive)
|
.keep_alive(c.keep_alive)
|
||||||
.client_request_timeout(c.client_request_timeout)
|
.client_request_timeout(c.client_request_timeout)
|
||||||
|
.h1_allow_half_closed(c.h1_allow_half_closed)
|
||||||
.client_disconnect_timeout(c.client_disconnect_timeout);
|
.client_disconnect_timeout(c.client_disconnect_timeout);
|
||||||
|
|
||||||
let svc = if let Some(handler) = on_connect_fn.clone() {
|
let svc = if let Some(handler) = on_connect_fn.clone() {
|
||||||
|
|
@ -794,6 +812,7 @@ where
|
||||||
let svc = HttpService::build()
|
let svc = HttpService::build()
|
||||||
.keep_alive(c.keep_alive)
|
.keep_alive(c.keep_alive)
|
||||||
.client_request_timeout(c.client_request_timeout)
|
.client_request_timeout(c.client_request_timeout)
|
||||||
|
.h1_allow_half_closed(c.h1_allow_half_closed)
|
||||||
.client_disconnect_timeout(c.client_disconnect_timeout);
|
.client_disconnect_timeout(c.client_disconnect_timeout);
|
||||||
|
|
||||||
let svc = if let Some(handler) = on_connect_fn.clone() {
|
let svc = if let Some(handler) = on_connect_fn.clone() {
|
||||||
|
|
@ -860,6 +879,7 @@ where
|
||||||
let svc = HttpService::build()
|
let svc = HttpService::build()
|
||||||
.keep_alive(c.keep_alive)
|
.keep_alive(c.keep_alive)
|
||||||
.client_request_timeout(c.client_request_timeout)
|
.client_request_timeout(c.client_request_timeout)
|
||||||
|
.h1_allow_half_closed(c.h1_allow_half_closed)
|
||||||
.client_disconnect_timeout(c.client_disconnect_timeout);
|
.client_disconnect_timeout(c.client_disconnect_timeout);
|
||||||
|
|
||||||
let svc = if let Some(handler) = on_connect_fn.clone() {
|
let svc = if let Some(handler) = on_connect_fn.clone() {
|
||||||
|
|
@ -927,6 +947,7 @@ where
|
||||||
.keep_alive(c.keep_alive)
|
.keep_alive(c.keep_alive)
|
||||||
.client_request_timeout(c.client_request_timeout)
|
.client_request_timeout(c.client_request_timeout)
|
||||||
.client_disconnect_timeout(c.client_disconnect_timeout)
|
.client_disconnect_timeout(c.client_disconnect_timeout)
|
||||||
|
.h1_allow_half_closed(c.h1_allow_half_closed)
|
||||||
.local_addr(addr);
|
.local_addr(addr);
|
||||||
|
|
||||||
let svc = if let Some(handler) = on_connect_fn.clone() {
|
let svc = if let Some(handler) = on_connect_fn.clone() {
|
||||||
|
|
@ -995,6 +1016,7 @@ where
|
||||||
.keep_alive(c.keep_alive)
|
.keep_alive(c.keep_alive)
|
||||||
.client_request_timeout(c.client_request_timeout)
|
.client_request_timeout(c.client_request_timeout)
|
||||||
.client_disconnect_timeout(c.client_disconnect_timeout)
|
.client_disconnect_timeout(c.client_disconnect_timeout)
|
||||||
|
.h1_allow_half_closed(c.h1_allow_half_closed)
|
||||||
.finish(map_config(fac, move |_| config.clone())),
|
.finish(map_config(fac, move |_| config.clone())),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
@ -1036,6 +1058,7 @@ where
|
||||||
let mut svc = HttpService::build()
|
let mut svc = HttpService::build()
|
||||||
.keep_alive(c.keep_alive)
|
.keep_alive(c.keep_alive)
|
||||||
.client_request_timeout(c.client_request_timeout)
|
.client_request_timeout(c.client_request_timeout)
|
||||||
|
.h1_allow_half_closed(c.h1_allow_half_closed)
|
||||||
.client_disconnect_timeout(c.client_disconnect_timeout);
|
.client_disconnect_timeout(c.client_disconnect_timeout);
|
||||||
|
|
||||||
if let Some(handler) = on_connect_fn.clone() {
|
if let Some(handler) = on_connect_fn.clone() {
|
||||||
|
|
|
||||||
|
|
@ -616,7 +616,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
let (req, mut pl) = TestRequest::default()
|
let (mut req, mut pl) = TestRequest::default()
|
||||||
.insert_header((
|
.insert_header((
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
header::HeaderValue::from_static("application/json"),
|
header::HeaderValue::from_static("application/json"),
|
||||||
|
|
@ -624,6 +624,7 @@ mod tests {
|
||||||
.set_payload(Bytes::from_static(&[0u8; 1000]))
|
.set_payload(Bytes::from_static(&[0u8; 1000]))
|
||||||
.to_http_parts();
|
.to_http_parts();
|
||||||
|
|
||||||
|
req.head_mut().headers_mut().remove(header::CONTENT_LENGTH);
|
||||||
let json = JsonBody::<MyObject>::new(&req, &mut pl, None, true)
|
let json = JsonBody::<MyObject>::new(&req, &mut pl, None, true)
|
||||||
.limit(100)
|
.limit(100)
|
||||||
.await;
|
.await;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ mod query;
|
||||||
mod readlines;
|
mod readlines;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
either::Either,
|
either::{Either, EitherExtractError},
|
||||||
form::{Form, FormConfig, UrlEncoded},
|
form::{Form, FormConfig, UrlEncoded},
|
||||||
header::Header,
|
header::Header,
|
||||||
html::Html,
|
html::Html,
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ use crate::{
|
||||||
///
|
///
|
||||||
/// A dynamic segment is specified in the form `{identifier}`, where the identifier can be used
|
/// A dynamic segment is specified in the form `{identifier}`, where the identifier can be used
|
||||||
/// later in a request handler to access the matched value for that segment. This is done by looking
|
/// later in a request handler to access the matched value for that segment. This is done by looking
|
||||||
/// up the identifier in the `Path` object returned by [`HttpRequest.match_info()`] method.
|
/// up the identifier in the `Path` object returned by [`HttpRequest::match_info()`](crate::HttpRequest::match_info) method.
|
||||||
///
|
///
|
||||||
/// By default, each segment matches the regular expression `[^{}/]+`.
|
/// By default, each segment matches the regular expression `[^{}/]+`.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -688,30 +688,20 @@ async fn test_brotli_encoding_large_openssl() {
|
||||||
|
|
||||||
#[cfg(feature = "rustls-0_23")]
|
#[cfg(feature = "rustls-0_23")]
|
||||||
mod plus_rustls {
|
mod plus_rustls {
|
||||||
use std::io::BufReader;
|
|
||||||
|
|
||||||
use rustls::{pki_types::PrivateKeyDer, ServerConfig as RustlsServerConfig};
|
use rustls::{pki_types::PrivateKeyDer, ServerConfig as RustlsServerConfig};
|
||||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
use rustls_pki_types::PrivatePkcs8KeyDer;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn tls_config() -> RustlsServerConfig {
|
fn tls_config() -> RustlsServerConfig {
|
||||||
let rcgen::CertifiedKey { cert, key_pair } =
|
let rcgen::CertifiedKey { cert, key_pair } =
|
||||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||||
let cert_file = cert.pem();
|
let cert_chain = vec![cert.der().clone()];
|
||||||
let key_file = key_pair.serialize_pem();
|
let key_der = PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key_pair.serialize_der()));
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
RustlsServerConfig::builder()
|
RustlsServerConfig::builder()
|
||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_single_cert(cert_chain, PrivateKeyDer::Pkcs8(keys.remove(0)))
|
.with_single_cert(cert_chain, key_der)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,115 @@
|
||||||
|
use std::{
|
||||||
|
pin::Pin,
|
||||||
|
task::{Context, Poll},
|
||||||
|
};
|
||||||
|
|
||||||
|
use actix_web::{
|
||||||
|
http::header::{self, HeaderValue},
|
||||||
|
HttpResponse,
|
||||||
|
};
|
||||||
|
use bytes::Bytes;
|
||||||
|
use futures_core::Stream;
|
||||||
|
|
||||||
|
struct FixedSizeStream {
|
||||||
|
data: Vec<u8>,
|
||||||
|
yielded: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FixedSizeStream {
|
||||||
|
fn new(size: usize) -> Self {
|
||||||
|
Self {
|
||||||
|
data: vec![0u8; size],
|
||||||
|
yielded: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Stream for FixedSizeStream {
|
||||||
|
type Item = Result<Bytes, std::io::Error>;
|
||||||
|
|
||||||
|
fn poll_next(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
|
if self.yielded {
|
||||||
|
Poll::Ready(None)
|
||||||
|
} else {
|
||||||
|
self.yielded = true;
|
||||||
|
let data = std::mem::take(&mut self.data);
|
||||||
|
Poll::Ready(Some(Ok(Bytes::from(data))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_streaming_response_with_content_length() {
|
||||||
|
let stream = FixedSizeStream::new(100);
|
||||||
|
|
||||||
|
let resp = HttpResponse::Ok()
|
||||||
|
.append_header((header::CONTENT_LENGTH, "100"))
|
||||||
|
.streaming(stream);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
resp.headers().get(header::CONTENT_LENGTH),
|
||||||
|
Some(&HeaderValue::from_static("100")),
|
||||||
|
"Content-Length should be preserved when explicitly set"
|
||||||
|
);
|
||||||
|
|
||||||
|
let has_chunked = resp
|
||||||
|
.headers()
|
||||||
|
.get(header::TRANSFER_ENCODING)
|
||||||
|
.map(|v| v.to_str().unwrap_or(""))
|
||||||
|
.unwrap_or("")
|
||||||
|
.contains("chunked");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
!has_chunked,
|
||||||
|
"chunked should not be used when Content-Length is provided"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
resp.headers().get(header::CONTENT_TYPE),
|
||||||
|
Some(&HeaderValue::from_static("application/octet-stream")),
|
||||||
|
"Content-Type should default to application/octet-stream"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_streaming_response_default_content_type() {
|
||||||
|
let stream = FixedSizeStream::new(50);
|
||||||
|
|
||||||
|
let resp = HttpResponse::Ok().streaming(stream);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
resp.headers().get(header::CONTENT_TYPE),
|
||||||
|
Some(&HeaderValue::from_static("application/octet-stream")),
|
||||||
|
"Content-Type should default to application/octet-stream"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_streaming_response_user_defined_content_type() {
|
||||||
|
let stream = FixedSizeStream::new(25);
|
||||||
|
|
||||||
|
let resp = HttpResponse::Ok()
|
||||||
|
.insert_header((header::CONTENT_TYPE, "text/plain"))
|
||||||
|
.streaming(stream);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
resp.headers().get(header::CONTENT_TYPE),
|
||||||
|
Some(&HeaderValue::from_static("text/plain")),
|
||||||
|
"User-defined Content-Type should be preserved"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_streaming_response_empty_stream() {
|
||||||
|
let stream = FixedSizeStream::new(0);
|
||||||
|
|
||||||
|
let resp = HttpResponse::Ok()
|
||||||
|
.append_header((header::CONTENT_LENGTH, "0"))
|
||||||
|
.streaming(stream);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
resp.headers().get(header::CONTENT_LENGTH),
|
||||||
|
Some(&HeaderValue::from_static("0")),
|
||||||
|
"Content-Length 0 should be preserved for empty streams"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,17 @@
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- Minimum supported Rust version (MSRV) is now 1.88.
|
||||||
|
|
||||||
|
## 3.8.1
|
||||||
|
|
||||||
|
- Fix a bug where `GO_AWAY` errors did not stop connections from returning to the pool.
|
||||||
|
|
||||||
|
## 3.8.0
|
||||||
|
|
||||||
|
- Add `hickory-dns` crate feature (off-by-default).
|
||||||
|
- The `trust-dns` crate feature now delegates DNS resolution to `hickory-dns`.
|
||||||
|
|
||||||
## 3.7.0
|
## 3.7.0
|
||||||
|
|
||||||
- Update `brotli` dependency to `8`.
|
- Update `brotli` dependency to `8`.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "awc"
|
name = "awc"
|
||||||
version = "3.7.0"
|
version = "3.8.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Async HTTP and WebSocket client library"
|
description = "Async HTTP and WebSocket client library"
|
||||||
keywords = ["actix", "http", "framework", "async", "web"]
|
keywords = ["actix", "http", "framework", "async", "web"]
|
||||||
|
|
@ -16,7 +16,6 @@ license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
|
||||||
features = [
|
features = [
|
||||||
"cookies",
|
"cookies",
|
||||||
"openssl",
|
"openssl",
|
||||||
|
|
@ -83,8 +82,10 @@ compress-zstd = ["actix-http/compress-zstd", "__compress"]
|
||||||
# Cookie parsing and cookie jar
|
# Cookie parsing and cookie jar
|
||||||
cookies = ["dep:cookie"]
|
cookies = ["dep:cookie"]
|
||||||
|
|
||||||
# Use `trust-dns-resolver` crate as DNS resolver
|
# Use `hickory-dns-resolver` crate as DNS resolver
|
||||||
trust-dns = ["trust-dns-resolver"]
|
hickory-dns = ["dep:hickory-resolver"]
|
||||||
|
# Use `trust-dns-resolver` crate as DNS resolver (deprecated, use `hickory-dns`)
|
||||||
|
trust-dns = ["hickory-dns"]
|
||||||
|
|
||||||
# Internal (PRIVATE!) features used to aid testing and checking feature status.
|
# Internal (PRIVATE!) features used to aid testing and checking feature status.
|
||||||
# Don't rely on these whatsoever. They may disappear at anytime.
|
# Don't rely on these whatsoever. They may disappear at anytime.
|
||||||
|
|
@ -109,7 +110,7 @@ cfg-if = "1"
|
||||||
derive_more = { version = "2", features = ["display", "error", "from"] }
|
derive_more = { version = "2", features = ["display", "error", "from"] }
|
||||||
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
futures-core = { version = "0.3.17", default-features = false, features = ["alloc"] }
|
||||||
futures-util = { version = "0.3.17", default-features = false, features = ["alloc", "sink"] }
|
futures-util = { version = "0.3.17", default-features = false, features = ["alloc", "sink"] }
|
||||||
h2 = "0.3.26"
|
h2 = "0.3.27"
|
||||||
http = "0.2.7"
|
http = "0.2.7"
|
||||||
itoa = "1"
|
itoa = "1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
@ -130,7 +131,7 @@ tls-rustls-0_21 = { package = "rustls", version = "0.21", optional = true, featu
|
||||||
tls-rustls-0_22 = { package = "rustls", version = "0.22", optional = true }
|
tls-rustls-0_22 = { package = "rustls", version = "0.22", optional = true }
|
||||||
tls-rustls-0_23 = { package = "rustls", version = "0.23", optional = true, default-features = false }
|
tls-rustls-0_23 = { package = "rustls", version = "0.23", optional = true, default-features = false }
|
||||||
|
|
||||||
trust-dns-resolver = { version = "0.23", optional = true }
|
hickory-resolver = { version = "0.25", optional = true, features = ["system-config", "tokio"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-http = { version = "3.7", features = ["openssl"] }
|
actix-http = { version = "3.7", features = ["openssl"] }
|
||||||
|
|
@ -148,7 +149,7 @@ flate2 = "1.0.13"
|
||||||
futures-util = { version = "0.3.17", default-features = false }
|
futures-util = { version = "0.3.17", default-features = false }
|
||||||
static_assertions = "1.1"
|
static_assertions = "1.1"
|
||||||
rcgen = "0.13"
|
rcgen = "0.13"
|
||||||
rustls-pemfile = "2"
|
rustls-pki-types = "1.13.1"
|
||||||
tokio = { version = "1.38.2", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.38.2", features = ["rt-multi-thread", "macros"] }
|
||||||
zstd = "0.13"
|
zstd = "0.13"
|
||||||
tls-rustls-0_23 = { package = "rustls", version = "0.23" } # add rustls 0.23 with default features to make aws_lc_rs work in tests
|
tls-rustls-0_23 = { package = "rustls", version = "0.23" } # add rustls 0.23 with default features to make aws_lc_rs work in tests
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,16 @@
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
|
|
||||||
[](https://crates.io/crates/awc)
|
[](https://crates.io/crates/awc)
|
||||||
[](https://docs.rs/awc/3.7.0)
|
[](https://docs.rs/awc/3.8.1)
|
||||||

|

|
||||||
[](https://deps.rs/crate/awc/3.7.0)
|
[](https://deps.rs/crate/awc/3.8.1)
|
||||||
[](https://discord.gg/NWpN5mmg3x)
|
[](https://discord.gg/NWpN5mmg3x)
|
||||||
|
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
[Example project using TLS-enabled client →](https://github.com/actix/examples/tree/master/https-tls/awc-https)
|
[Example project using TLS-enabled client →](https://github.com/actix/examples/tree/main/https-tls/awc-https)
|
||||||
|
|
||||||
Basic usage:
|
Basic usage:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1037,7 +1037,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "trust-dns"))]
|
#[cfg(not(feature = "hickory-dns"))]
|
||||||
mod resolver {
|
mod resolver {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
@ -1046,24 +1046,25 @@ mod resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "trust-dns")]
|
#[cfg(feature = "hickory-dns")]
|
||||||
mod resolver {
|
mod resolver {
|
||||||
use std::{cell::RefCell, net::SocketAddr};
|
use std::{cell::OnceCell, net::SocketAddr};
|
||||||
|
|
||||||
use actix_tls::connect::Resolve;
|
use actix_tls::connect::Resolve;
|
||||||
use trust_dns_resolver::{
|
use hickory_resolver::{
|
||||||
config::{ResolverConfig, ResolverOpts},
|
config::{ResolverConfig, ResolverOpts},
|
||||||
|
name_server::TokioConnectionProvider,
|
||||||
system_conf::read_system_conf,
|
system_conf::read_system_conf,
|
||||||
TokioAsyncResolver,
|
TokioResolver,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub(super) fn resolver() -> Resolver {
|
pub(super) fn resolver() -> Resolver {
|
||||||
// new type for impl Resolve trait for TokioAsyncResolver.
|
// new type for impl Resolve trait for TokioAsyncResolver.
|
||||||
struct TrustDnsResolver(TokioAsyncResolver);
|
struct HickoryDnsResolver(TokioResolver);
|
||||||
|
|
||||||
impl Resolve for TrustDnsResolver {
|
impl Resolve for HickoryDnsResolver {
|
||||||
fn lookup<'a>(
|
fn lookup<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
host: &'a str,
|
host: &'a str,
|
||||||
|
|
@ -1085,34 +1086,29 @@ mod resolver {
|
||||||
|
|
||||||
// resolver struct is cached in thread local so new clients can reuse the existing instance
|
// resolver struct is cached in thread local so new clients can reuse the existing instance
|
||||||
thread_local! {
|
thread_local! {
|
||||||
static TRUST_DNS_RESOLVER: RefCell<Option<Resolver>> = const { RefCell::new(None) };
|
static HICKORY_DNS_RESOLVER: OnceCell<Resolver> = const { OnceCell::new() };
|
||||||
}
|
}
|
||||||
|
|
||||||
// get from thread local or construct a new trust-dns resolver.
|
// get from thread local or construct a new hickory dns resolver.
|
||||||
TRUST_DNS_RESOLVER.with(|local| {
|
HICKORY_DNS_RESOLVER.with(|local| {
|
||||||
let resolver = local.borrow().as_ref().map(Clone::clone);
|
local
|
||||||
|
.get_or_init(|| {
|
||||||
match resolver {
|
|
||||||
Some(resolver) => resolver,
|
|
||||||
|
|
||||||
None => {
|
|
||||||
let (cfg, opts) = match read_system_conf() {
|
let (cfg, opts) = match read_system_conf() {
|
||||||
Ok((cfg, opts)) => (cfg, opts),
|
Ok((cfg, opts)) => (cfg, opts),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("Trust-DNS can not load system config: {err}");
|
log::error!("Hickory DNS can not load system config: {err}");
|
||||||
(ResolverConfig::default(), ResolverOpts::default())
|
(ResolverConfig::default(), ResolverOpts::default())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let resolver = TokioAsyncResolver::tokio(cfg, opts);
|
let resolver =
|
||||||
|
TokioResolver::builder_with_config(cfg, TokioConnectionProvider::default())
|
||||||
|
.with_options(opts)
|
||||||
|
.build();
|
||||||
|
|
||||||
// box trust dns resolver and put it in thread local.
|
Resolver::custom(HickoryDnsResolver(resolver))
|
||||||
let resolver = Resolver::custom(TrustDnsResolver(resolver));
|
})
|
||||||
*local.borrow_mut() = Some(resolver.clone());
|
.clone()
|
||||||
|
|
||||||
resolver
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ where
|
||||||
|
|
||||||
let res = poll_fn(|cx| io.poll_ready(cx)).await;
|
let res = poll_fn(|cx| io.poll_ready(cx)).await;
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
io.on_release(err.is_io());
|
io.on_release(err.is_io() || err.is_go_away());
|
||||||
return Err(SendRequestError::from(err));
|
return Err(SendRequestError::from(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ where
|
||||||
fut.await.map_err(SendRequestError::from)?
|
fut.await.map_err(SendRequestError::from)?
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
io.on_release(err.is_io());
|
io.on_release(err.is_io() || err.is_go_away());
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@
|
||||||
)]
|
)]
|
||||||
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
||||||
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
pub use actix_http::body;
|
pub use actix_http::body;
|
||||||
#[cfg(feature = "cookies")]
|
#[cfg(feature = "cookies")]
|
||||||
|
|
|
||||||
|
|
@ -309,10 +309,7 @@ impl ClientRequest {
|
||||||
/// Freeze request builder and construct `FrozenClientRequest`,
|
/// Freeze request builder and construct `FrozenClientRequest`,
|
||||||
/// which could be used for sending same request multiple times.
|
/// which could be used for sending same request multiple times.
|
||||||
pub fn freeze(self) -> Result<FrozenClientRequest, FreezeRequestError> {
|
pub fn freeze(self) -> Result<FrozenClientRequest, FreezeRequestError> {
|
||||||
let slf = match self.prep_for_sending() {
|
let slf = self.prep_for_sending()?;
|
||||||
Ok(slf) => slf,
|
|
||||||
Err(err) => return Err(err.into()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let request = FrozenClientRequest {
|
let request = FrozenClientRequest {
|
||||||
head: Rc::new(slf.head),
|
head: Rc::new(slf.head),
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,9 @@
|
||||||
|
|
||||||
extern crate tls_rustls_0_23 as rustls;
|
extern crate tls_rustls_0_23 as rustls;
|
||||||
|
|
||||||
use std::{
|
use std::sync::{
|
||||||
io::BufReader,
|
atomic::{AtomicUsize, Ordering},
|
||||||
sync::{
|
Arc,
|
||||||
atomic::{AtomicUsize, Ordering},
|
|
||||||
Arc,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_http::HttpService;
|
use actix_http::HttpService;
|
||||||
|
|
@ -16,29 +13,18 @@ use actix_service::{fn_service, map_config, ServiceFactoryExt};
|
||||||
use actix_tls::connect::rustls_0_23::webpki_roots_cert_store;
|
use actix_tls::connect::rustls_0_23::webpki_roots_cert_store;
|
||||||
use actix_utils::future::ok;
|
use actix_utils::future::ok;
|
||||||
use actix_web::{dev::AppConfig, http::Version, web, App, HttpResponse};
|
use actix_web::{dev::AppConfig, http::Version, web, App, HttpResponse};
|
||||||
use rustls::{
|
use rustls::{pki_types::ServerName, ClientConfig, ServerConfig};
|
||||||
pki_types::{CertificateDer, PrivateKeyDer, ServerName},
|
use rustls_pki_types::{CertificateDer, PrivateKeyDer, PrivatePkcs8KeyDer};
|
||||||
ClientConfig, ServerConfig,
|
|
||||||
};
|
|
||||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
|
||||||
|
|
||||||
fn tls_config() -> ServerConfig {
|
fn tls_config() -> ServerConfig {
|
||||||
let rcgen::CertifiedKey { cert, key_pair } =
|
let rcgen::CertifiedKey { cert, key_pair } =
|
||||||
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
rcgen::generate_simple_self_signed(["localhost".to_owned()]).unwrap();
|
||||||
let cert_file = cert.pem();
|
let cert_chain = vec![cert.der().clone()];
|
||||||
let key_file = key_pair.serialize_pem();
|
let key_der = PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key_pair.serialize_der()));
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
ServerConfig::builder()
|
ServerConfig::builder()
|
||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_single_cert(cert_chain, PrivateKeyDer::Pkcs8(keys.remove(0)))
|
.with_single_cert(cert_chain, key_der)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
[licenses]
|
||||||
|
confidence-threshold = 0.90
|
||||||
|
allow = [
|
||||||
|
"Apache-2.0",
|
||||||
|
"MIT",
|
||||||
|
"Unicode-3.0",
|
||||||
|
"ISC",
|
||||||
|
"CDLA-Permissive-2.0",
|
||||||
|
"BSD-3-Clause",
|
||||||
|
"Zlib",
|
||||||
|
"OpenSSL",
|
||||||
|
"MPL-2.0"
|
||||||
|
]
|
||||||
|
private = { ignore = true }
|
||||||
|
|
||||||
|
# FIXME: old rustls introduces old ring which is not set license field properly.
|
||||||
|
[[licenses.clarify]]
|
||||||
|
crate = "ring"
|
||||||
|
expression = "MIT AND ISC AND OpenSSL"
|
||||||
|
license-files = [
|
||||||
|
{ path = "LICENSE", hash = 0xbd0eed23 }
|
||||||
|
]
|
||||||
|
|
||||||
|
# FIXME: webpki is almost unmaintained and is not set license field properly.
|
||||||
|
# rustls has its own fork now so removing old rustls should resolve the issue.
|
||||||
|
[[licenses.clarify]]
|
||||||
|
crate = "webpki"
|
||||||
|
expression = "ISC"
|
||||||
|
license-files = [
|
||||||
|
{ path = "LICENSE", hash = 0x001c7e6c }
|
||||||
|
]
|
||||||
|
|
||||||
|
[bans]
|
||||||
|
multiple-versions = "allow"
|
||||||
|
|
||||||
|
[bans.build]
|
||||||
|
executables = "deny"
|
||||||
|
|
||||||
|
[advisories]
|
||||||
|
# because of old rustls support:
|
||||||
|
ignore = [
|
||||||
|
"RUSTSEC-2024-0336",
|
||||||
|
"RUSTSEC-2025-0009",
|
||||||
|
"RUSTSEC-2025-0010"
|
||||||
|
]
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue