mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-12 14:11:39 +00:00
No content check (#823)
* No content check * unit test for no content * fixing merge conflict break * oops during manual merge conflict
This commit is contained in:
parent
85b4abbf16
commit
8d9a477edb
@ -5544,7 +5544,7 @@ inline bool ClientImpl::process_request(Stream &strm, const Request &req,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Body
|
// Body
|
||||||
if (req.method != "HEAD" && req.method != "CONNECT") {
|
if ((res.status != 204) && req.method != "HEAD" && req.method != "CONNECT") {
|
||||||
auto out =
|
auto out =
|
||||||
req.content_receiver_
|
req.content_receiver_
|
||||||
? static_cast<ContentReceiverWithProgress>(
|
? static_cast<ContentReceiverWithProgress>(
|
||||||
|
25
test/test.cc
25
test/test.cc
@ -953,6 +953,31 @@ TEST(ErrorHandlerTest, ContentLength) {
|
|||||||
ASSERT_FALSE(svr.is_running());
|
ASSERT_FALSE(svr.is_running());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(NoContentTest, ContentLength) {
|
||||||
|
Server svr;
|
||||||
|
|
||||||
|
svr.Get("/hi", [](const Request & /*req*/, Response &res) {
|
||||||
|
res.status = 204;
|
||||||
|
});
|
||||||
|
auto thread = std::thread([&]() { svr.listen(HOST, PORT); });
|
||||||
|
|
||||||
|
// Give GET time to get a few messages.
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
|
||||||
|
{
|
||||||
|
Client cli(HOST, PORT);
|
||||||
|
|
||||||
|
auto res = cli.Get("/hi");
|
||||||
|
ASSERT_TRUE(res);
|
||||||
|
EXPECT_EQ(204, res->status);
|
||||||
|
EXPECT_EQ("0", res->get_header_value("Content-Length"));
|
||||||
|
}
|
||||||
|
|
||||||
|
svr.stop();
|
||||||
|
thread.join();
|
||||||
|
ASSERT_FALSE(svr.is_running());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(RoutingHandlerTest, PreRoutingHandler) {
|
TEST(RoutingHandlerTest, PreRoutingHandler) {
|
||||||
Server svr;
|
Server svr;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user