Skip to content

Commit f9b42ee

Browse files
author
Wor Ker
committed
Fix HTTP 414 errors hanging until timeout
1 parent 551f96d commit f9b42ee

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

httplib.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8403,8 +8403,6 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
84038403

84048404
// Check if the request URI doesn't exceed the limit
84058405
if (req.target.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) {
8406-
Headers dummy;
8407-
detail::read_headers(strm, dummy);
84088406
res.status = StatusCode::UriTooLong_414;
84098407
output_error_log(Error::ExceedUriMaxLength, &req);
84108408
return write_response(strm, close_connection, req, res);

test/test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4289,10 +4289,16 @@ TEST_F(ServerTest, TooLongRequest) {
42894289
}
42904290
request += "_NG";
42914291

4292+
auto start = std::chrono::high_resolution_clock::now();
42924293
auto res = cli_.Get(request.c_str());
4294+
auto end = std::chrono::high_resolution_clock::now();
4295+
auto elapsed =
4296+
std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
4297+
.count();
42934298

42944299
ASSERT_TRUE(res);
42954300
EXPECT_EQ(StatusCode::UriTooLong_414, res->status);
4301+
EXPECT_LE(elapsed, 100);
42964302
}
42974303

42984304
TEST_F(ServerTest, AlmostTooLongRequest) {
@@ -4363,10 +4369,16 @@ TEST_F(ServerTest, LongHeader) {
43634369
}
43644370

43654371
TEST_F(ServerTest, LongQueryValue) {
4372+
auto start = std::chrono::high_resolution_clock::now();
43664373
auto res = cli_.Get(LONG_QUERY_URL.c_str());
4374+
auto end = std::chrono::high_resolution_clock::now();
4375+
auto elapsed =
4376+
std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
4377+
.count();
43674378

43684379
ASSERT_TRUE(res);
43694380
EXPECT_EQ(StatusCode::UriTooLong_414, res->status);
4381+
EXPECT_LE(elapsed, 100);
43704382
}
43714383

43724384
TEST_F(ServerTest, TooLongQueryValue) {

0 commit comments

Comments
 (0)