mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-29 22:38:36 +08:00
Name and config changes
This commit is contained in:
@@ -124,7 +124,7 @@ A sample `upstreams.yaml` entry:
|
||||
```yaml
|
||||
provider: "file"
|
||||
sticky_sessions: false
|
||||
to_ssl: false
|
||||
to_https: false
|
||||
headers:
|
||||
- "Access-Control-Allow-Origin:*"
|
||||
- "Access-Control-Allow-Methods:POST, GET, OPTIONS"
|
||||
|
||||
@@ -14,7 +14,7 @@ pub fn load_configuration(d: &str, kind: &str) -> Option<Configuration> {
|
||||
typecfg: "".to_string(),
|
||||
extraparams: Extraparams {
|
||||
sticky_sessions: false,
|
||||
to_ssl: None,
|
||||
to_https: None,
|
||||
authentication: DashMap::new(),
|
||||
},
|
||||
};
|
||||
@@ -57,7 +57,7 @@ pub fn load_configuration(d: &str, kind: &str) -> Option<Configuration> {
|
||||
toreturn.headers.insert("GLOBAL_HEADERS".to_string(), global_headers);
|
||||
|
||||
toreturn.extraparams.sticky_sessions = parsed.sticky_sessions;
|
||||
toreturn.extraparams.to_ssl = parsed.to_ssl;
|
||||
toreturn.extraparams.to_https = parsed.to_https;
|
||||
}
|
||||
if let Some(auth) = &parsed.authorization {
|
||||
let name = auth.get("type").unwrap().to_string();
|
||||
|
||||
@@ -17,7 +17,7 @@ pub struct ServiceMapping {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Extraparams {
|
||||
pub sticky_sessions: bool,
|
||||
pub to_ssl: Option<bool>,
|
||||
pub to_https: Option<bool>,
|
||||
pub authentication: DashMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ pub struct Consul {
|
||||
pub struct Config {
|
||||
pub provider: String,
|
||||
pub sticky_sessions: bool,
|
||||
pub to_ssl: Option<bool>,
|
||||
pub to_https: Option<bool>,
|
||||
pub upstreams: Option<HashMap<String, HostConfig>>,
|
||||
pub globals: Option<HashMap<String, Vec<String>>>,
|
||||
pub headers: Option<Vec<String>>,
|
||||
|
||||
@@ -57,7 +57,7 @@ impl BackgroundService for LB {
|
||||
let current = self.extraparams.load_full();
|
||||
let mut new = (*current).clone();
|
||||
new.sticky_sessions = ss.extraparams.sticky_sessions;
|
||||
new.to_ssl = ss.extraparams.to_ssl;
|
||||
new.to_https = ss.extraparams.to_https;
|
||||
new.authentication = ss.extraparams.authentication.clone();
|
||||
self.extraparams.store(Arc::new(new));
|
||||
self.headers.clear();
|
||||
|
||||
@@ -86,7 +86,7 @@ impl ProxyHttp for LB {
|
||||
peer.options.verify_hostname = false;
|
||||
}
|
||||
// println!("{}, {}, alpn {}, h2 {:?}, to_https {}", hostname, address.as_str(), peer.options.alpn, is_h2, _to_https);
|
||||
if self.extraparams.load().to_ssl.unwrap_or(false) || to_https {
|
||||
if self.extraparams.load().to_https.unwrap_or(false) || to_https {
|
||||
if let Some(stream) = session.stream() {
|
||||
if stream.get_ssl().is_none() {
|
||||
if let Some(addr) = session.server_addr() {
|
||||
@@ -142,22 +142,15 @@ impl ProxyHttp for LB {
|
||||
if self.extraparams.load().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));
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.to_https {
|
||||
// println!("{} => {}", ctx.to_https, ctx.redirect_to);
|
||||
let mut redirect_response = ResponseHeader::build(StatusCode::MOVED_PERMANENTLY, None)?;
|
||||
redirect_response.insert_header("Location", ctx.redirect_to.clone())?;
|
||||
redirect_response.insert_header("Content-Length", "0")?;
|
||||
session.write_response_header(Box::new(redirect_response), false).await?;
|
||||
// return Ok(());
|
||||
// let response = session.write_response_header(Box::new(redirect_response), false).await?;
|
||||
// return Ok(response);
|
||||
}
|
||||
|
||||
match return_header_host(&session) {
|
||||
Some(host) => {
|
||||
let path = session.req_header().uri.path();
|
||||
|
||||
@@ -24,7 +24,7 @@ pub fn run() {
|
||||
let hh_config = Arc::new(DashMap::new());
|
||||
let ec_config = Arc::new(ArcSwap::from_pointee(Extraparams {
|
||||
sticky_sessions: false,
|
||||
to_ssl: None,
|
||||
to_https: None,
|
||||
authentication: DashMap::new(),
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user