Skip to content

Commit 35168ac

Browse files
Fix for clippy errors
Clippy returned errors for routing, and also an unrelated block of code with a redundant else block.
1 parent cb9aacc commit 35168ac

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

src/webserver/http.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -533,24 +533,25 @@ pub async fn run_server(config: &AppConfig, state: AppState) -> anyhow::Result<(
533533
}
534534
#[cfg(not(target_family = "unix"))]
535535
anyhow::bail!("Unix sockets are not supported on your operating system. Use listen_on instead of unix_socket.");
536-
} else {
537-
if let Some(domain) = &config.https_domain {
538-
let mut listen_on_https = listen_on;
539-
listen_on_https.set_port(443);
540-
log::debug!("Will start HTTPS server on {listen_on_https}");
541-
let config = make_auto_rustls_config(domain, config);
542-
server = server
543-
.bind_rustls_0_23(listen_on_https, config)
544-
.map_err(|e| bind_error(e, listen_on_https))?;
545-
} else if listen_on.port() == 443 {
546-
bail!("Please specify a value for https_domain in the configuration file. This is required when using HTTPS (port 443)");
547-
}
548-
if listen_on.port() != 443 {
549-
log::debug!("Will start HTTP server on {listen_on}");
550-
server = server
551-
.bind(listen_on)
552-
.map_err(|e| bind_error(e, listen_on))?;
553-
}
536+
}
537+
538+
if let Some(domain) = &config.https_domain {
539+
let mut listen_on_https = listen_on;
540+
listen_on_https.set_port(443);
541+
log::debug!("Will start HTTPS server on {listen_on_https}");
542+
let config = make_auto_rustls_config(domain, config);
543+
server = server
544+
.bind_rustls_0_23(listen_on_https, config)
545+
.map_err(|e| bind_error(e, listen_on_https))?;
546+
} else if listen_on.port() == 443 {
547+
bail!("Please specify a value for https_domain in the configuration file. This is required when using HTTPS (port 443)");
548+
}
549+
550+
if listen_on.port() != 443 {
551+
log::debug!("Will start HTTP server on {listen_on}");
552+
server = server
553+
.bind(listen_on)
554+
.map_err(|e| bind_error(e, listen_on))?;
554555
}
555556

556557
log_welcome_message(config);

src/webserver/routing.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,35 +117,30 @@ where
117117
{
118118
if path_and_query.path().ends_with(FORWARD_SLASH) {
119119
path.push(INDEX);
120-
match find_file_or_not_found(&path, SQL_EXTENSION, store).await {
121-
Ok(NotFound) => {
122-
let target_sql = path
123-
.parent()
124-
.unwrap_or_else(|| Path::new("/"))
125-
.join("_.sql");
126-
if store.contains(&target_sql).await? {
127-
Ok(Execute(target_sql))
128-
} else {
129-
Ok(NotFound)
130-
}
120+
if let Ok(NotFound) = find_file_or_not_found(&path, SQL_EXTENSION, store).await {
121+
let target_sql = path.parent().unwrap_or_else(|| Path::new("/")).join("_.sql");
122+
if store.contains(&target_sql).await? {
123+
Ok(Execute(target_sql))
124+
} else {
125+
Ok(NotFound)
131126
}
132-
result => result,
127+
} else {
128+
find_file_or_not_found(&path, SQL_EXTENSION, store).await
133129
}
134130
} else {
135131
let path_with_ext = path.with_extension(SQL_EXTENSION);
136-
match find_file(&path_with_ext, SQL_EXTENSION, store).await? {
137-
Some(action) => Ok(action),
138-
None => {
139-
let mut parent = path.parent();
140-
while let Some(p) = parent {
141-
let target_sql = p.join("_.sql");
142-
if store.contains(&target_sql).await? {
143-
return find_file_or_not_found(&path, SQL_EXTENSION, store).await;
144-
}
145-
parent = p.parent();
132+
if let Some(action) = find_file(&path_with_ext, SQL_EXTENSION, store).await? {
133+
Ok(action)
134+
} else {
135+
let mut parent = path.parent();
136+
while let Some(p) = parent {
137+
let target_sql = p.join("_.sql");
138+
if store.contains(&target_sql).await? {
139+
return find_file_or_not_found(&path, SQL_EXTENSION, store).await;
146140
}
147-
Ok(Redirect(append_to_path(path_and_query, FORWARD_SLASH)))
141+
parent = p.parent();
148142
}
143+
Ok(Redirect(append_to_path(path_and_query, FORWARD_SLASH)))
149144
}
150145
}
151146
}

test/models/_.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
select sqlpage.path();
2+
select sqlpage.variables();

0 commit comments

Comments
 (0)