Fix UB when HttpStatus code is not one in the enum.

PiperOrigin-RevId: 736244405
This commit is contained in:
Francis Tsui
2025-03-12 13:24:18 -07:00
committed by Copybara-Service
parent b62b56c75e
commit 5da86f5a72
2 changed files with 4 additions and 0 deletions
+2
View File
@@ -109,6 +109,8 @@ absl::string_view GetHttpReasonPhrase(HttpStatusCode code) {
return "Gateway Timeout";
case HttpStatusCode::kHttpVersionNotSupported:
return "HTTP Version Not Supported";
default:
return "Unknown HTTP status code";
}
}
@@ -100,6 +100,8 @@ TEST(HttpStatusCode, TestReturnCorrectReasonPhrase) {
"HTTP Version Not Supported");
EXPECT_EQ(GetHttpReasonPhrase(HttpStatusCode::kHttpRequestUriTooLong),
"Request-URI Too Long");
EXPECT_EQ(GetHttpReasonPhrase(static_cast<HttpStatusCode>(600)),
"Unknown HTTP status code");
}
} // namespace