mirror of
https://github.com/sadoyan/aralez.git
synced 2026-05-30 03:44:06 +08:00
Changed sticky session from bool to Option<u64>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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::<u16>() {
|
||||
|
||||
@@ -14,7 +14,7 @@ pub type Headers = DashMap<Arc<str>, DashMap<Arc<str>, Vec<(String, Arc<str>)>>>
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Extraparams {
|
||||
pub to_https: Option<bool>,
|
||||
pub sticky_sessions: bool,
|
||||
pub sticky_sessions: Option<u64>,
|
||||
pub authentication: Option<Arc<InnerAuth>>,
|
||||
pub rate_limit: Option<isize>,
|
||||
}
|
||||
@@ -25,7 +25,7 @@ pub struct GlobalServiceMapping {
|
||||
pub hostname: String,
|
||||
pub path: Option<String>,
|
||||
pub to_https: Option<bool>,
|
||||
pub sticky_sessions: Option<bool>,
|
||||
pub sticky_sessions: Option<u64>,
|
||||
pub rate_limit: Option<isize>,
|
||||
pub client_headers: Option<Vec<String>>,
|
||||
pub server_headers: Option<Vec<String>>,
|
||||
@@ -48,7 +48,7 @@ pub struct Consul {
|
||||
pub struct Config {
|
||||
pub provider: String,
|
||||
pub to_https: Option<bool>,
|
||||
pub sticky_sessions: bool,
|
||||
pub sticky_sessions: Option<u64>,
|
||||
#[serde(default)]
|
||||
pub upstreams: Option<HashMap<String, HostConfig>>,
|
||||
#[serde(default)]
|
||||
|
||||
@@ -39,7 +39,7 @@ pub struct LB {
|
||||
|
||||
pub struct Context {
|
||||
backend_id: Option<String>,
|
||||
sticky_sessions: bool,
|
||||
sticky_sessions: Option<u64>,
|
||||
start_time: Instant,
|
||||
hostname: Option<Arc<str>>,
|
||||
upstream_peer: Option<Arc<InnerMap>>,
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user