mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-27 17:22:57 +01:00
rename private-network-access feature (#320)
* update CI with concurrency options * cors: rename private-network => local-network * modernize CI * clippy * run api diff job on all features
This commit is contained in:
parent
8729f60f79
commit
111d95eaea
58
.github/workflows/ci-post-merge.yml
vendored
58
.github/workflows/ci-post-merge.yml
vendored
@ -1,8 +1,14 @@
|
|||||||
name: CI (post-merge)
|
name: CI (post-merge)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push: { branches: [master] }
|
||||||
branches: [master]
|
|
||||||
|
permissions:
|
||||||
|
contents: read # to fetch code (actions/checkout)
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_and_test_linux_nightly:
|
build_and_test_linux_nightly:
|
||||||
@ -27,39 +33,26 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install ${{ matrix.version }}
|
- name: Install Rust (${{ matrix.version }})
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ matrix.version }}-${{ matrix.target.triple }}
|
toolchain: ${{ matrix.version }}
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Install cargo-hack
|
- uses: taiki-e/cache-cargo-install-action@v1
|
||||||
uses: taiki-e/install-action@cargo-hack
|
with: { tool: cargo-hack }
|
||||||
|
|
||||||
- name: Generate Cargo.lock
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: generate-lockfile
|
|
||||||
- name: Cache Dependencies
|
|
||||||
uses: Swatinem/rust-cache@v2.1.0
|
|
||||||
|
|
||||||
- name: check minimal
|
- name: check minimal
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo ci-min
|
||||||
with: { command: ci-min }
|
|
||||||
|
|
||||||
- name: check minimal + examples
|
- name: check minimal + examples
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo ci-check-min-examples
|
||||||
with: { command: ci-check-min-examples }
|
|
||||||
|
|
||||||
- name: check default
|
- name: check default
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo ci-check
|
||||||
with: { command: ci-check }
|
|
||||||
|
|
||||||
- name: tests
|
- name: tests
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
timeout-minutes: 40
|
timeout-minutes: 40
|
||||||
with: { command: ci-test }
|
run: cargo ci-test
|
||||||
|
|
||||||
- name: Clear the cargo caches
|
- name: Clear the cargo caches
|
||||||
run: |
|
run: |
|
||||||
@ -86,18 +79,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install ${{ matrix.version }}
|
- name: Install Rust (${{ matrix.version }})
|
||||||
run: |
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
rustup install ${{ matrix.version }}-${{ matrix.target.triple }}
|
with:
|
||||||
rustup override set ${{ matrix.version }}-${{ matrix.target.triple }}
|
toolchain: ${{ matrix.version }}
|
||||||
|
|
||||||
- name: Install cargo-hack
|
- uses: taiki-e/cache-cargo-install-action@v1
|
||||||
uses: taiki-e/install-action@cargo-hack
|
with: { tool: cargo-hack }
|
||||||
|
|
||||||
- name: Generate Cargo.lock
|
|
||||||
run: cargo generate-lockfile
|
|
||||||
- name: Cache Dependencies
|
|
||||||
uses: Swatinem/rust-cache@v2.1.0
|
|
||||||
|
|
||||||
- name: check minimal
|
- name: check minimal
|
||||||
run: cargo ci-min
|
run: cargo ci-min
|
||||||
|
84
.github/workflows/ci.yml
vendored
84
.github/workflows/ci.yml
vendored
@ -1,10 +1,15 @@
|
|||||||
name: CI
|
name: CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request: {}
|
||||||
types: [opened, synchronize, reopened]
|
push: { branches: [master] }
|
||||||
push:
|
|
||||||
branches: [master]
|
permissions:
|
||||||
|
contents: read # to fetch code (actions/checkout)
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_and_test_linux:
|
build_and_test_linux:
|
||||||
@ -35,33 +40,18 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install ${{ matrix.version }}
|
- name: Install Rust (${{ matrix.version }})
|
||||||
run: |
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
rustup install ${{ matrix.version }}-${{ matrix.target.triple }}
|
with:
|
||||||
rustup override set ${{ matrix.version }}-${{ matrix.target.triple }}
|
toolchain: ${{ matrix.version }}
|
||||||
|
|
||||||
- name: Install cargo-hack
|
- uses: taiki-e/cache-cargo-install-action@v1
|
||||||
uses: taiki-e/install-action@cargo-hack
|
with: { tool: cargo-hack }
|
||||||
|
|
||||||
- name: workaround MSRV issues
|
- name: workaround MSRV issues
|
||||||
if: matrix.version != 'stable'
|
if: matrix.version != 'stable'
|
||||||
run: |
|
run: |
|
||||||
cargo install cargo-edit --version=0.8.0
|
cargo update -p=time:0.3.20 --precise=0.3.16
|
||||||
cargo add env_logger@0.9 --dev -p=actix-cors
|
|
||||||
cargo add env_logger@0.9 --dev -p=actix-identity
|
|
||||||
cargo add env_logger@0.9 --dev -p=actix-redis
|
|
||||||
cargo add env_logger@0.9 --dev -p=actix-session
|
|
||||||
cargo add env_logger@0.9 --dev -p=actix-settings
|
|
||||||
|
|
||||||
- name: Generate Cargo.lock
|
|
||||||
run: cargo generate-lockfile
|
|
||||||
- name: Cache Dependencies
|
|
||||||
uses: Swatinem/rust-cache@v2.1.0
|
|
||||||
|
|
||||||
- name: workaround MSRV issues
|
|
||||||
if: matrix.version != 'stable'
|
|
||||||
run: |
|
|
||||||
cargo update -p=time --precise=0.3.13
|
|
||||||
|
|
||||||
- name: check minimal
|
- name: check minimal
|
||||||
run: cargo ci-min
|
run: cargo ci-min
|
||||||
@ -102,33 +92,21 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install ${{ matrix.version }}
|
- name: Install Rust (${{ matrix.version }})
|
||||||
run: |
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
rustup install ${{ matrix.version }}-${{ matrix.target.triple }}
|
with:
|
||||||
rustup override set ${{ matrix.version }}-${{ matrix.target.triple }}
|
toolchain: ${{ matrix.version }}
|
||||||
|
|
||||||
- name: Install cargo-hack
|
- uses: taiki-e/cache-cargo-install-action@v1
|
||||||
uses: taiki-e/install-action@cargo-hack
|
with: { tool: cargo-hack }
|
||||||
|
|
||||||
|
- uses: taiki-e/cache-cargo-install-action@v1
|
||||||
|
with: { tool: cargo-hack }
|
||||||
|
|
||||||
- name: workaround MSRV issues
|
- name: workaround MSRV issues
|
||||||
if: matrix.version != 'stable'
|
if: matrix.version != 'stable'
|
||||||
run: |
|
run: |
|
||||||
cargo install cargo-edit --version=0.8.0
|
cargo update -p=time:0.3.20 --precise=0.3.16
|
||||||
cargo add env_logger@0.9 --dev -p=actix-cors
|
|
||||||
cargo add env_logger@0.9 --dev -p=actix-identity
|
|
||||||
cargo add env_logger@0.9 --dev -p=actix-redis
|
|
||||||
cargo add env_logger@0.9 --dev -p=actix-session
|
|
||||||
cargo add env_logger@0.9 --dev -p=actix-settings
|
|
||||||
|
|
||||||
- name: Generate Cargo.lock
|
|
||||||
run: cargo generate-lockfile
|
|
||||||
- name: Cache Dependencies
|
|
||||||
uses: Swatinem/rust-cache@v2.1.0
|
|
||||||
|
|
||||||
- name: workaround MSRV issues
|
|
||||||
if: matrix.version != 'stable'
|
|
||||||
run: |
|
|
||||||
cargo update -p=time --precise=0.3.13
|
|
||||||
|
|
||||||
- name: check minimal
|
- name: check minimal
|
||||||
run: cargo ci-min
|
run: cargo ci-min
|
||||||
@ -155,14 +133,8 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install Rust (nightly)
|
- name: Install Rust (nightly)
|
||||||
run: |
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
rustup install nightly
|
with: { toolchain: nightly }
|
||||||
rustup override set nightly
|
|
||||||
|
|
||||||
- name: Generate Cargo.lock
|
|
||||||
run: cargo generate-lockfile
|
|
||||||
- name: Cache Dependencies
|
|
||||||
uses: Swatinem/rust-cache@v2.1.0
|
|
||||||
|
|
||||||
- name: doc tests
|
- name: doc tests
|
||||||
timeout-minutes: 40
|
timeout-minutes: 40
|
||||||
|
10
.github/workflows/coverage.yml
vendored
10
.github/workflows/coverage.yml
vendored
@ -3,8 +3,14 @@
|
|||||||
name: Coverage
|
name: Coverage
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push: { branches: [master] }
|
||||||
branches: [master]
|
|
||||||
|
permissions:
|
||||||
|
contents: read # to fetch code (actions/checkout)
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
coverage:
|
coverage:
|
||||||
|
52
.github/workflows/lint.yml
vendored
52
.github/workflows/lint.yml
vendored
@ -1,8 +1,13 @@
|
|||||||
name: Lint
|
name: Lint
|
||||||
|
|
||||||
on:
|
on: [pull_request]
|
||||||
pull_request:
|
|
||||||
types: [opened, synchronize, reopened]
|
permissions:
|
||||||
|
contents: read # to fetch code (actions/checkout)
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
fmt:
|
fmt:
|
||||||
@ -10,11 +15,12 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust (nightly)
|
||||||
run: |
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
rustup override set nightly
|
with:
|
||||||
rustup update nightly
|
toolchain: nightly
|
||||||
rustup component add rustfmt
|
components: rustfmt
|
||||||
|
|
||||||
- name: Check with rustfmt
|
- name: Check with rustfmt
|
||||||
run: cargo fmt --all -- --check
|
run: cargo fmt --all -- --check
|
||||||
|
|
||||||
@ -24,9 +30,31 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
run: |
|
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
rustup override set stable
|
with: { components: clippy }
|
||||||
rustup update stable
|
|
||||||
rustup component add rustfmt
|
|
||||||
- name: Check with Clippy
|
- name: Check with Clippy
|
||||||
run: cargo clippy --workspace --tests --all-features
|
run: cargo clippy --workspace --tests --all-features
|
||||||
|
|
||||||
|
public-api-diff:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout ${{ github.base_ref }}
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: ${{ github.base_ref }}
|
||||||
|
|
||||||
|
- name: checkout ${{ github.head_ref }}
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with: { toolchain: nightly }
|
||||||
|
|
||||||
|
- uses: taiki-e/cache-cargo-install-action@v1
|
||||||
|
with: { tool: cargo-public-api }
|
||||||
|
|
||||||
|
- name: generate API diff
|
||||||
|
run: |
|
||||||
|
for f in $(find -mindepth 2 -maxdepth 2 -name Cargo.toml); do
|
||||||
|
cargo public-api --manifest-path "$f" --all-features diff ${{ github.event.pull_request.base.sha }}..${{ github.sha }}
|
||||||
|
done
|
||||||
|
10
.github/workflows/upload-doc.yml
vendored
10
.github/workflows/upload-doc.yml
vendored
@ -1,8 +1,14 @@
|
|||||||
name: Upload Documentation
|
name: Upload Documentation
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push: { branches: [master] }
|
||||||
branches: [master]
|
|
||||||
|
permissions:
|
||||||
|
contents: read # to fetch code (actions/checkout)
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Unreleased - 2022-xx-xx
|
## Unreleased - 2022-xx-xx
|
||||||
|
|
||||||
|
- Rename `Cors::{allow_private_network_access => allow_local_network_access}()` and its unstable flag (`draft-private-network-access` => `draft-local-network-access`).
|
||||||
- Minimum supported Rust version (MSRV) is now 1.60.
|
- Minimum supported Rust version (MSRV) is now 1.60.
|
||||||
|
|
||||||
## 0.6.4 - 2022-10-28
|
## 0.6.4 - 2022-10-28
|
||||||
|
@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
|
|||||||
all-features = true
|
all-features = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
draft-private-network-access = []
|
draft-local-network-access = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-utils = "3"
|
actix-utils = "3"
|
||||||
|
@ -101,8 +101,8 @@ impl Cors {
|
|||||||
preflight: true,
|
preflight: true,
|
||||||
send_wildcard: false,
|
send_wildcard: false,
|
||||||
supports_credentials: true,
|
supports_credentials: true,
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
allow_private_network_access: false,
|
allow_local_network_access: false,
|
||||||
vary_header: true,
|
vary_header: true,
|
||||||
block_on_origin_mismatch: true,
|
block_on_origin_mismatch: true,
|
||||||
};
|
};
|
||||||
@ -422,19 +422,19 @@ impl Cors {
|
|||||||
|
|
||||||
/// Allow private network access.
|
/// Allow private network access.
|
||||||
///
|
///
|
||||||
/// If true, injects the `Access-Control-Allow-Private-Network: true` header in responses if the
|
/// If true, injects the `Access-Control-Allow-Local-Network: true` header in responses if the
|
||||||
/// request contained the `Access-Control-Request-Private-Network: true` header.
|
/// request contained the `Access-Control-Request-Local-Network: true` header.
|
||||||
///
|
///
|
||||||
/// For more information on this behavior, see the draft [Private Network Access] spec.
|
/// For more information on this behavior, see the draft [Local Network Access] spec.
|
||||||
///
|
///
|
||||||
/// Defaults to `false`.
|
/// Defaults to `false`.
|
||||||
///
|
///
|
||||||
/// [Private Network Access]: https://wicg.github.io/private-network-access
|
/// [Private Network Access]: https://wicg.github.io/local-network-access
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "draft-private-network-access")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "draft-local-network-access")))]
|
||||||
pub fn allow_private_network_access(mut self) -> Cors {
|
pub fn allow_local_network_access(mut self) -> Cors {
|
||||||
if let Some(cors) = cors(&mut self.inner, &self.error) {
|
if let Some(cors) = cors(&mut self.inner, &self.error) {
|
||||||
cors.allow_private_network_access = true;
|
cors.allow_local_network_access = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
@ -514,8 +514,8 @@ impl Default for Cors {
|
|||||||
preflight: true,
|
preflight: true,
|
||||||
send_wildcard: false,
|
send_wildcard: false,
|
||||||
supports_credentials: false,
|
supports_credentials: false,
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
allow_private_network_access: false,
|
allow_local_network_access: false,
|
||||||
vary_header: true,
|
vary_header: true,
|
||||||
block_on_origin_mismatch: true,
|
block_on_origin_mismatch: true,
|
||||||
};
|
};
|
||||||
|
@ -64,8 +64,8 @@ pub(crate) struct Inner {
|
|||||||
pub(crate) preflight: bool,
|
pub(crate) preflight: bool,
|
||||||
pub(crate) send_wildcard: bool,
|
pub(crate) send_wildcard: bool,
|
||||||
pub(crate) supports_credentials: bool,
|
pub(crate) supports_credentials: bool,
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
pub(crate) allow_private_network_access: bool,
|
pub(crate) allow_local_network_access: bool,
|
||||||
pub(crate) vary_header: bool,
|
pub(crate) vary_header: bool,
|
||||||
pub(crate) block_on_origin_mismatch: bool,
|
pub(crate) block_on_origin_mismatch: bool,
|
||||||
}
|
}
|
||||||
@ -222,19 +222,19 @@ pub(crate) fn add_vary_header(headers: &mut HeaderMap) {
|
|||||||
val.extend(hdr.as_bytes());
|
val.extend(hdr.as_bytes());
|
||||||
val.extend(b", Origin, Access-Control-Request-Method, Access-Control-Request-Headers");
|
val.extend(b", Origin, Access-Control-Request-Method, Access-Control-Request-Headers");
|
||||||
|
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
val.extend(b", Access-Control-Allow-Private-Network");
|
val.extend(b", Access-Control-Allow-Local-Network");
|
||||||
|
|
||||||
val.try_into().unwrap()
|
val.try_into().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
None => HeaderValue::from_static(
|
None => HeaderValue::from_static(
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, \
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, \
|
||||||
Access-Control-Allow-Private-Network",
|
Access-Control-Allow-Local-Network",
|
||||||
),
|
),
|
||||||
|
|
||||||
#[cfg(not(feature = "draft-private-network-access"))]
|
#[cfg(not(feature = "draft-local-network-access"))]
|
||||||
None => HeaderValue::from_static(
|
None => HeaderValue::from_static(
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||||
),
|
),
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
//! This CORS middleware automatically handles `OPTIONS` preflight requests.
|
//! This CORS middleware automatically handles `OPTIONS` preflight requests.
|
||||||
//!
|
//!
|
||||||
//! # Crate Features
|
//! # Crate Features
|
||||||
//! - `draft-private-network-access`: ⚠️ Unstable. Adds opt-in support for the [Private Network
|
//! - `draft-local-network-access`: ⚠️ Unstable. Adds opt-in support for the [Local Network Access]
|
||||||
//! Access] spec extensions. This feature is unstable since it will follow any breaking changes in
|
//! spec extensions. This feature is unstable since it will follow any breaking changes in the
|
||||||
//! the draft spec until it is finalized.
|
//! draft spec until it is finalized.
|
||||||
//!
|
//!
|
||||||
//! # Example
|
//! # Example
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
@ -46,7 +46,7 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! [Private Network Access]: https://wicg.github.io/private-network-access
|
//! [Local Network Access]: https://wicg.github.io/local-network-access
|
||||||
|
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![deny(rust_2018_idioms, nonstandard_style)]
|
#![deny(rust_2018_idioms, nonstandard_style)]
|
||||||
|
@ -93,14 +93,14 @@ impl<S> CorsMiddleware<S> {
|
|||||||
res.insert_header((header::ACCESS_CONTROL_ALLOW_HEADERS, headers.clone()));
|
res.insert_header((header::ACCESS_CONTROL_ALLOW_HEADERS, headers.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
if inner.allow_private_network_access
|
if inner.allow_local_network_access
|
||||||
&& req
|
&& req
|
||||||
.headers()
|
.headers()
|
||||||
.contains_key("access-control-request-private-network")
|
.contains_key("access-control-request-local-network")
|
||||||
{
|
{
|
||||||
res.insert_header((
|
res.insert_header((
|
||||||
header::HeaderName::from_static("access-control-allow-private-network"),
|
header::HeaderName::from_static("access-control-allow-local-network"),
|
||||||
HeaderValue::from_static("true"),
|
HeaderValue::from_static("true"),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -149,7 +149,6 @@ impl<S> CorsMiddleware<S> {
|
|||||||
let expose_all_request_headers = res
|
let expose_all_request_headers = res
|
||||||
.headers()
|
.headers()
|
||||||
.keys()
|
.keys()
|
||||||
.into_iter()
|
|
||||||
.map(|name| name.as_str())
|
.map(|name| name.as_str())
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
@ -174,15 +173,15 @@ impl<S> CorsMiddleware<S> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
if inner.allow_private_network_access
|
if inner.allow_local_network_access
|
||||||
&& res
|
&& res
|
||||||
.request()
|
.request()
|
||||||
.headers()
|
.headers()
|
||||||
.contains_key("access-control-request-private-network")
|
.contains_key("access-control-request-local-network")
|
||||||
{
|
{
|
||||||
res.headers_mut().insert(
|
res.headers_mut().insert(
|
||||||
header::HeaderName::from_static("access-control-allow-private-network"),
|
header::HeaderName::from_static("access-control-allow-local-network"),
|
||||||
HeaderValue::from_static("true"),
|
HeaderValue::from_static("true"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -264,15 +264,15 @@ async fn test_response() {
|
|||||||
.get(header::ACCESS_CONTROL_ALLOW_ORIGIN)
|
.get(header::ACCESS_CONTROL_ALLOW_ORIGIN)
|
||||||
.map(HeaderValue::as_bytes)
|
.map(HeaderValue::as_bytes)
|
||||||
);
|
);
|
||||||
#[cfg(not(feature = "draft-private-network-access"))]
|
#[cfg(not(feature = "draft-local-network-access"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::VARY).map(HeaderValue::as_bytes),
|
resp.headers().get(header::VARY).map(HeaderValue::as_bytes),
|
||||||
Some(&b"Origin, Access-Control-Request-Method, Access-Control-Request-Headers"[..]),
|
Some(&b"Origin, Access-Control-Request-Method, Access-Control-Request-Headers"[..]),
|
||||||
);
|
);
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::VARY).map(HeaderValue::as_bytes),
|
resp.headers().get(header::VARY).map(HeaderValue::as_bytes),
|
||||||
Some(&b"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Private-Network"[..]),
|
Some(&b"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Local-Network"[..]),
|
||||||
);
|
);
|
||||||
|
|
||||||
#[allow(clippy::needless_collect)]
|
#[allow(clippy::needless_collect)]
|
||||||
@ -317,7 +317,7 @@ async fn test_response() {
|
|||||||
.method(Method::OPTIONS)
|
.method(Method::OPTIONS)
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
let resp = test::call_service(&cors, req).await;
|
let resp = test::call_service(&cors, req).await;
|
||||||
#[cfg(not(feature = "draft-private-network-access"))]
|
#[cfg(not(feature = "draft-local-network-access"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
@ -325,10 +325,10 @@ async fn test_response() {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
b"Accept, Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
b"Accept, Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||||
);
|
);
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers().get(header::VARY).map(HeaderValue::as_bytes).unwrap(),
|
resp.headers().get(header::VARY).map(HeaderValue::as_bytes).unwrap(),
|
||||||
b"Accept, Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Private-Network",
|
b"Accept, Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Local-Network",
|
||||||
);
|
);
|
||||||
|
|
||||||
let cors = Cors::default()
|
let cors = Cors::default()
|
||||||
@ -478,7 +478,7 @@ async fn vary_header_on_all_handled_responses() {
|
|||||||
assert!(resp
|
assert!(resp
|
||||||
.headers()
|
.headers()
|
||||||
.contains_key(header::ACCESS_CONTROL_ALLOW_METHODS));
|
.contains_key(header::ACCESS_CONTROL_ALLOW_METHODS));
|
||||||
#[cfg(not(feature = "draft-private-network-access"))]
|
#[cfg(not(feature = "draft-local-network-access"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
@ -487,14 +487,14 @@ async fn vary_header_on_all_handled_responses() {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||||
);
|
);
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
.expect("response should have Vary header")
|
.expect("response should have Vary header")
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Private-Network",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Local-Network",
|
||||||
);
|
);
|
||||||
|
|
||||||
// follow-up regular request
|
// follow-up regular request
|
||||||
@ -504,7 +504,7 @@ async fn vary_header_on_all_handled_responses() {
|
|||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
let resp = test::call_service(&cors, req).await;
|
let resp = test::call_service(&cors, req).await;
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
#[cfg(not(feature = "draft-private-network-access"))]
|
#[cfg(not(feature = "draft-local-network-access"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
@ -513,14 +513,14 @@ async fn vary_header_on_all_handled_responses() {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||||
);
|
);
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
.expect("response should have Vary header")
|
.expect("response should have Vary header")
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Private-Network",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Local-Network",
|
||||||
);
|
);
|
||||||
|
|
||||||
let cors = Cors::default()
|
let cors = Cors::default()
|
||||||
@ -536,7 +536,7 @@ async fn vary_header_on_all_handled_responses() {
|
|||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
let resp = test::call_service(&cors, req).await;
|
let resp = test::call_service(&cors, req).await;
|
||||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
#[cfg(not(feature = "draft-private-network-access"))]
|
#[cfg(not(feature = "draft-local-network-access"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
@ -545,21 +545,21 @@ async fn vary_header_on_all_handled_responses() {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||||
);
|
);
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
.expect("response should have Vary header")
|
.expect("response should have Vary header")
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Private-Network",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Local-Network",
|
||||||
);
|
);
|
||||||
|
|
||||||
// regular request no origin
|
// regular request no origin
|
||||||
let req = TestRequest::default().method(Method::PUT).to_srv_request();
|
let req = TestRequest::default().method(Method::PUT).to_srv_request();
|
||||||
let resp = test::call_service(&cors, req).await;
|
let resp = test::call_service(&cors, req).await;
|
||||||
assert_eq!(resp.status(), StatusCode::OK);
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
#[cfg(not(feature = "draft-private-network-access"))]
|
#[cfg(not(feature = "draft-local-network-access"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
@ -568,14 +568,14 @@ async fn vary_header_on_all_handled_responses() {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||||
);
|
);
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
resp.headers()
|
resp.headers()
|
||||||
.get(header::VARY)
|
.get(header::VARY)
|
||||||
.expect("response should have Vary header")
|
.expect("response should have Vary header")
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Private-Network",
|
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Local-Network",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,12 +634,12 @@ async fn expose_all_request_header_values() {
|
|||||||
assert!(cd_hdr.contains("access-control-allow-origin"));
|
assert!(cd_hdr.contains("access-control-allow-origin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "draft-private-network-access")]
|
#[cfg(feature = "draft-local-network-access")]
|
||||||
#[actix_web::test]
|
#[actix_web::test]
|
||||||
async fn private_network_access() {
|
async fn private_network_access() {
|
||||||
let cors = Cors::permissive()
|
let cors = Cors::permissive()
|
||||||
.allowed_origin("https://public.site")
|
.allowed_origin("https://public.site")
|
||||||
.allow_private_network_access()
|
.allow_local_network_access()
|
||||||
.new_transform(fn_service(|req: ServiceRequest| async move {
|
.new_transform(fn_service(|req: ServiceRequest| async move {
|
||||||
let res = req.into_response(
|
let res = req.into_response(
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
@ -664,11 +664,11 @@ async fn private_network_access() {
|
|||||||
.insert_header((header::ORIGIN, "https://public.site"))
|
.insert_header((header::ORIGIN, "https://public.site"))
|
||||||
.insert_header((header::ACCESS_CONTROL_REQUEST_METHOD, "POST"))
|
.insert_header((header::ACCESS_CONTROL_REQUEST_METHOD, "POST"))
|
||||||
.insert_header((header::ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"))
|
.insert_header((header::ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"))
|
||||||
.insert_header(("Access-Control-Request-Private-Network", "true"))
|
.insert_header(("Access-Control-Request-Local-Network", "true"))
|
||||||
.to_srv_request();
|
.to_srv_request();
|
||||||
let res = test::call_service(&cors, req).await;
|
let res = test::call_service(&cors, req).await;
|
||||||
assert!(res.headers().contains_key("access-control-allow-origin"));
|
assert!(res.headers().contains_key("access-control-allow-origin"));
|
||||||
assert!(res
|
assert!(res
|
||||||
.headers()
|
.headers()
|
||||||
.contains_key("access-control-allow-private-network"));
|
.contains_key("access-control-allow-local-network"));
|
||||||
}
|
}
|
||||||
|
@ -726,10 +726,7 @@ pub mod test_helpers {
|
|||||||
|
|
||||||
impl ServiceResponseExt for ServiceResponse {
|
impl ServiceResponseExt for ServiceResponse {
|
||||||
fn get_cookie(&self, cookie_name: &str) -> Option<actix_web::cookie::Cookie<'_>> {
|
fn get_cookie(&self, cookie_name: &str) -> Option<actix_web::cookie::Cookie<'_>> {
|
||||||
self.response()
|
self.response().cookies().find(|c| c.name() == cookie_name)
|
||||||
.cookies()
|
|
||||||
.into_iter()
|
|
||||||
.find(|c| c.name() == cookie_name)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user