@@ -511,6 +511,15 @@ TEST(GetHeaderValueTest, RegularValueInt) {
511511  EXPECT_EQ (100ull , val);
512512}
513513
514+ TEST (GetHeaderValueTest, RegularInvalidValueInt) {
515+   Headers headers = {{" Content-Length"  , " x"  }};
516+   auto  is_invalid_value = false ;
517+   auto  val = detail::get_header_value_u64 (headers, " Content-Length"  , 0 , 0 ,
518+                                           is_invalid_value);
519+   EXPECT_EQ (0ull , val);
520+   EXPECT_TRUE (is_invalid_value);
521+ }
522+ 
514523TEST (GetHeaderValueTest, Range) {
515524  {
516525    Headers headers = {make_range_header ({{1 , -1 }})};
@@ -7496,9 +7505,9 @@ TEST(MultipartFormDataTest, CloseDelimiterWithoutCRLF) {
74967505             " text2" 
74977506             " \r\n ------------"  ;
74987507
7499-   std::string resonse ;
7500-   ASSERT_TRUE (send_request (1 , req, &resonse ));
7501-   ASSERT_EQ (" 200"  , resonse .substr (9 , 3 ));
7508+   std::string response ;
7509+   ASSERT_TRUE (send_request (1 , req, &response ));
7510+   ASSERT_EQ (" 200"  , response .substr (9 , 3 ));
75027511}
75037512
75047513TEST (MultipartFormDataTest, ContentLength) {
@@ -7543,11 +7552,10 @@ TEST(MultipartFormDataTest, ContentLength) {
75437552             " text2" 
75447553             " \r\n ------------\r\n "  ;
75457554
7546-   std::string resonse ;
7547-   ASSERT_TRUE (send_request (1 , req, &resonse ));
7548-   ASSERT_EQ (" 200"  , resonse .substr (9 , 3 ));
7555+   std::string response ;
7556+   ASSERT_TRUE (send_request (1 , req, &response ));
7557+   ASSERT_EQ (" 200"  , response .substr (9 , 3 ));
75497558}
7550- 
75517559#endif 
75527560
75537561TEST (TaskQueueTest, IncreaseAtomicInteger) {
@@ -8007,6 +8015,32 @@ TEST(InvalidHeaderCharsTest, OnServer) {
80078015  }
80088016}
80098017
8018+ TEST (InvalidHeaderValueTest, InvalidContentLength) {
8019+   auto  handled = false ;
8020+ 
8021+   Server svr;
8022+   svr.Post (" /test"  , [&](const  Request &, Response &) { handled = true ; });
8023+ 
8024+   thread t = thread ([&] { svr.listen (HOST, PORT); });
8025+   auto  se = detail::scope_exit ([&] {
8026+     svr.stop ();
8027+     t.join ();
8028+     ASSERT_FALSE (svr.is_running ());
8029+     ASSERT_FALSE (handled);
8030+   });
8031+ 
8032+   svr.wait_until_ready ();
8033+ 
8034+   auto  req = " POST /test HTTP/1.1\r\n " 
8035+              " Content-Length: x\r\n " 
8036+              " \r\n "  ;
8037+ 
8038+   std::string response;
8039+   ASSERT_TRUE (send_request (1 , req, &response));
8040+   ASSERT_EQ (" HTTP/1.1 400 Bad Request"  ,
8041+             response.substr (0 , response.find (" \r\n "  )));
8042+ }
8043+ 
80108044#ifndef  _WIN32
80118045TEST (Expect100ContinueTest, ServerClosesConnection) {
80128046  static  constexpr  char  reject[] = " Unauthorized"  ;
0 commit comments