This is an automated email from the ASF dual-hosted git repository. mgreber pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push: new eb5a54dca [webserver] avoid memory alloc©ing for HTTP status eb5a54dca is described below commit eb5a54dcac6d93b328fdf5850075fc6988722f78 Author: Alexey Serbin <ale...@apache.org> AuthorDate: Thu Jul 10 11:12:12 2025 -0700 [webserver] avoid memory alloc©ing for HTTP status There is no need to create an instance of std::string out of a static string literal just to generate formatted HTTP status line: passing 'const char*' to strings::Substitute() is enough. Also, don't crash on unexpected HTTP status codes in RELEASE builds, but log an error and return '500 Internal Server Error' instead, reserving SIGABRT only for DEBUG builds. This changelist doesn't contains any functional modifications. Change-Id: I58d40bc8bf41791e53b5033ee95e981c6957faa1 Reviewed-on: http://gerrit.cloudera.org:8080/23157 Reviewed-by: Marton Greber <greber...@gmail.com> Tested-by: Marton Greber <greber...@gmail.com> Reviewed-by: Gabriella Lotz <lotzgabrie...@gmail.com> --- src/kudu/server/webserver.cc | 49 +++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/kudu/server/webserver.cc b/src/kudu/server/webserver.cc index f247f1439..453fefb7d 100644 --- a/src/kudu/server/webserver.cc +++ b/src/kudu/server/webserver.cc @@ -149,38 +149,55 @@ namespace { // about this. Clean this up. string kWebserverLastErrMsg; // NOLINT(runtime/string) -string HttpStatusCodeToString(kudu::HttpStatusCode code) { +const char* HttpStatusCodeToString(kudu::HttpStatusCode code) { + static constexpr const char* const k200 = "200 OK"; + static constexpr const char* const k201 = "201 Created"; + static constexpr const char* const k204 = "204 No Content"; + static constexpr const char* const k307 = "307 Temporary Redirect"; + static constexpr const char* const k400 = "400 Bad Request"; + static constexpr const char* const k401 = "401 Authentication Required"; + static constexpr const char* const k403 = "403 Forbidden"; + static constexpr const char* const k404 = "404 Not Found"; + static constexpr const char* const k405 = "405 Method Not Allowed"; + static constexpr const char* const k411 = "411 Length Required"; + static constexpr const char* const k413 = "413 Request Entity Too Large"; + static constexpr const char* const k500 = "500 Internal Server Error"; + static constexpr const char* const k503 = "503 Service Unavailable"; + static constexpr const char* const k504 = "504 Gateway Timeout"; + switch (code) { case kudu::HttpStatusCode::Ok: - return "200 OK"; + return k200; case kudu::HttpStatusCode::Created: - return "201 Created"; + return k201; case kudu::HttpStatusCode::NoContent: - return "204 No Content"; + return k204; case kudu::HttpStatusCode::TemporaryRedirect: - return "307 Temporary Redirect"; + return k307; case kudu::HttpStatusCode::BadRequest: - return "400 Bad Request"; + return k400; case kudu::HttpStatusCode::AuthenticationRequired: - return "401 Authentication Required"; + return k401; case kudu::HttpStatusCode::Forbidden: - return "403 Forbidden"; + return k403; case kudu::HttpStatusCode::NotFound: - return "404 Not Found"; + return k404; case kudu::HttpStatusCode::MethodNotAllowed: - return "405 Method Not Allowed"; + return k405; case kudu::HttpStatusCode::LengthRequired: - return "411 Length Required"; + return k411; case kudu::HttpStatusCode::RequestEntityTooLarge: - return "413 Request Entity Too Large"; + return k413; case kudu::HttpStatusCode::InternalServerError: - return "500 Internal Server Error"; + return k500; case kudu::HttpStatusCode::ServiceUnavailable: - return "503 Service Unavailable"; + return k503; case kudu::HttpStatusCode::GatewayTimeout: - return "504 Gateway Timeout"; + return k504; } - LOG(FATAL) << "Unexpected HTTP response code"; + + LOG(DFATAL) << "unexpected HTTP response code: " << static_cast<uint16_t>(code); + return k500; } // Return the address of the remote user from the squeasel request info.