mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 23:08:40 +08:00
COnfig parameters update
This commit is contained in:
@@ -54,6 +54,14 @@ impl BackgroundService for LB {
|
||||
clone_dashmap_into(&ss.upstreams, &self.ump_full);
|
||||
clone_dashmap_into(&ss.upstreams, &self.ump_upst);
|
||||
self.proxyconf.clear();
|
||||
|
||||
// println!(" ====> {:?}", self.extraparams);
|
||||
{
|
||||
let mut write_guard = self.extraparams.write().await;
|
||||
write_guard.stickysessions = ss.extraparams.stickysessions;
|
||||
}
|
||||
// println!(" ====> {:?}", self.extraparams);
|
||||
|
||||
match ss.globals {
|
||||
Some(globals) => {
|
||||
for (k,v) in globals {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::utils::auth::authenticate;
|
||||
use crate::utils::parceyaml::AppConfig;
|
||||
use crate::utils::parceyaml::{AppConfig, Extraparams};
|
||||
use crate::utils::tools::*;
|
||||
use crate::web::gethosts::GetHost;
|
||||
use async_trait::async_trait;
|
||||
@@ -13,6 +13,7 @@ use pingora_http::ResponseHeader;
|
||||
use pingora_proxy::{ProxyHttp, Session};
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub struct LB {
|
||||
pub ump_upst: Arc<UpstreamsDashMap>,
|
||||
@@ -23,6 +24,8 @@ pub struct LB {
|
||||
pub config: Arc<AppConfig>,
|
||||
pub local: Arc<(String, u16)>,
|
||||
pub proxyconf: Arc<DashMap<String, Vec<String>>>,
|
||||
// pub extraparams: Arc<Mutex<Extraparams>>,
|
||||
pub extraparams: Arc<RwLock<Extraparams>>,
|
||||
}
|
||||
|
||||
pub struct MyCtx {
|
||||
@@ -53,15 +56,17 @@ impl ProxyHttp for LB {
|
||||
// }
|
||||
|
||||
let mut backend_id = None;
|
||||
|
||||
if self.config.sticky_sessions {
|
||||
if let Some(cookies) = session.req_header().headers.get("cookie") {
|
||||
if let Ok(cookie_str) = cookies.to_str() {
|
||||
for cookie in cookie_str.split(';') {
|
||||
let trimmed = cookie.trim();
|
||||
if let Some(value) = trimmed.strip_prefix("backend_id=") {
|
||||
backend_id = Some(value);
|
||||
break;
|
||||
{
|
||||
let read_guard = self.extraparams.read().await;
|
||||
if read_guard.stickysessions {
|
||||
if let Some(cookies) = session.req_header().headers.get("cookie") {
|
||||
if let Ok(cookie_str) = cookies.to_str() {
|
||||
for cookie in cookie_str.split(';') {
|
||||
let trimmed = cookie.trim();
|
||||
if let Some(value) = trimmed.strip_prefix("backend_id=") {
|
||||
backend_id = Some(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,11 +139,14 @@ impl ProxyHttp for LB {
|
||||
async fn response_filter(&self, _session: &mut Session, _upstream_response: &mut ResponseHeader, _ctx: &mut Self::CTX) -> Result<()> {
|
||||
// _upstream_response.insert_header("X-Proxied-From", "Fooooooooooooooo").unwrap();
|
||||
|
||||
if self.config.sticky_sessions {
|
||||
let backend_id = _ctx.backend_id.clone();
|
||||
if let Some(bid) = self.ump_byid.get(&backend_id) {
|
||||
// let _ = _upstream_response.insert_header("set-cookie", format!("backend {}", bid.0));
|
||||
let _ = _upstream_response.insert_header("set-cookie", format!("backend_id={}; Path=/; Max-Age=600; HttpOnly; SameSite=Lax", bid.0));
|
||||
{
|
||||
let read_guard = self.extraparams.read().await;
|
||||
if read_guard.stickysessions {
|
||||
let backend_id = _ctx.backend_id.clone();
|
||||
if let Some(bid) = self.ump_byid.get(&backend_id) {
|
||||
// let _ = _upstream_response.insert_header("set-cookie", format!("backend {}", bid.0));
|
||||
let _ = _upstream_response.insert_header("set-cookie", format!("backend_id={}; Path=/; Max-Age=600; HttpOnly; SameSite=Lax", bid.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::utils::parceyaml::Extraparams;
|
||||
use crate::utils::tools::*;
|
||||
use crate::web::proxyhttp::LB;
|
||||
use dashmap::DashMap;
|
||||
@@ -6,6 +7,7 @@ use pingora_core::prelude::{background_service, Opt};
|
||||
use pingora_core::server::Server;
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub fn run() {
|
||||
let parameters = Some(Opt::parse_args()).unwrap();
|
||||
@@ -28,11 +30,13 @@ pub fn run() {
|
||||
let ff: UpstreamsDashMap = DashMap::new();
|
||||
let im: UpstreamsIdMap = DashMap::new();
|
||||
let hh: Headers = DashMap::new();
|
||||
let ec: Extraparams = Extraparams { stickysessions: false };
|
||||
|
||||
let uf_config = Arc::new(uf);
|
||||
let ff_config = Arc::new(ff);
|
||||
let im_config = Arc::new(im);
|
||||
let hh_config = Arc::new(hh);
|
||||
let ec_config = Arc::new(RwLock::new(ec));
|
||||
|
||||
let cfg = Arc::new(maincfg);
|
||||
let local = Arc::new(local_conf);
|
||||
@@ -48,6 +52,7 @@ pub fn run() {
|
||||
local: local.clone(),
|
||||
headers: hh_config.clone(),
|
||||
proxyconf: pconf.clone(),
|
||||
extraparams: ec_config.clone(),
|
||||
};
|
||||
let bg = LB {
|
||||
ump_upst: uf_config.clone(),
|
||||
@@ -57,6 +62,7 @@ pub fn run() {
|
||||
local: local.clone(),
|
||||
headers: hh_config.clone(),
|
||||
proxyconf: pconf.clone(),
|
||||
extraparams: ec_config.clone(),
|
||||
};
|
||||
|
||||
// env_logger::Env::new();
|
||||
|
||||
Reference in New Issue
Block a user