From b2e329e6b29d8fc67d8e0b8a4c205cba9fd0bbed Mon Sep 17 00:00:00 2001 From: Jiwoo Park Date: Fri, 18 Oct 2024 20:08:20 +0900 Subject: [PATCH] Allow empty header values --- httplib.h | 2 +- test/test.cc | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/httplib.h b/httplib.h index 72bd2b6307..56af8f673c 100644 --- a/httplib.h +++ b/httplib.h @@ -4115,7 +4115,7 @@ inline bool parse_header(const char *beg, const char *end, T fn) { p++; } - if (p < end) { + if (p <= end) { auto key_len = key_end - beg; if (!key_len) { return false; } diff --git a/test/test.cc b/test/test.cc index 0cd450e763..612304b371 100644 --- a/test/test.cc +++ b/test/test.cc @@ -4922,6 +4922,15 @@ TEST(ServerRequestParsingTest, InvalidFieldValueContains_CR_LF_NUL) { EXPECT_EQ("HTTP/1.1 400 Bad Request", out.substr(0, 24)); } +TEST(ServerRequestParsingTest, EmptyFieldValue) { + std::string out; + + test_raw_request("GET /header_field_value_check HTTP/1.1\r\n" + "Test: \r\n\r\n", + &out); + EXPECT_EQ("HTTP/1.1 200 OK", out.substr(0, 15)); +} + TEST(ServerStopTest, StopServerWithChunkedTransmission) { Server svr;