@@ -472,30 +472,38 @@ pub(crate) async fn rustdoc_html_server_handler(
472
472
{
473
473
debug ! ( "got error serving {}: {}" , storage_path, err) ;
474
474
}
475
- // If it fails, we try again with /index.html at the end
476
- storage_path. push_str ( "/index.html" ) ;
477
- req_path. push ( "index.html" ) ;
478
475
479
- return if storage
480
- . rustdoc_file_exists (
481
- & params. name ,
482
- & krate. version . to_string ( ) ,
483
- krate. latest_build_id ,
484
- & storage_path,
485
- krate. archive_storage ,
486
- )
487
- . await ?
488
476
{
489
- redirect (
490
- & params. name ,
491
- & krate. version ,
492
- & req_path,
493
- CachePolicy :: ForeverInCdn ,
494
- )
495
- } else if req_path. first ( ) . map_or ( false , |p| p. contains ( '-' ) ) {
477
+ // If it fails, we try again with /index.html at the end
478
+ let mut storage_path = storage_path. clone ( ) ;
479
+ storage_path. push_str ( "/index.html" ) ;
480
+
481
+ let mut req_path = req_path. clone ( ) ;
482
+ req_path. push ( "index.html" ) ;
483
+
484
+ if storage
485
+ . rustdoc_file_exists (
486
+ & params. name ,
487
+ & krate. version . to_string ( ) ,
488
+ krate. latest_build_id ,
489
+ & storage_path,
490
+ krate. archive_storage ,
491
+ )
492
+ . await ?
493
+ {
494
+ return redirect (
495
+ & params. name ,
496
+ & krate. version ,
497
+ & req_path,
498
+ CachePolicy :: ForeverInCdn ,
499
+ ) ;
500
+ }
501
+ }
502
+
503
+ if req_path. first ( ) . map_or ( false , |p| p. contains ( '-' ) ) {
496
504
// This is a target, not a module; it may not have been built.
497
505
// Redirect to the default target and show a search page instead of a hard 404.
498
- Ok ( axum_cached_redirect (
506
+ return Ok ( axum_cached_redirect (
499
507
encode_url_path ( & format ! (
500
508
"/crate/{}/{}/target-redirect/{}" ,
501
509
params. name,
@@ -504,21 +512,28 @@ pub(crate) async fn rustdoc_html_server_handler(
504
512
) ) ,
505
513
CachePolicy :: ForeverInCdn ,
506
514
) ?
507
- . into_response ( ) )
508
- } else {
509
- if storage_path == format ! ( "{}/index.html" , krate. target_name. expect( "we check rustdoc_status = true above, and with docs we have target_name" ) ) {
510
- error ! (
511
- krate = params. name,
512
- version = krate. version. to_string( ) ,
513
- original_path = original_path. as_ref( ) ,
514
- storage_path,
515
- "Couldn't find crate documentation root on storage.
516
- Something is wrong with the build."
515
+ . into_response ( ) ) ;
516
+ }
517
+
518
+ if storage_path
519
+ == format ! (
520
+ "{}/index.html" ,
521
+ krate. target_name. expect(
522
+ "we check rustdoc_status = true above, and with docs we have target_name"
517
523
)
518
- }
524
+ )
525
+ {
526
+ error ! (
527
+ krate = params. name,
528
+ version = krate. version. to_string( ) ,
529
+ original_path = original_path. as_ref( ) ,
530
+ storage_path,
531
+ "Couldn't find crate documentation root on storage.
532
+ Something is wrong with the build."
533
+ )
534
+ }
519
535
520
- Err ( AxumNope :: ResourceNotFound )
521
- } ;
536
+ return Err ( AxumNope :: ResourceNotFound ) ;
522
537
}
523
538
} ;
524
539
@@ -2899,7 +2914,7 @@ mod test {
2899
2914
2900
2915
web. assert_redirect_cached_unchecked (
2901
2916
"/clap/2.24.0/i686-pc-windows-gnu/clap/which%20is%20a%20part%20of%20%5B%60Display%60%5D" ,
2902
- "/crate/clap/2.24.0/target-redirect/i686-pc-windows-gnu/clap/which%20is%20a%20part%20of%20[%60Display%60]/index.html " ,
2917
+ "/crate/clap/2.24.0/target-redirect/i686-pc-windows-gnu/clap/which%20is%20a%20part%20of%20[%60Display%60]" ,
2903
2918
CachePolicy :: ForeverInCdn ,
2904
2919
& env. config ( ) ,
2905
2920
) . await ?;
0 commit comments