mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Fix #136
This commit is contained in:
parent
acc5e5a450
commit
8483e5931f
2 changed files with 17 additions and 2 deletions
|
@ -2119,8 +2119,10 @@ inline void Client::write_request(Stream& strm, Request& req)
|
|||
req.set_header("Content-Type", "text/plain");
|
||||
}
|
||||
|
||||
auto length = std::to_string(req.body.size());
|
||||
req.set_header("Content-Length", length.c_str());
|
||||
if (!req.has_header("Content-Length")) {
|
||||
auto length = std::to_string(req.body.size());
|
||||
req.set_header("Content-Length", length.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
detail::write_headers(bstrm, req);
|
||||
|
|
13
test/test.cc
13
test/test.cc
|
@ -470,6 +470,10 @@ protected:
|
|||
EXPECT_EQ("value2", req.get_param_value("array", 1));
|
||||
EXPECT_EQ("value3", req.get_param_value("array", 2));
|
||||
})
|
||||
.Post("/validate-no-multiple-headers", [&](const Request& req, Response& res) {
|
||||
EXPECT_EQ(1u, req.get_header_value_count("Content-Length"));
|
||||
EXPECT_EQ("5", req.get_header_value("Content-Length"));
|
||||
})
|
||||
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
|
||||
.Get("/gzip", [&](const Request& /*req*/, Response& res) {
|
||||
res.set_content("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "text/plain");
|
||||
|
@ -989,6 +993,15 @@ TEST_F(ServerTest, ArrayParam)
|
|||
EXPECT_EQ(200, res->status);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, NoMultipleHeaders)
|
||||
{
|
||||
Headers headers;
|
||||
headers.emplace("Content-Length", "5");
|
||||
auto res = cli_.Post("/validate-no-multiple-headers", headers, "hello", "text/plain");
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
EXPECT_EQ(200, res->status);
|
||||
}
|
||||
|
||||
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
|
||||
TEST_F(ServerTest, Gzip)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue