mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
fix #110
This commit is contained in:
parent
5ad4311fb0
commit
86b3dfc480
2 changed files with 21 additions and 6 deletions
|
@ -2068,12 +2068,7 @@ inline void Client::write_request(Stream& strm, Request& req)
|
|||
|
||||
// Body
|
||||
if (!req.body.empty()) {
|
||||
if (req.get_header_value("Content-Type") == "application/x-www-form-urlencoded") {
|
||||
auto str = detail::encode_url(req.body);
|
||||
bstrm.write(str.c_str(), str.size());
|
||||
} else {
|
||||
bstrm.write(req.body.c_str(), req.body.size());
|
||||
}
|
||||
bstrm.write(req.body.c_str(), req.body.size());
|
||||
}
|
||||
|
||||
// Flush buffer
|
||||
|
|
20
test/test.cc
20
test/test.cc
|
@ -23,6 +23,8 @@ const int PORT = 1234;
|
|||
const string LONG_QUERY_VALUE = string(25000, '@');
|
||||
const string LONG_QUERY_URL = "/long-query-value?key=" + LONG_QUERY_VALUE;
|
||||
|
||||
const std::string JSON_DATA = "{\"hello\":\"world\"}";
|
||||
|
||||
#ifdef _WIN32
|
||||
TEST(StartupTest, WSAStartup)
|
||||
{
|
||||
|
@ -345,6 +347,12 @@ protected:
|
|||
res.status = 404;
|
||||
}
|
||||
})
|
||||
.Post("/x-www-form-urlencoded-json", [&](const Request& req, Response& res) {
|
||||
auto json = req.get_param_value("json");
|
||||
ASSERT_EQ(JSON_DATA, json);
|
||||
res.set_content(json, "appliation/json");
|
||||
res.status = 200;
|
||||
})
|
||||
.Get("/streamedchunked", [&](const Request& /*req*/, Response& res) {
|
||||
res.streamcb = [] (uint64_t offset) {
|
||||
if (offset < 3)
|
||||
|
@ -572,6 +580,18 @@ TEST_F(ServerTest, PostMethod2)
|
|||
ASSERT_EQ("coder", res->body);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, PostWwwFormUrlEncodedJson)
|
||||
{
|
||||
Params params;
|
||||
params.emplace("json", JSON_DATA);
|
||||
|
||||
auto res = cli_.Post("/x-www-form-urlencoded-json", params);
|
||||
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
ASSERT_EQ(200, res->status);
|
||||
ASSERT_EQ(JSON_DATA, res->body);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, PostEmptyContent)
|
||||
{
|
||||
auto res = cli_.Post("/empty", "", "text/plain");
|
||||
|
|
Loading…
Reference in a new issue