Fix #889
This commit is contained in:
parent
6ff84d34d1
commit
9d3365df54
@ -5820,6 +5820,9 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
|
|||||||
req.content_receiver
|
req.content_receiver
|
||||||
? static_cast<ContentReceiverWithProgress>(
|
? static_cast<ContentReceiverWithProgress>(
|
||||||
[&](const char *buf, size_t n, uint64_t off, uint64_t len) {
|
[&](const char *buf, size_t n, uint64_t off, uint64_t len) {
|
||||||
|
if (300 < res.status && res.status < 400 && follow_location_) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
auto ret = req.content_receiver(buf, n, off, len);
|
auto ret = req.content_receiver(buf, n, off, len);
|
||||||
if (!ret) { error = Error::Canceled; }
|
if (!ret) { error = Error::Canceled; }
|
||||||
return ret;
|
return ret;
|
||||||
|
58
test/test.cc
58
test/test.cc
@ -889,6 +889,64 @@ TEST(UrlWithSpace, Redirect) {
|
|||||||
EXPECT_EQ(200, res->status);
|
EXPECT_EQ(200, res->status);
|
||||||
EXPECT_EQ(18527, res->get_header_value<uint64_t>("Content-Length"));
|
EXPECT_EQ(18527, res->get_header_value<uint64_t>("Content-Length"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(RedirectFromPageWithContent, Redirect) {
|
||||||
|
Server svr;
|
||||||
|
|
||||||
|
svr.Get("/1", [&](const Request & /*req*/, Response &res) {
|
||||||
|
res.set_content("___", "text/plain");
|
||||||
|
res.set_redirect("/2");
|
||||||
|
});
|
||||||
|
|
||||||
|
svr.Get("/2", [&](const Request & /*req*/, Response &res) {
|
||||||
|
res.set_content("Hello World!", "text/plain");
|
||||||
|
});
|
||||||
|
|
||||||
|
auto th = std::thread([&]() { svr.listen("localhost", PORT); });
|
||||||
|
|
||||||
|
while (!svr.is_running()) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Give GET time to get a few messages.
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
|
||||||
|
{
|
||||||
|
Client cli("localhost", PORT);
|
||||||
|
cli.set_follow_location(true);
|
||||||
|
|
||||||
|
std::string body;
|
||||||
|
auto res = cli.Get("/1",
|
||||||
|
[&](const char *data, size_t data_length) {
|
||||||
|
body.append(data, data_length);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_TRUE(res);
|
||||||
|
EXPECT_EQ(200, res->status);
|
||||||
|
EXPECT_EQ("Hello World!", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Client cli("localhost", PORT);
|
||||||
|
|
||||||
|
std::string body;
|
||||||
|
auto res = cli.Get("/1",
|
||||||
|
[&](const char *data, size_t data_length) {
|
||||||
|
body.append(data, data_length);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
ASSERT_TRUE(res);
|
||||||
|
EXPECT_EQ(302, res->status);
|
||||||
|
EXPECT_EQ("___", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
svr.stop();
|
||||||
|
th.join();
|
||||||
|
ASSERT_FALSE(svr.is_running());
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST(BindServerTest, BindDualStack) {
|
TEST(BindServerTest, BindDualStack) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user