Skip to content

Commit b845425

Browse files
committed
Fix #878
1 parent 89519c8 commit b845425

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

httplib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5933,7 +5933,7 @@ inline Result ClientImpl::Get(const char *path, const Params &params,
59335933
}
59345934

59355935
std::string path_with_query = detail::append_query_params(path, params);
5936-
return Get(path_with_query.c_str(), params, headers, response_handler,
5936+
return Get(path_with_query.c_str(), headers, response_handler,
59375937
content_receiver, progress);
59385938
}
59395939

test/test.cc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,6 +3495,69 @@ TEST(ErrorHandlerWithContentProviderTest, ErrorHandler) {
34953495
ASSERT_FALSE(svr.is_running());
34963496
}
34973497

3498+
TEST(GetWithParametersTest, GetWithParameters) {
3499+
Server svr;
3500+
3501+
svr.Get("/", [&](const Request & req, Response &res) {
3502+
auto text = req.get_param_value("hello");
3503+
res.set_content(text, "text/plain");
3504+
});
3505+
3506+
auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
3507+
while (!svr.is_running()) {
3508+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
3509+
}
3510+
std::this_thread::sleep_for(std::chrono::seconds(1));
3511+
3512+
Client cli("localhost", PORT);
3513+
3514+
Params params;
3515+
params.emplace("hello", "world");
3516+
auto res = cli.Get("/", params, Headers{});
3517+
3518+
ASSERT_TRUE(res);
3519+
EXPECT_EQ(200, res->status);
3520+
EXPECT_EQ("world", res->body);
3521+
3522+
svr.stop();
3523+
listen_thread.join();
3524+
ASSERT_FALSE(svr.is_running());
3525+
}
3526+
3527+
TEST(GetWithParametersTest, GetWithParameters2) {
3528+
Server svr;
3529+
3530+
svr.Get("/", [&](const Request & req, Response &res) {
3531+
auto text = req.get_param_value("hello");
3532+
res.set_content(text, "text/plain");
3533+
});
3534+
3535+
auto listen_thread = std::thread([&svr]() { svr.listen("localhost", PORT); });
3536+
while (!svr.is_running()) {
3537+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
3538+
}
3539+
std::this_thread::sleep_for(std::chrono::seconds(1));
3540+
3541+
Client cli("localhost", PORT);
3542+
3543+
Params params;
3544+
params.emplace("hello", "world");
3545+
3546+
std::string body;
3547+
auto res = cli.Get("/", params, Headers{}, [&](const char *data, size_t data_length) {
3548+
body.append(data, data_length);
3549+
return true;
3550+
});
3551+
3552+
ASSERT_TRUE(res);
3553+
EXPECT_EQ(200, res->status);
3554+
EXPECT_EQ("world", body);
3555+
3556+
svr.stop();
3557+
listen_thread.join();
3558+
ASSERT_FALSE(svr.is_running());
3559+
}
3560+
34983561
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
34993562
TEST(KeepAliveTest, ReadTimeoutSSL) {
35003563
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);

0 commit comments

Comments
 (0)