mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
keepalive: support multiple post using content provider (#461)
This commit is contained in:
parent
31bb13abd2
commit
d043b18097
15
httplib.h
15
httplib.h
@ -855,6 +855,21 @@ inline void Post(std::vector<Request> &requests, const char *path,
|
|||||||
Post(requests, path, Headers(), body, content_type);
|
Post(requests, path, Headers(), body, content_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Post(std::vector<Request> &requests,
|
||||||
|
const char *path, size_t content_length,
|
||||||
|
ContentProvider content_provider, const char *content_type) {
|
||||||
|
Request req;
|
||||||
|
req.method = "POST";
|
||||||
|
req.headers = Headers();
|
||||||
|
req.path = path;
|
||||||
|
req.content_length = content_length;
|
||||||
|
req.content_provider = content_provider;
|
||||||
|
|
||||||
|
if (content_type) { req.headers.emplace("Content-Type", content_type); }
|
||||||
|
|
||||||
|
requests.emplace_back(std::move(req));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
class SSLServer : public Server {
|
class SSLServer : public Server {
|
||||||
public:
|
public:
|
||||||
|
@ -2088,6 +2088,7 @@ TEST_F(ServerTest, KeepAlive) {
|
|||||||
Get(requests, "/hi");
|
Get(requests, "/hi");
|
||||||
Get(requests, "/not-exist");
|
Get(requests, "/not-exist");
|
||||||
Post(requests, "/empty", "", "text/plain");
|
Post(requests, "/empty", "", "text/plain");
|
||||||
|
Post(requests, "/empty", 0, [&](size_t offset, size_t length, httplib::DataSink &sink){}, "text/plain");
|
||||||
|
|
||||||
std::vector<Response> responses;
|
std::vector<Response> responses;
|
||||||
auto ret = cli_.send(requests, responses);
|
auto ret = cli_.send(requests, responses);
|
||||||
@ -2107,8 +2108,8 @@ TEST_F(ServerTest, KeepAlive) {
|
|||||||
EXPECT_EQ(404, res.status);
|
EXPECT_EQ(404, res.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
for (size_t i = 4; i < 6; i++) {
|
||||||
auto &res = responses[4];
|
auto &res = responses[i];
|
||||||
EXPECT_EQ(200, res.status);
|
EXPECT_EQ(200, res.status);
|
||||||
EXPECT_EQ("text/plain", res.get_header_value("Content-Type"));
|
EXPECT_EQ("text/plain", res.get_header_value("Content-Type"));
|
||||||
EXPECT_EQ("empty", res.body);
|
EXPECT_EQ("empty", res.body);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user