Skip to content

Commit

Permalink
feat: Promote rpxy-lib/sticky-cookie to top-level feature
Browse files Browse the repository at this point in the history
.. and fix compile warnings when disabled
  • Loading branch information
xkr47 committed Nov 2, 2024
1 parent dac1c38 commit 8e1a0e7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
13 changes: 6 additions & 7 deletions rpxy-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ publish.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
# default = ["http3-quinn", "cache", "rustls-backend", "acme", "post-quantum"]
# default = ["http3-s2n", "cache", "rustls-backend", "acme", "post-quantum"]
default = ["http3-quinn", "cache", "rustls-backend", "acme"]
# default = ["http3-s2n", "cache", "rustls-backend", "acme"]
# default = ["http3-quinn", "cache", "rustls-backend", "acme", "sticky-cookie", "post-quantum"]
# default = ["http3-s2n", "cache", "rustls-backend", "acme", "sticky-cookie", "post-quantum"]
default = ["http3-quinn", "cache", "rustls-backend", "acme", "sticky-cookie"]
# default = ["http3-s2n", "cache", "rustls-backend", "acme", "sticky-cookie"]
http3-quinn = ["rpxy-lib/http3-quinn"]
http3-s2n = ["rpxy-lib/http3-s2n"]
native-tls-backend = ["rpxy-lib/native-tls-backend"]
Expand All @@ -25,11 +25,10 @@ webpki-roots = ["rpxy-lib/webpki-roots"]
cache = ["rpxy-lib/cache"]
acme = ["rpxy-lib/acme", "rpxy-acme"]
post-quantum = ["rpxy-lib/post-quantum"]
sticky-cookie = ["rpxy-lib/sticky-cookie"]

[dependencies]
rpxy-lib = { path = "../rpxy-lib/", default-features = false, features = [
"sticky-cookie",
] }
rpxy-lib = { path = "../rpxy-lib/", default-features = false }

mimalloc = { version = "*", default-features = false }
anyhow = "1.0.91"
Expand Down
2 changes: 0 additions & 2 deletions rpxy-lib/src/backend/load_balance/load_balance_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,4 @@ impl LoadBalance {
pub struct LoadBalanceContext {
#[cfg(feature = "sticky-cookie")]
pub sticky_cookie: StickyCookie,
#[cfg(not(feature = "sticky-cookie"))]
pub sticky_cookie: (),
}
2 changes: 2 additions & 0 deletions rpxy-lib/src/backend/load_balance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod load_balance_sticky;
#[cfg(feature = "sticky-cookie")]
mod sticky_cookie;

#[cfg(feature = "sticky-cookie")]
use super::upstream::Upstream;
use thiserror::Error;

Expand All @@ -16,6 +17,7 @@ pub use load_balance_sticky::LoadBalanceStickyBuilder;
pub use sticky_cookie::{StickyCookie, StickyCookieValue};

/// Result type for load balancing
#[cfg(feature = "sticky-cookie")]
type LoadBalanceResult<T> = std::result::Result<T, LoadBalanceError>;
/// Describes things that can go wrong in the Load Balance
#[derive(Debug, Error)]
Expand Down
4 changes: 2 additions & 2 deletions rpxy-lib/src/message_handler/handler_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{
utils_request::InspectParseHost,
};
use crate::{
backend::{BackendAppManager, LoadBalanceContext},
backend::BackendAppManager,
error::*,
forwarder::{ForwardRequest, Forwarder},
globals::Globals,
Expand All @@ -25,7 +25,7 @@ use tokio::io::copy_bidirectional;
/// Context object to handle sticky cookies at HTTP message handler
pub(super) struct HandlerContext {
#[cfg(feature = "sticky-cookie")]
pub(super) context_lb: Option<LoadBalanceContext>,
pub(super) context_lb: Option<crate::backend::LoadBalanceContext>,
#[cfg(not(feature = "sticky-cookie"))]
pub(super) context_lb: Option<()>,
}
Expand Down
4 changes: 3 additions & 1 deletion rpxy-lib/src/message_handler/utils_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
backend::{UpstreamCandidates, UpstreamOption},
log::*,
};
use anyhow::{anyhow, ensure, Result};
use anyhow::{anyhow, Result};
use bytes::BufMut;
use http::{header, HeaderMap, HeaderName, HeaderValue, Uri};
use std::{borrow::Cow, net::SocketAddr};
Expand All @@ -22,6 +22,8 @@ pub(super) fn takeout_sticky_cookie_lb_context(
headers: &mut HeaderMap,
expected_cookie_name: &str,
) -> Result<Option<LoadBalanceContext>> {
use anyhow::ensure;

let mut headers_clone = headers.clone();

match headers_clone.entry(header::COOKIE) {
Expand Down

0 comments on commit 8e1a0e7

Please sign in to comment.