Skip to content

rustdoc json: check target existance before redirecting to S3 #2837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ pub(crate) async fn json_download_handler(
Path(params): Path<JsonDownloadParams>,
mut conn: DbConnection,
Extension(config): Extension<Arc<Config>>,
Extension(storage): Extension<Arc<AsyncStorage>>,
) -> AxumResult<impl IntoResponse> {
let matched_release = match_version(&mut conn, &params.name, &params.version)
.await?
Expand Down Expand Up @@ -875,6 +876,10 @@ pub(crate) async fn json_download_handler(
format_version,
);

if !storage.exists(&storage_path).await? {
return Err(AxumNope::ResourceNotFound);
}

// since we didn't build rustdoc json for all releases yet,
// this redirect might redirect to a location that doesn't exist.
Ok(super::axum_cached_redirect(
Expand Down Expand Up @@ -3166,6 +3171,7 @@ mod test {

#[test_case("0.1.0/json"; "rustdoc status false")]
#[test_case("0.2.0/unknown-target/json"; "unknown target")]
#[test_case("0.2.0/json/99"; "target file doesnt exist")]
#[test_case("0.42.0/json"; "unknown version")]
fn json_download_not_found(request_path_suffix: &str) {
async_wrapper(|env| async move {
Expand Down
Loading