Skip to content

Commit 3c0281c

Browse files
committed
redirect to crate-page trying to access rustdoc pages on failed releases
1 parent c0bf243 commit 3c0281c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/web/crate_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub struct CrateDetails {
3838
release_time: DateTime<Utc>,
3939
build_status: bool,
4040
last_successful_build: Option<String>,
41-
rustdoc_status: bool,
41+
pub rustdoc_status: bool,
4242
pub archive_storage: bool,
4343
repository_url: Option<String>,
4444
homepage_url: Option<String>,

src/web/rustdoc.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,15 @@ pub(crate) async fn rustdoc_html_server_handler(
473473
.await?
474474
.ok_or(AxumNope::ResourceNotFound)?;
475475

476+
if !krate.rustdoc_status {
477+
rendering_time.step("redirect to crate");
478+
return Ok(axum_cached_redirect(
479+
format!("/crate/{}/{}", params.name, version_or_latest),
480+
CachePolicy::ForeverInCdn,
481+
)?
482+
.into_response());
483+
}
484+
476485
// if visiting the full path to the default target, remove the target from the path
477486
// expects a req_path that looks like `[/:target]/.*`
478487
if req_path.first().copied() == Some(&krate.metadata.default_target) {
@@ -2589,4 +2598,28 @@ mod test {
25892598
Ok(())
25902599
})
25912600
}
2601+
2602+
#[test_case("/something/1.2.3/some_path/", "/crate/something/1.2.3")]
2603+
#[test_case("/something/latest/some_path/", "/crate/something/latest")]
2604+
fn rustdoc_page_from_failed_build_redirects_to_crate(path: &str, expected: &str) {
2605+
wrapper(|env| {
2606+
env.fake_release()
2607+
.name("something")
2608+
.version("1.2.3")
2609+
.archive_storage(true)
2610+
.build_result_failed()
2611+
.create()?;
2612+
let web = env.frontend();
2613+
2614+
assert_redirect_cached(
2615+
path,
2616+
expected,
2617+
CachePolicy::ForeverInCdn,
2618+
web,
2619+
&env.config(),
2620+
)?;
2621+
2622+
Ok(())
2623+
})
2624+
}
25922625
}

0 commit comments

Comments
 (0)