Fix check for URI length to prevent incorrect HTTP 414 errors (#2046)

This commit is contained in:
Brett Profitt 2025-02-10 21:46:38 -05:00 committed by GitHub
parent b397c768e4
commit a268d65c4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 9 deletions

View file

@ -3541,7 +3541,7 @@ TEST_F(ServerTest, LongRequest) {
TEST_F(ServerTest, TooLongRequest) {
std::string request;
for (size_t i = 0; i < 545; i++) {
for (size_t i = 0; i < 546; i++) {
request += "/TooLongRequest";
}
request += "_NG";
@ -3552,6 +3552,17 @@ TEST_F(ServerTest, TooLongRequest) {
EXPECT_EQ(StatusCode::UriTooLong_414, res->status);
}
TEST_F(ServerTest, AlmostTooLongRequest) {
// test for #2046 - URI length check shouldn't include other content on req line
// URI is max URI length, minus 14 other chars in req line (GET, space, leading /, space, HTTP/1.1)
std::string request = "/" + string(CPPHTTPLIB_REQUEST_URI_MAX_LENGTH - 14, 'A');
auto res = cli_.Get(request.c_str());
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::NotFound_404, res->status);
}
TEST_F(ServerTest, LongHeader) {
Request req;
req.method = "GET";