Skip to content

Commit

Permalink
Fix regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamwil committed Feb 11, 2024
1 parent 84d9098 commit 338e396
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async fn handle_request(
return Ok(not_found());
}

let trimmed_path = &path_str[base_path.len()..];
let trimmed_path = &path_str[base_path.len() - 1..];

let original_root = root.clone();
let mut path = RelativePathBuf::new();
Expand Down Expand Up @@ -284,7 +284,11 @@ fn construct_url(base_url: &str, no_port_append: bool, interface_port: u16) -> S
format!("{}{}:{}{}", protocol, domain, interface_port, path)
};

full_address
if full_address.ends_with('/') {
full_address
} else {
format!("{}/", full_address)
}
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -857,25 +861,25 @@ mod tests {
#[test]
fn test_construct_url_http_protocol() {
let result = construct_url("http://example.com", false, 8080);
assert_eq!(result, "http://example.com:8080");
assert_eq!(result, "http://example.com:8080/");
}

#[test]
fn test_construct_url_https_protocol() {
let result = construct_url("https://example.com", false, 8080);
assert_eq!(result, "https://example.com:8080");
assert_eq!(result, "https://example.com:8080/");
}

#[test]
fn test_construct_url_no_protocol() {
let result = construct_url("example.com", false, 8080);
assert_eq!(result, "http://example.com:8080");
assert_eq!(result, "http://example.com:8080/");
}

#[test]
fn test_construct_url_no_port_append() {
let result = construct_url("https://example.com", true, 8080);
assert_eq!(result, "https://example.com");
assert_eq!(result, "https://example.com/");
}

#[test]
Expand Down

0 comments on commit 338e396

Please sign in to comment.