mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
keepalive: support multiple post using content provider (#461)
This commit is contained in:
parent
31bb13abd2
commit
d043b18097
2 changed files with 18 additions and 2 deletions
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);
|
||||
}
|
||||
|
||||
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
|
||||
class SSLServer : public Server {
|
||||
public:
|
||||
|
|
|
@ -2088,6 +2088,7 @@ TEST_F(ServerTest, KeepAlive) {
|
|||
Get(requests, "/hi");
|
||||
Get(requests, "/not-exist");
|
||||
Post(requests, "/empty", "", "text/plain");
|
||||
Post(requests, "/empty", 0, [&](size_t offset, size_t length, httplib::DataSink &sink){}, "text/plain");
|
||||
|
||||
std::vector<Response> responses;
|
||||
auto ret = cli_.send(requests, responses);
|
||||
|
@ -2107,8 +2108,8 @@ TEST_F(ServerTest, KeepAlive) {
|
|||
EXPECT_EQ(404, res.status);
|
||||
}
|
||||
|
||||
{
|
||||
auto &res = responses[4];
|
||||
for (size_t i = 4; i < 6; i++) {
|
||||
auto &res = responses[i];
|
||||
EXPECT_EQ(200, res.status);
|
||||
EXPECT_EQ("text/plain", res.get_header_value("Content-Type"));
|
||||
EXPECT_EQ("empty", res.body);
|
||||
|
|
Loading…
Reference in a new issue