@@ -35,7 +35,8 @@ pub async fn create_service(
35
35
domain_storage : Arc < DomainStorage > ,
36
36
is_https : bool ,
37
37
) -> Result < Response < Body > , Infallible > {
38
- let from_uri = req. uri ( ) . authority ( ) . cloned ( ) ;
38
+ let uri = req. uri ( ) ;
39
+ let from_uri = uri. authority ( ) . cloned ( ) ;
39
40
// trick, need more check
40
41
let authority_opt = from_uri. or_else ( || {
41
42
req. headers ( )
@@ -52,6 +53,7 @@ pub async fn create_service(
52
53
53
54
if let Some ( authority) = authority_opt {
54
55
let host = authority. host ( ) ;
56
+
55
57
let service_config = service_config. get_domain_service_config ( host) ;
56
58
// cors
57
59
let origin_opt = match resp_cors_request ( req. method ( ) , req. headers ( ) , service_config. cors ) {
@@ -67,15 +69,24 @@ pub async fn create_service(
67
69
} else {
68
70
format ! ( ":{}" , port)
69
71
} ;
70
- let redirect_path = format ! ( "https://{host}{port}{}" , req . uri( ) ) ;
72
+ let redirect_path = format ! ( "https://{host}{port}{}" , uri) ;
71
73
resp. headers_mut ( )
72
74
. insert ( LOCATION , redirect_path. parse ( ) . unwrap ( ) ) ;
73
75
* resp. status_mut ( ) = StatusCode :: MOVED_PERMANENTLY ;
74
76
return Ok ( resp) ;
75
77
}
76
78
}
79
+ // path: "" => "/"
80
+ let path = uri. path ( ) ;
81
+ if domain_storage. check_if_empty_index ( host, path) {
82
+ let mut resp = Response :: default ( ) ;
83
+ resp. headers_mut ( )
84
+ . insert ( LOCATION , format ! ( "{path}/" ) . parse ( ) . unwrap ( ) ) ;
85
+ * resp. status_mut ( ) = StatusCode :: MOVED_PERMANENTLY ;
86
+ return Ok ( resp) ;
87
+ }
77
88
// static file
78
- let mut resp = match get_cache_file ( req . uri ( ) . path ( ) , host, domain_storage) . await {
89
+ let mut resp = match get_cache_file ( path, host, domain_storage) . await {
79
90
Ok ( item) => {
80
91
let headers = req. headers ( ) ;
81
92
let conditionals = Conditionals {
0 commit comments