Skip to content

response: Add "TooManyRequests" status code #59

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
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
response: Add "TooManyRequests" status code
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 <[email protected]>
  • Loading branch information
fidencio committed Apr 25, 2025
commit 0f545a4528106a2fd2aaa75887d6fe19cc6d9629
4 changes: 4 additions & 0 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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");
Expand Down