Skip to content

Commit fc25dbe

Browse files
committed
fix http redirect
1 parent 6584558 commit fc25dbe

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

server/src/service.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ pub async fn create_service(
6464
if !is_https {
6565
if let Some(port) = service_config.http_redirect_to_https {
6666
let mut resp = Response::default();
67-
6867
let redirect_path = if port != 443 {
69-
format!("https://{host}{port}{uri}")
68+
format!("https://{host}:{port}{uri}")
7069
} else {
7170
format!("https://{host}{uri}")
7271
};
@@ -81,13 +80,12 @@ pub async fn create_service(
8180
if domain_storage.check_if_empty_index(host, path) {
8281
let mut resp = Response::default();
8382
let mut path = format!("{path}/");
84-
if let Some(query) = uri.query() {
83+
if let Some(query) = uri.query() {
8584
path.push('?');
8685
path.push_str(query);
8786
}
8887
let path = path.parse().unwrap();
89-
resp.headers_mut()
90-
.insert(LOCATION, path);
88+
resp.headers_mut().insert(LOCATION, path);
9189
*resp.status_mut() = StatusCode::MOVED_PERMANENTLY;
9290
return Ok(resp);
9391
}

tests/tests/starter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ async fn self_signed_cert_https() {
185185

186186
run_server_with_config("server_config_https.conf");
187187
tokio::time::sleep(Duration::from_secs(2)).await;
188-
upload_file_and_check(domain, request_prefix, 1, vec!["index.html", "1.html"]).await;
189-
// TODO: only support 443 port now.
188+
upload_file_and_check(domain, request_prefix, 1, vec!["", "index.html", "1.html"]).await;
189+
assert_index_redirect_correct(request_prefix).await;
190190
assert_files(
191191
domain,
192192
&format!("http://{LOCAL_HOST}:8080/27"),

0 commit comments

Comments
 (0)