From 59ab64440a95f7b16253fef67b5201c2ec4adaf7 Mon Sep 17 00:00:00 2001 From: Changwei Ge Date: Wed, 28 Oct 2020 16:05:28 +0800 Subject: [PATCH] Add http status code 503 When we are not capable to provide a certain kind of service, but should be after some delay. Http server is better to reply status code 503. It is more suggestive per as to http spec. ``` The server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay. ``` Signed-off-by: Changwei Ge --- coverage_config.json | 2 +- src/response.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/coverage_config.json b/coverage_config.json index ecf738b..750586a 100644 --- a/coverage_config.json +++ b/coverage_config.json @@ -1 +1 @@ -{"coverage_score": 92.4, "exclude_path": "", "crate_features": ""} +{"coverage_score": 92.5, "exclude_path": "", "crate_features": ""} diff --git a/src/response.rs b/src/response.rs index 216a43c..5e0cb79 100644 --- a/src/response.rs +++ b/src/response.rs @@ -27,6 +27,8 @@ pub enum StatusCode { InternalServerError, /// 501, Not Implemented NotImplemented, + /// 503, Service Unavailable + ServiceUnavailable, } impl StatusCode { @@ -40,6 +42,7 @@ impl StatusCode { StatusCode::NotFound => b"404", StatusCode::InternalServerError => b"500", StatusCode::NotImplemented => b"501", + StatusCode::ServiceUnavailable => b"503", } } } @@ -285,5 +288,6 @@ mod tests { assert_eq!(StatusCode::NotFound.raw(), b"404"); assert_eq!(StatusCode::InternalServerError.raw(), b"500"); assert_eq!(StatusCode::NotImplemented.raw(), b"501"); + assert_eq!(StatusCode::ServiceUnavailable.raw(), b"503"); } }