From 4f621532e81ee2ad096a9c9592fdacc40d19de48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Fri, 25 Apr 2025 12:31:21 +0200 Subject: [PATCH] response: Add "TooManyRequests" status code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The addition of the "TooManyRequests" status code is in order to notify users when an operation is still pending, and this seems to be the best fit we can have for now. On the Cloud Hypervisor side we'll use it, for instance, for the case when a caller tries to offline a vCPU but the previous offline operation is still pending, leaving at least a chance for the caller to analyse the error and decide whether they want to retry the operation or not. TooManyRequests: https://datatracker.ietf.org/doc/html/rfc6585#section-4 Signed-off-by: Fabiano FidĂȘncio --- src/response.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/response.rs b/src/response.rs index bf0881f..d60a0e5 100644 --- a/src/response.rs +++ b/src/response.rs @@ -30,6 +30,8 @@ pub enum StatusCode { MethodNotAllowed, /// 413, Payload Too Large PayloadTooLarge, + /// 429, Too Many Requests + TooManyRequests, /// 500, Internal Server Error InternalServerError, /// 501, Not Implemented @@ -50,6 +52,7 @@ impl StatusCode { Self::NotFound => b"404", Self::MethodNotAllowed => b"405", Self::PayloadTooLarge => b"413", + Self::TooManyRequests => b"429", Self::InternalServerError => b"500", Self::NotImplemented => b"501", Self::ServiceUnavailable => b"503", @@ -448,6 +451,7 @@ mod tests { assert_eq!(StatusCode::NotFound.raw(), b"404"); assert_eq!(StatusCode::MethodNotAllowed.raw(), b"405"); assert_eq!(StatusCode::PayloadTooLarge.raw(), b"413"); + assert_eq!(StatusCode::TooManyRequests.raw(), b"429"); assert_eq!(StatusCode::InternalServerError.raw(), b"500"); assert_eq!(StatusCode::NotImplemented.raw(), b"501"); assert_eq!(StatusCode::ServiceUnavailable.raw(), b"503");