@@ -72,6 +72,11 @@ fn serve(req: Request) -> Result<Response> {
7272 . map ( |h| h. to_str ( ) )
7373 . unwrap_or ( Ok ( "" ) ) ?;
7474
75+ let path = match path {
76+ "/" => "index.html" ,
77+ _ => path,
78+ } ;
79+
7580 let body = match FileServer :: read ( path, & enc) {
7681 Ok ( b) => Some ( b) ,
7782 Err ( e) => {
@@ -200,10 +205,7 @@ mod tests {
200205 let req = spin_http:: Request {
201206 method : spin_http:: Method :: Get ,
202207 uri : "http://thisistest.com" . to_string ( ) ,
203- headers : vec ! [ (
204- PATH_INFO_HEADER . to_string( ) ,
205- "./content/hello-test.txt" . to_string( ) ,
206- ) ] ,
208+ headers : vec ! [ ( PATH_INFO_HEADER . to_string( ) , "./hello-test.txt" . to_string( ) ) ] ,
207209 params : vec ! [ ] ,
208210 body : None ,
209211 } ;
@@ -217,10 +219,7 @@ mod tests {
217219 method : spin_http:: Method :: Get ,
218220 uri : "http://thisistest.com" . to_string ( ) ,
219221 headers : vec ! [
220- (
221- PATH_INFO_HEADER . to_string( ) ,
222- "./content/hello-test.txt" . to_string( ) ,
223- ) ,
222+ ( PATH_INFO_HEADER . to_string( ) , "./hello-test.txt" . to_string( ) ) ,
224223 (
225224 IF_NONE_MATCH . to_string( ) ,
226225 "13946318585003701156" . to_string( ) ,
@@ -239,10 +238,7 @@ mod tests {
239238 method : spin_http:: Method :: Get ,
240239 uri : "http://thisistest.com" . to_string ( ) ,
241240 headers : vec ! [
242- (
243- PATH_INFO_HEADER . to_string( ) ,
244- "./content/hello-test.txt" . to_string( ) ,
245- ) ,
241+ ( PATH_INFO_HEADER . to_string( ) , "./hello-test.txt" . to_string( ) ) ,
246242 ( IF_NONE_MATCH . to_string( ) , "" . to_string( ) ) ,
247243 ] ,
248244 params : vec ! [ ] ,
@@ -267,4 +263,17 @@ mod tests {
267263 let rsp = <super :: SpinHttp as spin_http:: SpinHttp >:: handle_http_request ( req) ;
268264 assert_eq ! ( rsp. status, 404 ) ;
269265 }
266+
267+ #[ test]
268+ fn test_serve_index ( ) {
269+ let req = spin_http:: Request {
270+ method : spin_http:: Method :: Get ,
271+ uri : "http://thisistest.com" . to_string ( ) ,
272+ headers : vec ! [ ( PATH_INFO_HEADER . to_string( ) , "/" . to_string( ) ) ] ,
273+ params : vec ! [ ] ,
274+ body : None ,
275+ } ;
276+ let rsp = <super :: SpinHttp as spin_http:: SpinHttp >:: handle_http_request ( req) ;
277+ assert_eq ! ( rsp. status, 200 ) ;
278+ }
270279}
0 commit comments