Skip to content

Commit

Permalink
controllers/krate/delete: Adjust HTTP status code (#10169)
Browse files Browse the repository at this point in the history
`DELETE` endpoints are supposed to return "204 No Content" upon successful deletion, unless the response contains an entity, which is not the case here.

see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE#successfully_deleting_a_resource
  • Loading branch information
Turbo87 authored Dec 10, 2024
1 parent 9ed4853 commit b883ebb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/controllers/krate/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const AVAILABLE_AFTER: TimeDelta = TimeDelta::hours(24);
/// crate has been published for less than 72 hours, or if the crate has a
/// single owner, has been downloaded less than 100 times for each month it has
/// been published, and is not depended upon by any other crate on crates.io.
pub async fn delete(Path(name): Path<String>, parts: Parts, app: AppState) -> AppResult<()> {
pub async fn delete(
Path(name): Path<String>,
parts: Parts,
app: AppState,
) -> AppResult<StatusCode> {
let mut conn = app.db_write().await?;

// Check that the user is authenticated
Expand Down Expand Up @@ -107,7 +111,7 @@ pub async fn delete(Path(name): Path<String>, parts: Parts, app: AppState) -> Ap
})
.await?;

Ok(())
Ok(StatusCode::NO_CONTENT)
}

async fn find_crate(conn: &mut AsyncPgConnection, name: &str) -> QueryResult<Option<Crate>> {
Expand Down Expand Up @@ -177,7 +181,7 @@ mod tests {
");

let response = delete_crate(&user, "foo").await;
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.status(), StatusCode::NO_CONTENT);
assert!(response.body().is_empty());

// Assert that the crate no longer exists
Expand Down Expand Up @@ -212,7 +216,7 @@ mod tests {
");

let response = delete_crate(&user, "foo").await;
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.status(), StatusCode::NO_CONTENT);
assert!(response.body().is_empty());

// Assert that the crate no longer exists
Expand Down Expand Up @@ -247,7 +251,7 @@ mod tests {
");

let response = delete_crate(&user, "foo").await;
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.status(), StatusCode::NO_CONTENT);
assert!(response.body().is_empty());

// Assert that the crate no longer exists
Expand Down

0 comments on commit b883ebb

Please sign in to comment.