Skip to content

Commit 8d9a477

Browse files
authored
No content check (#823)
* No content check * unit test for no content * fixing merge conflict break * oops during manual merge conflict
1 parent 85b4abb commit 8d9a477

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

httplib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5544,7 +5544,7 @@ inline bool ClientImpl::process_request(Stream &strm, const Request &req,
55445544
}
55455545

55465546
// Body
5547-
if (req.method != "HEAD" && req.method != "CONNECT") {
5547+
if ((res.status != 204) && req.method != "HEAD" && req.method != "CONNECT") {
55485548
auto out =
55495549
req.content_receiver_
55505550
? static_cast<ContentReceiverWithProgress>(

test/test.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,31 @@ TEST(ErrorHandlerTest, ContentLength) {
953953
ASSERT_FALSE(svr.is_running());
954954
}
955955

956+
TEST(NoContentTest, ContentLength) {
957+
Server svr;
958+
959+
svr.Get("/hi", [](const Request & /*req*/, Response &res) {
960+
res.status = 204;
961+
});
962+
auto thread = std::thread([&]() { svr.listen(HOST, PORT); });
963+
964+
// Give GET time to get a few messages.
965+
std::this_thread::sleep_for(std::chrono::seconds(1));
966+
967+
{
968+
Client cli(HOST, PORT);
969+
970+
auto res = cli.Get("/hi");
971+
ASSERT_TRUE(res);
972+
EXPECT_EQ(204, res->status);
973+
EXPECT_EQ("0", res->get_header_value("Content-Length"));
974+
}
975+
976+
svr.stop();
977+
thread.join();
978+
ASSERT_FALSE(svr.is_running());
979+
}
980+
956981
TEST(RoutingHandlerTest, PreRoutingHandler) {
957982
Server svr;
958983

0 commit comments

Comments
 (0)