Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
- set default frontend rule position to TREE for config
- remove debug warnings
- apply clippy suggestions

Signed-off-by: Eloi DEMOLIS <[email protected]>
  • Loading branch information
Wonshtrum committed Feb 10, 2025
1 parent 4eb3555 commit 8eee269
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 33 deletions.
16 changes: 3 additions & 13 deletions bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ impl CommandManager {

pub fn reload_configuration(&mut self, path: Option<String>) -> Result<(), CtlError> {
debug!("Reloading configuration…");
let path = match path {
Some(p) => p,
None => String::new(),
};
self.send_request(RequestType::ReloadConfiguration(path).into())
self.send_request(RequestType::ReloadConfiguration(path.unwrap_or_default()).into())
}

pub fn list_frontends(
Expand Down Expand Up @@ -246,10 +242,7 @@ impl CommandManager {
path: PathRule::from_cli_options(path_prefix, path_regex, path_equals),
method: method.map(String::from),
position: RulePosition::Tree.into(),
tags: match tags {
Some(tags) => tags,
None => BTreeMap::new(),
},
tags: tags.unwrap_or_default(),
required_auth: todo!(),
redirect: todo!(),

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 247 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unreachable expression
redirect_scheme: todo!(),
Expand Down Expand Up @@ -302,10 +295,7 @@ impl CommandManager {
path: PathRule::from_cli_options(path_prefix, path_regex, path_equals),
method: method.map(String::from),
position: RulePosition::Tree.into(),
tags: match tags {
Some(tags) => tags,
None => BTreeMap::new(),
},
tags: tags.unwrap_or_default(),
required_auth: todo!(),
redirect: todo!(),

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unreachable expression

Check warning on line 300 in bin/src/ctl/request_builder.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unreachable expression
redirect_scheme: todo!(),
Expand Down
12 changes: 8 additions & 4 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ pub struct FileClusterFrontendConfig {
pub certificate_chain: Option<String>,
#[serde(default)]
pub tls_versions: Vec<TlsVersion>,
#[serde(default)]
#[serde(default = "default_rule_position")]
pub position: RulePosition,
pub tags: Option<BTreeMap<String, String>>,
pub required_auth: Option<bool>,
Expand Down Expand Up @@ -727,7 +727,7 @@ impl FileClusterFrontendConfig {
redirect_template: self.redirect_template.clone(),
rewrite_host: self.rewrite_host.clone(),
rewrite_path: self.rewrite_path.clone(),
rewrite_port: self.rewrite_port.clone(),
rewrite_port: self.rewrite_port,
headers: self.headers.clone(),
})
}
Expand Down Expand Up @@ -848,7 +848,7 @@ impl FileClusterConfig {
self.authorized_hashes
.iter()
.map(|hash| {
hex::decode(&hash)
hex::decode(hash)
.map_err(|_| ConfigError::InvalidHash(hash.clone()))
.and_then(|v| {
v.try_into()
Expand Down Expand Up @@ -887,7 +887,7 @@ pub struct HttpFrontendConfig {
pub certificate_chain: Option<Vec<String>>,
#[serde(default)]
pub tls_versions: Vec<TlsVersion>,
#[serde(default)]
#[serde(default = "default_rule_position")]
pub position: RulePosition,
pub tags: Option<BTreeMap<String, String>>,
pub required_auth: bool,
Expand All @@ -900,6 +900,10 @@ pub struct HttpFrontendConfig {
pub headers: Vec<Header>,
}

fn default_rule_position() -> RulePosition {
RulePosition::Tree
}

impl HttpFrontendConfig {
pub fn generate_requests(&self, cluster_id: &str) -> Vec<Request> {
let mut v = Vec::new();
Expand Down
4 changes: 1 addition & 3 deletions lib/src/protocol/kawa_h1/answers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,9 +1007,7 @@ impl HttpAnswers {
name.into(),
];
variables_once = vec![location.into()];
// custom_name_owner = name;
// &custom_name_owner
unsafe { &from_utf8_unchecked(variables[3].as_bytes()) }
unsafe { from_utf8_unchecked(variables[3].as_bytes()) }
}
};
// kawa::debug_kawa(&template.kawa);
Expand Down
3 changes: 0 additions & 3 deletions lib/src/protocol/kawa_h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,9 +1394,6 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
self.set_answer(DefaultAnswer::Answer301 { location });
return Err(RetrieveClusterError::Redirected);
}
warn!("{:?}", body);
warn!("{:?}", headers_request);
warn!("{:?}", headers_response);
apply_header_edits(&mut self.request_stream, headers_request);
self.request_stream.blocks.extend(body);
self.context.headers_response = headers_response;
Expand Down
20 changes: 10 additions & 10 deletions lib/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl Router {
}
}

pub fn lookup<'a, 'b>(
&'a self,
hostname: &'b str,
path: &'b str,
method: &'b Method,
pub fn lookup<'a>(
&self,
hostname: &'a str,
path: &'a str,
method: &'a Method,
) -> Result<RouteResult, RouterError> {
let hostname_b = hostname.as_bytes();
let path_b = path.as_bytes();
Expand Down Expand Up @@ -529,7 +529,7 @@ pub enum PathRule {
Equals(String),
}

#[derive(PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PathRuleResult {
Regex,
Prefix(usize),
Expand Down Expand Up @@ -697,7 +697,7 @@ impl RewriteParts {
}
Some(Self(result))
}
pub fn run(&self, host_captures: &Vec<&str>, path_captures: &Vec<&str>) -> String {
pub fn run(&self, host_captures: &[&str], path_captures: &[&str]) -> String {
let mut cap = 0;
for part in &self.0 {
cap += match part {
Expand Down Expand Up @@ -977,7 +977,7 @@ impl RouteResult {
}
PathRule::Regex(regex) => captures_path.extend(
regex
.captures(&path)
.captures(path)
.unwrap()
.iter()
.map(|c| unsafe { from_utf8_unchecked(c.unwrap().as_bytes()) }),
Expand Down Expand Up @@ -1028,7 +1028,7 @@ impl RouteResult {
.push(unsafe { from_utf8_unchecked(&domain[..domain.len() - suffix.len()]) }),
DomainRule::Regex(regex) => captures_host.extend(
regex
.captures(&domain)
.captures(domain)
.unwrap()
.iter()
.skip(1)
Expand Down Expand Up @@ -1065,7 +1065,7 @@ impl RouteResult {
}
TrieSubMatch::Regexp(part, regex) => captures_host.extend(
regex
.captures(&part)
.captures(part)
.unwrap()
.iter()
.skip(1)
Expand Down

0 comments on commit 8eee269

Please sign in to comment.