From 2f5def5c3c4ae0754171b0b9b63802801e0cc1b2 Mon Sep 17 00:00:00 2001 From: Ara Sadoyan Date: Wed, 20 May 2026 21:09:23 +0200 Subject: [PATCH] Changed sticky session from bool to Option --- README.md | 6 +----- src/utils/auth.rs | 1 - src/utils/parceyaml.rs | 1 + src/utils/structs.rs | 6 +++--- src/web/proxyhttp.rs | 19 +++++++++++-------- src/web/start.rs | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ab7c0f1..ffa66c2 100644 --- a/README.md +++ b/README.md @@ -110,11 +110,7 @@ For getting the best performance on newer hardware use `aralez-x86_64-*.gz`. **Via docker** ```shell -docker run -d \ - -v /local/path/to/config:/etc/aralez:rw \ - -p 80:80 \ - -p 443:443 \ - sadoyan/aralez +docker run -d -v /path/to/config:/etc/aralez:rw -p 80:80 -p 443:443 sadoyan/aralez ``` ## Running the Proxy diff --git a/src/utils/auth.rs b/src/utils/auth.rs index cb1ab7b..3d937c6 100644 --- a/src/utils/auth.rs +++ b/src/utils/auth.rs @@ -179,7 +179,6 @@ impl AuthValidator for ApiKeyAuth<'_> { impl AuthValidator for JwtAuth { async fn validate(&self, session: &mut Session) -> bool { if let Some(jwtsecret) = JWT_TOKEN.clone() { - // println!(" ===> {:?}", jwtsecret); if let Some(tok) = get_query_param(session, "araleztoken") { return check_jwt(tok.as_str(), jwtsecret.as_ref()); } diff --git a/src/utils/parceyaml.rs b/src/utils/parceyaml.rs index 824e561..35066d8 100644 --- a/src/utils/parceyaml.rs +++ b/src/utils/parceyaml.rs @@ -197,6 +197,7 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) { }; path_auth = Some(Arc::from(y)); } + let redirect_link = path_config.redirect_to.as_ref().map(|www| Arc::from(www.as_str())); if let Some((ip, port_str)) = server.split_once(':') { if let Ok(port) = port_str.parse::() { diff --git a/src/utils/structs.rs b/src/utils/structs.rs index ff2c506..dafc439 100644 --- a/src/utils/structs.rs +++ b/src/utils/structs.rs @@ -14,7 +14,7 @@ pub type Headers = DashMap, DashMap, Vec<(String, Arc)>>> #[derive(Clone, Debug, Default)] pub struct Extraparams { pub to_https: Option, - pub sticky_sessions: bool, + pub sticky_sessions: Option, pub authentication: Option>, pub rate_limit: Option, } @@ -25,7 +25,7 @@ pub struct GlobalServiceMapping { pub hostname: String, pub path: Option, pub to_https: Option, - pub sticky_sessions: Option, + pub sticky_sessions: Option, pub rate_limit: Option, pub client_headers: Option>, pub server_headers: Option>, @@ -48,7 +48,7 @@ pub struct Consul { pub struct Config { pub provider: String, pub to_https: Option, - pub sticky_sessions: bool, + pub sticky_sessions: Option, #[serde(default)] pub upstreams: Option>, #[serde(default)] diff --git a/src/web/proxyhttp.rs b/src/web/proxyhttp.rs index 535c14b..8704887 100644 --- a/src/web/proxyhttp.rs +++ b/src/web/proxyhttp.rs @@ -39,7 +39,7 @@ pub struct LB { pub struct Context { backend_id: Option, - sticky_sessions: bool, + sticky_sessions: Option, start_time: Instant, hostname: Option>, upstream_peer: Option>, @@ -53,7 +53,7 @@ impl ProxyHttp for LB { fn new_ctx(&self) -> Self::CTX { Context { backend_id: None, - sticky_sessions: false, + sticky_sessions: None, start_time: Instant::now(), hostname: None, upstream_peer: None, @@ -66,7 +66,7 @@ impl ProxyHttp for LB { let hostname = return_header_host_from_upstream(session, &self.ump_upst); _ctx.hostname = hostname; let mut backend_id = None; - if _ctx.extraparams.sticky_sessions { + if let Some(_) = _ctx.extraparams.sticky_sessions { if let Some(cookies) = session.req_header().headers.get("cookie") { if let Ok(cookie_str) = cookies.to_str() { if let Some(pos) = cookie_str.find("backend_id=") { @@ -91,7 +91,6 @@ impl ProxyHttp for LB { return Ok(true); } } - if let Some(rate) = innermap.rate_limit.or(_ctx.extraparams.rate_limit) { let rate_key = session.client_addr().and_then(|addr| addr.as_inet()).map(|inet| inet.ip()); let curr_window_requests = RATE_LIMITER.observe(&rate_key, 1); @@ -161,7 +160,7 @@ impl ProxyHttp for LB { peer.options.verify_cert = false; peer.options.verify_hostname = false; } - if ctx.extraparams.sticky_sessions { + if let Some(_) = ctx.extraparams.sticky_sessions { let mut s = String::with_capacity(64); write!( &mut s, @@ -177,7 +176,7 @@ impl ProxyHttp for LB { ) .unwrap_or(()); ctx.backend_id = Some(s); - ctx.sticky_sessions = true; + ctx.sticky_sessions = ctx.extraparams.sticky_sessions; } Ok(peer) } @@ -237,7 +236,7 @@ impl ProxyHttp for LB { Ok(()) } async fn response_filter(&self, _session: &mut Session, _upstream_response: &mut ResponseHeader, ctx: &mut Self::CTX) -> Result<()> { - if ctx.sticky_sessions { + if let Some(val) = ctx.sticky_sessions { if let Some(bid) = &ctx.backend_id { let tt = if let Some(existing) = REVERSE_STORE.get(bid) { existing.value().clone() @@ -255,7 +254,11 @@ impl ProxyHttp for LB { let mut buf = String::with_capacity(80); buf.push_str("backend_id="); buf.push_str(&tt); - buf.push_str("; Path=/; Max-Age=86400; HttpOnly; SameSite=Lax"); + buf.push_str("; Path=/; Max-Age="); + buf.push_str(&val.to_string()); + buf.push_str("; HttpOnly; SameSite=Lax"); + // buf.push_str("; Path=/; Max-Age=86400; HttpOnly; SameSite=Lax"); + // println!("{}", buf); let _ = _upstream_response.insert_header("set-cookie", buf.as_str()); } } diff --git a/src/web/start.rs b/src/web/start.rs index 0bde5bf..5c683bc 100644 --- a/src/web/start.rs +++ b/src/web/start.rs @@ -33,7 +33,7 @@ pub fn run() { let ec_config = Arc::new(ArcSwap::from_pointee(Extraparams { to_https: None, - sticky_sessions: false, + sticky_sessions: None, authentication: None, rate_limit: None, }));