mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
fix #110
This commit is contained in:
parent
5ad4311fb0
commit
86b3dfc480
@ -2068,13 +2068,8 @@ inline void Client::write_request(Stream& strm, Request& req)
|
|||||||
|
|
||||||
// Body
|
// Body
|
||||||
if (!req.body.empty()) {
|
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
|
// Flush buffer
|
||||||
auto& data = bstrm.get_buffer();
|
auto& data = bstrm.get_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_VALUE = string(25000, '@');
|
||||||
const string LONG_QUERY_URL = "/long-query-value?key=" + LONG_QUERY_VALUE;
|
const string LONG_QUERY_URL = "/long-query-value?key=" + LONG_QUERY_VALUE;
|
||||||
|
|
||||||
|
const std::string JSON_DATA = "{\"hello\":\"world\"}";
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
TEST(StartupTest, WSAStartup)
|
TEST(StartupTest, WSAStartup)
|
||||||
{
|
{
|
||||||
@ -345,6 +347,12 @@ protected:
|
|||||||
res.status = 404;
|
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) {
|
.Get("/streamedchunked", [&](const Request& /*req*/, Response& res) {
|
||||||
res.streamcb = [] (uint64_t offset) {
|
res.streamcb = [] (uint64_t offset) {
|
||||||
if (offset < 3)
|
if (offset < 3)
|
||||||
@ -572,6 +580,18 @@ TEST_F(ServerTest, PostMethod2)
|
|||||||
ASSERT_EQ("coder", res->body);
|
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)
|
TEST_F(ServerTest, PostEmptyContent)
|
||||||
{
|
{
|
||||||
auto res = cli_.Post("/empty", "", "text/plain");
|
auto res = cli_.Post("/empty", "", "text/plain");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user