mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 09:18:27 +00:00
Implementing streaming Responses
This enables a much easier handling of big queries after all.
This commit is contained in:
parent
ca343ae1d8
commit
dae4124039
2 changed files with 71 additions and 2 deletions
36
test/test.cc
36
test/test.cc
|
@ -282,6 +282,25 @@ protected:
|
|||
res.status = 404;
|
||||
}
|
||||
})
|
||||
.Get("/streamedchunked", [&](const Request& /*req*/, Response& res) {
|
||||
res.streamcb = [] (uint64_t offset) {
|
||||
if (offset < 3)
|
||||
return "a";
|
||||
if (offset < 6)
|
||||
return "b";
|
||||
return "";
|
||||
};
|
||||
})
|
||||
.Get("/streamed", [&](const Request& /*req*/, Response& res) {
|
||||
res.set_header("Content-Length", "6");
|
||||
res.streamcb = [] (uint64_t offset) {
|
||||
if (offset < 3)
|
||||
return "a";
|
||||
if (offset < 6)
|
||||
return "b";
|
||||
return "";
|
||||
};
|
||||
})
|
||||
.Post("/chunked", [&](const Request& req, Response& /*res*/) {
|
||||
EXPECT_EQ(req.body, "dechunked post body");
|
||||
})
|
||||
|
@ -712,6 +731,23 @@ TEST_F(ServerTest, CaseInsensitiveTransferEncoding)
|
|||
EXPECT_EQ(200, res->status);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, GetStreamed)
|
||||
{
|
||||
auto res = cli_.Get("/streamed");
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
EXPECT_EQ(200, res->status);
|
||||
EXPECT_EQ("6", res->get_header_value("Content-Length"));
|
||||
EXPECT_TRUE(res->body == "aaabbb");
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, GetStreamedChunked)
|
||||
{
|
||||
auto res = cli_.Get("/streamedchunked");
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
EXPECT_EQ(200, res->status);
|
||||
EXPECT_TRUE(res->body == "aaabbb");
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, LargeChunkedPost) {
|
||||
Request req;
|
||||
req.method = "POST";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue