mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-26 10:27:42 +02: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:
@ -101,8 +101,8 @@ impl Cors {
|
||||
preflight: true,
|
||||
send_wildcard: false,
|
||||
supports_credentials: true,
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
allow_private_network_access: false,
|
||||
#[cfg(feature = "draft-local-network-access")]
|
||||
allow_local_network_access: false,
|
||||
vary_header: true,
|
||||
block_on_origin_mismatch: true,
|
||||
};
|
||||
@ -422,19 +422,19 @@ impl Cors {
|
||||
|
||||
/// Allow private network access.
|
||||
///
|
||||
/// If true, injects the `Access-Control-Allow-Private-Network: true` header in responses if the
|
||||
/// request contained the `Access-Control-Request-Private-Network: true` header.
|
||||
/// If true, injects the `Access-Control-Allow-Local-Network: true` header in responses if the
|
||||
/// 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`.
|
||||
///
|
||||
/// [Private Network Access]: https://wicg.github.io/private-network-access
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "draft-private-network-access")))]
|
||||
pub fn allow_private_network_access(mut self) -> Cors {
|
||||
/// [Private Network Access]: https://wicg.github.io/local-network-access
|
||||
#[cfg(feature = "draft-local-network-access")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "draft-local-network-access")))]
|
||||
pub fn allow_local_network_access(mut self) -> Cors {
|
||||
if let Some(cors) = cors(&mut self.inner, &self.error) {
|
||||
cors.allow_private_network_access = true;
|
||||
cors.allow_local_network_access = true;
|
||||
}
|
||||
|
||||
self
|
||||
@ -514,8 +514,8 @@ impl Default for Cors {
|
||||
preflight: true,
|
||||
send_wildcard: false,
|
||||
supports_credentials: false,
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
allow_private_network_access: false,
|
||||
#[cfg(feature = "draft-local-network-access")]
|
||||
allow_local_network_access: false,
|
||||
vary_header: true,
|
||||
block_on_origin_mismatch: true,
|
||||
};
|
||||
|
@ -64,8 +64,8 @@ pub(crate) struct Inner {
|
||||
pub(crate) preflight: bool,
|
||||
pub(crate) send_wildcard: bool,
|
||||
pub(crate) supports_credentials: bool,
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
pub(crate) allow_private_network_access: bool,
|
||||
#[cfg(feature = "draft-local-network-access")]
|
||||
pub(crate) allow_local_network_access: bool,
|
||||
pub(crate) vary_header: 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(b", Origin, Access-Control-Request-Method, Access-Control-Request-Headers");
|
||||
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
val.extend(b", Access-Control-Allow-Private-Network");
|
||||
#[cfg(feature = "draft-local-network-access")]
|
||||
val.extend(b", Access-Control-Allow-Local-Network");
|
||||
|
||||
val.try_into().unwrap()
|
||||
}
|
||||
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
#[cfg(feature = "draft-local-network-access")]
|
||||
None => HeaderValue::from_static(
|
||||
"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(
|
||||
"Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
||||
),
|
||||
|
@ -7,9 +7,9 @@
|
||||
//! This CORS middleware automatically handles `OPTIONS` preflight requests.
|
||||
//!
|
||||
//! # Crate Features
|
||||
//! - `draft-private-network-access`: ⚠️ Unstable. Adds opt-in support for the [Private Network
|
||||
//! Access] spec extensions. This feature is unstable since it will follow any breaking changes in
|
||||
//! the draft spec until it is finalized.
|
||||
//! - `draft-local-network-access`: ⚠️ Unstable. Adds opt-in support for the [Local Network Access]
|
||||
//! spec extensions. This feature is unstable since it will follow any breaking changes in the
|
||||
//! draft spec until it is finalized.
|
||||
//!
|
||||
//! # Example
|
||||
//! ```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)]
|
||||
#![deny(rust_2018_idioms, nonstandard_style)]
|
||||
|
@ -93,14 +93,14 @@ impl<S> CorsMiddleware<S> {
|
||||
res.insert_header((header::ACCESS_CONTROL_ALLOW_HEADERS, headers.clone()));
|
||||
}
|
||||
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
if inner.allow_private_network_access
|
||||
#[cfg(feature = "draft-local-network-access")]
|
||||
if inner.allow_local_network_access
|
||||
&& req
|
||||
.headers()
|
||||
.contains_key("access-control-request-private-network")
|
||||
.contains_key("access-control-request-local-network")
|
||||
{
|
||||
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"),
|
||||
));
|
||||
}
|
||||
@ -149,7 +149,6 @@ impl<S> CorsMiddleware<S> {
|
||||
let expose_all_request_headers = res
|
||||
.headers()
|
||||
.keys()
|
||||
.into_iter()
|
||||
.map(|name| name.as_str())
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
@ -174,15 +173,15 @@ impl<S> CorsMiddleware<S> {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "draft-private-network-access")]
|
||||
if inner.allow_private_network_access
|
||||
#[cfg(feature = "draft-local-network-access")]
|
||||
if inner.allow_local_network_access
|
||||
&& res
|
||||
.request()
|
||||
.headers()
|
||||
.contains_key("access-control-request-private-network")
|
||||
.contains_key("access-control-request-local-network")
|
||||
{
|
||||
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"),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user