feat: Promote rpxy-lib/sticky-cookie to top-level feature

.. and fix compile warnings when disabled
This commit is contained in:
Jonas Berlin 2024-10-28 11:22:46 +02:00
commit 8e1a0e78d1
5 changed files with 13 additions and 12 deletions

View file

@ -13,10 +13,10 @@ publish.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features] [features]
# default = ["http3-quinn", "cache", "rustls-backend", "acme", "post-quantum"] # default = ["http3-quinn", "cache", "rustls-backend", "acme", "sticky-cookie", "post-quantum"]
# default = ["http3-s2n", "cache", "rustls-backend", "acme", "post-quantum"] # default = ["http3-s2n", "cache", "rustls-backend", "acme", "sticky-cookie", "post-quantum"]
default = ["http3-quinn", "cache", "rustls-backend", "acme"] default = ["http3-quinn", "cache", "rustls-backend", "acme", "sticky-cookie"]
# default = ["http3-s2n", "cache", "rustls-backend", "acme"] # default = ["http3-s2n", "cache", "rustls-backend", "acme", "sticky-cookie"]
http3-quinn = ["rpxy-lib/http3-quinn"] http3-quinn = ["rpxy-lib/http3-quinn"]
http3-s2n = ["rpxy-lib/http3-s2n"] http3-s2n = ["rpxy-lib/http3-s2n"]
native-tls-backend = ["rpxy-lib/native-tls-backend"] native-tls-backend = ["rpxy-lib/native-tls-backend"]
@ -25,11 +25,10 @@ webpki-roots = ["rpxy-lib/webpki-roots"]
cache = ["rpxy-lib/cache"] cache = ["rpxy-lib/cache"]
acme = ["rpxy-lib/acme", "rpxy-acme"] acme = ["rpxy-lib/acme", "rpxy-acme"]
post-quantum = ["rpxy-lib/post-quantum"] post-quantum = ["rpxy-lib/post-quantum"]
sticky-cookie = ["rpxy-lib/sticky-cookie"]
[dependencies] [dependencies]
rpxy-lib = { path = "../rpxy-lib/", default-features = false, features = [ rpxy-lib = { path = "../rpxy-lib/", default-features = false }
"sticky-cookie",
] }
mimalloc = { version = "*", default-features = false } mimalloc = { version = "*", default-features = false }
anyhow = "1.0.91" anyhow = "1.0.91"

View file

@ -131,6 +131,4 @@ impl LoadBalance {
pub struct LoadBalanceContext { pub struct LoadBalanceContext {
#[cfg(feature = "sticky-cookie")] #[cfg(feature = "sticky-cookie")]
pub sticky_cookie: StickyCookie, pub sticky_cookie: StickyCookie,
#[cfg(not(feature = "sticky-cookie"))]
pub sticky_cookie: (),
} }

View file

@ -4,6 +4,7 @@ mod load_balance_sticky;
#[cfg(feature = "sticky-cookie")] #[cfg(feature = "sticky-cookie")]
mod sticky_cookie; mod sticky_cookie;
#[cfg(feature = "sticky-cookie")]
use super::upstream::Upstream; use super::upstream::Upstream;
use thiserror::Error; use thiserror::Error;
@ -16,6 +17,7 @@ pub use load_balance_sticky::LoadBalanceStickyBuilder;
pub use sticky_cookie::{StickyCookie, StickyCookieValue}; pub use sticky_cookie::{StickyCookie, StickyCookieValue};
/// Result type for load balancing /// Result type for load balancing
#[cfg(feature = "sticky-cookie")]
type LoadBalanceResult<T> = std::result::Result<T, LoadBalanceError>; type LoadBalanceResult<T> = std::result::Result<T, LoadBalanceError>;
/// Describes things that can go wrong in the Load Balance /// Describes things that can go wrong in the Load Balance
#[derive(Debug, Error)] #[derive(Debug, Error)]

View file

@ -6,7 +6,7 @@ use super::{
utils_request::InspectParseHost, utils_request::InspectParseHost,
}; };
use crate::{ use crate::{
backend::{BackendAppManager, LoadBalanceContext}, backend::BackendAppManager,
error::*, error::*,
forwarder::{ForwardRequest, Forwarder}, forwarder::{ForwardRequest, Forwarder},
globals::Globals, globals::Globals,
@ -25,7 +25,7 @@ use tokio::io::copy_bidirectional;
/// Context object to handle sticky cookies at HTTP message handler /// Context object to handle sticky cookies at HTTP message handler
pub(super) struct HandlerContext { pub(super) struct HandlerContext {
#[cfg(feature = "sticky-cookie")] #[cfg(feature = "sticky-cookie")]
pub(super) context_lb: Option<LoadBalanceContext>, pub(super) context_lb: Option<crate::backend::LoadBalanceContext>,
#[cfg(not(feature = "sticky-cookie"))] #[cfg(not(feature = "sticky-cookie"))]
pub(super) context_lb: Option<()>, pub(super) context_lb: Option<()>,
} }

View file

@ -3,7 +3,7 @@ use crate::{
backend::{UpstreamCandidates, UpstreamOption}, backend::{UpstreamCandidates, UpstreamOption},
log::*, log::*,
}; };
use anyhow::{anyhow, ensure, Result}; use anyhow::{anyhow, Result};
use bytes::BufMut; use bytes::BufMut;
use http::{header, HeaderMap, HeaderName, HeaderValue, Uri}; use http::{header, HeaderMap, HeaderName, HeaderValue, Uri};
use std::{borrow::Cow, net::SocketAddr}; use std::{borrow::Cow, net::SocketAddr};
@ -22,6 +22,8 @@ pub(super) fn takeout_sticky_cookie_lb_context(
headers: &mut HeaderMap, headers: &mut HeaderMap,
expected_cookie_name: &str, expected_cookie_name: &str,
) -> Result<Option<LoadBalanceContext>> { ) -> Result<Option<LoadBalanceContext>> {
use anyhow::ensure;
let mut headers_clone = headers.clone(); let mut headers_clone = headers.clone();
match headers_clone.entry(header::COOKIE) { match headers_clone.entry(header::COOKIE) {