Skip to content

Commit b883ebb

Browse files
authored
controllers/krate/delete: Adjust HTTP status code (#10169)
`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
1 parent 9ed4853 commit b883ebb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/controllers/krate/delete.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ const AVAILABLE_AFTER: TimeDelta = TimeDelta::hours(24);
2424
/// crate has been published for less than 72 hours, or if the crate has a
2525
/// single owner, has been downloaded less than 100 times for each month it has
2626
/// been published, and is not depended upon by any other crate on crates.io.
27-
pub async fn delete(Path(name): Path<String>, parts: Parts, app: AppState) -> AppResult<()> {
27+
pub async fn delete(
28+
Path(name): Path<String>,
29+
parts: Parts,
30+
app: AppState,
31+
) -> AppResult<StatusCode> {
2832
let mut conn = app.db_write().await?;
2933

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

110-
Ok(())
114+
Ok(StatusCode::NO_CONTENT)
111115
}
112116

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

179183
let response = delete_crate(&user, "foo").await;
180-
assert_eq!(response.status(), StatusCode::OK);
184+
assert_eq!(response.status(), StatusCode::NO_CONTENT);
181185
assert!(response.body().is_empty());
182186

183187
// Assert that the crate no longer exists
@@ -212,7 +216,7 @@ mod tests {
212216
");
213217

214218
let response = delete_crate(&user, "foo").await;
215-
assert_eq!(response.status(), StatusCode::OK);
219+
assert_eq!(response.status(), StatusCode::NO_CONTENT);
216220
assert!(response.body().is_empty());
217221

218222
// Assert that the crate no longer exists
@@ -247,7 +251,7 @@ mod tests {
247251
");
248252

249253
let response = delete_crate(&user, "foo").await;
250-
assert_eq!(response.status(), StatusCode::OK);
254+
assert_eq!(response.status(), StatusCode::NO_CONTENT);
251255
assert!(response.body().is_empty());
252256

253257
// Assert that the crate no longer exists

0 commit comments

Comments
 (0)