From 6bfda7d69b0a6b3e1f67715841b0c90097a13e14 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 9 Aug 2022 18:08:44 +0200 Subject: [PATCH] Use new Cargo features to avoid implicit features for optional dependencies --- axum-extra/Cargo.toml | 27 +++++++++++++++--------- axum-extra/src/extract/cookie/mod.rs | 10 ++++----- axum-extra/src/extract/cookie/private.rs | 12 +++++------ axum-extra/src/extract/cookie/signed.rs | 14 ++++++------ axum/Cargo.toml | 12 +++++------ 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/axum-extra/Cargo.toml b/axum-extra/Cargo.toml index 7e513c4484..aad940475a 100644 --- a/axum-extra/Cargo.toml +++ b/axum-extra/Cargo.toml @@ -14,16 +14,23 @@ version = "0.3.5" [features] default = [] -async-read-body = ["tokio-util/io"] -cookie = ["cookie-lib"] -cookie-private = ["cookie", "cookie-lib/private"] -cookie-signed = ["cookie", "cookie-lib/signed"] -erased-json = ["serde_json", "serde"] -form = ["serde", "serde_html_form"] -json-lines = ["serde_json", "serde", "tokio-util/io", "tokio-stream/io-util"] -query = ["serde", "serde_html_form"] +async-read-body = ["dep:tokio-util", "tokio-util?/io"] +cookie = ["dep:cookie"] +cookie-private = ["cookie", "cookie?/private"] +cookie-signed = ["cookie", "cookie?/signed"] +erased-json = ["dep:serde_json", "dep:serde"] +form = ["dep:serde", "dep:serde_html_form"] +json-lines = [ + "dep:serde_json", + "dep:serde", + "dep:tokio-util", + "dep:tokio-stream", + "tokio-util?/io", + "tokio-stream?/io-util" +] +query = ["dep:serde", "dep:serde_html_form"] spa = ["tower-http/fs"] -typed-routing = ["axum-macros", "serde", "percent-encoding"] +typed-routing = ["dep:axum-macros", "dep:serde", "dep:percent-encoding"] [dependencies] axum = { path = "../axum", version = "0.5", default-features = false } @@ -40,7 +47,7 @@ tower-service = "0.3" # optional dependencies axum-macros = { path = "../axum-macros", version = "0.2.2", optional = true } -cookie-lib = { package = "cookie", version = "0.16", features = ["percent-encode"], optional = true } +cookie = { package = "cookie", version = "0.16", features = ["percent-encode"], optional = true } percent-encoding = { version = "2.1", optional = true } serde = { version = "1.0", optional = true } serde_html_form = { version = "0.1", optional = true } diff --git a/axum-extra/src/extract/cookie/mod.rs b/axum-extra/src/extract/cookie/mod.rs index 7bda1ea34e..04eb5877c7 100644 --- a/axum-extra/src/extract/cookie/mod.rs +++ b/axum-extra/src/extract/cookie/mod.rs @@ -23,10 +23,10 @@ pub use self::private::PrivateCookieJar; #[cfg(feature = "cookie-signed")] pub use self::signed::SignedCookieJar; -pub use cookie_lib::{Cookie, Expiration, SameSite}; +pub use cookie::{Cookie, Expiration, SameSite}; #[cfg(any(feature = "cookie-signed", feature = "cookie-private"))] -pub use cookie_lib::Key; +pub use cookie::Key; /// Extractor that grabs cookies from the request and manages the jar. /// @@ -84,7 +84,7 @@ pub use cookie_lib::Key; /// ``` #[derive(Debug)] pub struct CookieJar { - jar: cookie_lib::CookieJar, + jar: cookie::CookieJar, } #[async_trait] @@ -95,7 +95,7 @@ where type Rejection = Infallible; async fn from_request(req: &mut RequestParts) -> Result { - let mut jar = cookie_lib::CookieJar::new(); + let mut jar = cookie::CookieJar::new(); for cookie in cookies_from_request(req) { jar.add_original(cookie); } @@ -193,7 +193,7 @@ impl IntoResponse for CookieJar { } } -fn set_cookies(jar: cookie_lib::CookieJar, headers: &mut HeaderMap) { +fn set_cookies(jar: cookie::CookieJar, headers: &mut HeaderMap) { for cookie in jar.delta() { if let Ok(header_value) = cookie.encoded().to_string().parse() { headers.append(SET_COOKIE, header_value); diff --git a/axum-extra/src/extract/cookie/private.rs b/axum-extra/src/extract/cookie/private.rs index a583a3c9a9..032d020adb 100644 --- a/axum-extra/src/extract/cookie/private.rs +++ b/axum-extra/src/extract/cookie/private.rs @@ -5,7 +5,7 @@ use axum::{ response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, Extension, }; -use cookie_lib::PrivateJar; +use cookie::PrivateJar; use std::{convert::Infallible, fmt, marker::PhantomData}; /// Extractor that grabs private cookies from the request and manages the jar. @@ -57,7 +57,7 @@ use std::{convert::Infallible, fmt, marker::PhantomData}; /// # let app: Router = app; /// ``` pub struct PrivateCookieJar { - jar: cookie_lib::CookieJar, + jar: cookie::CookieJar, key: Key, // The key used to extract the key extension. Allows users to use multiple keys for different // jars. Maybe a library wants its own key. @@ -84,7 +84,7 @@ where async fn from_request(req: &mut RequestParts) -> Result { let key = Extension::::from_request(req).await?.0.into(); - let mut jar = cookie_lib::CookieJar::new(); + let mut jar = cookie::CookieJar::new(); let mut private_jar = jar.private_mut(&key); for cookie in cookies_from_request(req) { if let Some(cookie) = private_jar.decrypt(cookie) { @@ -176,11 +176,11 @@ impl PrivateCookieJar { } } - fn private_jar(&self) -> PrivateJar<&'_ cookie_lib::CookieJar> { + fn private_jar(&self) -> PrivateJar<&'_ cookie::CookieJar> { self.jar.private(&self.key) } - fn private_jar_mut(&mut self) -> PrivateJar<&'_ mut cookie_lib::CookieJar> { + fn private_jar_mut(&mut self) -> PrivateJar<&'_ mut cookie::CookieJar> { self.jar.private_mut(&self.key) } } @@ -202,7 +202,7 @@ impl IntoResponse for PrivateCookieJar { struct PrivateCookieJarIter<'a, K> { jar: &'a PrivateCookieJar, - iter: cookie_lib::Iter<'a>, + iter: cookie::Iter<'a>, } impl<'a, K> Iterator for PrivateCookieJarIter<'a, K> { diff --git a/axum-extra/src/extract/cookie/signed.rs b/axum-extra/src/extract/cookie/signed.rs index 51fb865c6e..05a3880eab 100644 --- a/axum-extra/src/extract/cookie/signed.rs +++ b/axum-extra/src/extract/cookie/signed.rs @@ -5,8 +5,8 @@ use axum::{ response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, Extension, }; -use cookie_lib::SignedJar; -use cookie_lib::{Cookie, Key}; +use cookie::SignedJar; +use cookie::{Cookie, Key}; use std::{convert::Infallible, fmt, marker::PhantomData}; /// Extractor that grabs signed cookies from the request and manages the jar. @@ -75,7 +75,7 @@ use std::{convert::Infallible, fmt, marker::PhantomData}; /// # let app: Router = app; /// ``` pub struct SignedCookieJar { - jar: cookie_lib::CookieJar, + jar: cookie::CookieJar, key: Key, // The key used to extract the key extension. Allows users to use multiple keys for different // jars. Maybe a library wants its own key. @@ -102,7 +102,7 @@ where async fn from_request(req: &mut RequestParts) -> Result { let key = Extension::::from_request(req).await?.0.into(); - let mut jar = cookie_lib::CookieJar::new(); + let mut jar = cookie::CookieJar::new(); let mut signed_jar = jar.signed_mut(&key); for cookie in cookies_from_request(req) { if let Some(cookie) = signed_jar.verify(cookie) { @@ -195,11 +195,11 @@ impl SignedCookieJar { } } - fn signed_jar(&self) -> SignedJar<&'_ cookie_lib::CookieJar> { + fn signed_jar(&self) -> SignedJar<&'_ cookie::CookieJar> { self.jar.signed(&self.key) } - fn signed_jar_mut(&mut self) -> SignedJar<&'_ mut cookie_lib::CookieJar> { + fn signed_jar_mut(&mut self) -> SignedJar<&'_ mut cookie::CookieJar> { self.jar.signed_mut(&self.key) } } @@ -221,7 +221,7 @@ impl IntoResponse for SignedCookieJar { struct SignedCookieJarIter<'a, K> { jar: &'a SignedCookieJar, - iter: cookie_lib::Iter<'a>, + iter: cookie::Iter<'a>, } impl<'a, K> Iterator for SignedCookieJarIter<'a, K> { diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 3ce902aab4..fda655d29e 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -13,17 +13,17 @@ repository = "https://github.com/tokio-rs/axum" [features] default = ["form", "http1", "json", "matched-path", "original-uri", "query", "tower-log"] -form = ["serde_urlencoded"] +form = ["dep:serde_urlencoded"] http1 = ["hyper/http1"] http2 = ["hyper/http2"] -json = ["serde_json"] -macros = ["axum-macros"] +json = ["dep:serde_json"] +macros = ["dep:axum-macros"] matched-path = [] -multipart = ["multer"] +multipart = ["dep:multer"] original-uri = [] -query = ["serde_urlencoded"] +query = ["dep:serde_urlencoded"] tower-log = ["tower/log"] -ws = ["tokio-tungstenite", "sha-1", "base64"] +ws = ["dep:tokio-tungstenite", "dep:sha-1", "dep:base64"] # Required for intra-doc links to resolve correctly __private_docs = ["tower/full", "tower-http/full"]