Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ferron/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,13 @@ async fn server_event_loop(
if let Some(host) = host_yaml.as_hash() {
if let Some(domain_yaml) = host.get(&Yaml::from_str("domain")) {
if let Some(domain) = domain_yaml.as_str() {
if !domain.contains("*") {
// check if we even want auto-TLS for this domain
let want_auto_tls = host
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Code - Priority: High
The logic for handling enableAutomaticTLS is duplicated between ferron/src/server.rs and ferron/src/util/validate_config.rs. Consider extracting this logic into a shared utility function.

.get(&Yaml::from_str("enableAutomaticTLS"))
.and_then(|enable| enable.as_bool())
.unwrap_or(true);

if want_auto_tls && !domain.contains("*") {
acme_domains.push(domain);
}
}
Expand Down
17 changes: 6 additions & 11 deletions ferron/src/util/validate_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,17 +727,12 @@ pub fn validate_config(
Err(anyhow::anyhow!("Invalid directory listing enabling option"))?
}

if used_properties.contains("enableAutomaticTLS") {
if !is_global {
Err(anyhow::anyhow!(
"Automatic TLS enabling configuration is not allowed in host configuration"
))?
}
if config["enableAutomaticTLS"].as_bool().is_none() {
Err(anyhow::anyhow!(
"Invalid automatic TLS enabling option value"
))?
}
if used_properties.contains("enableAutomaticTLS")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical Code - Priority: Medium
The condition checking for enableAutomaticTLS is identical in functionality between ferron/src/server.rs and ferron/src/util/validate_config.rs. This could be refactored to avoid redundancy.

&& config["enableAutomaticTLS"].as_bool().is_none()
{
Err(anyhow::anyhow!(
"Invalid automatic TLS enabling option value"
))?
}

if used_properties.contains("useAutomaticTLSHTTPChallenge") {
Expand Down