1
0
mirror of synced 2025-04-21 22:25:55 +03:00

Added a unit test for REMOTE_ADDR

This commit is contained in:
yhirose 2018-03-13 23:03:54 -04:00
parent 9d2fe9e6c8
commit 4e391fdae6

View File

@ -201,6 +201,10 @@ protected:
svr_.get("/hi", [&](const Request& /*req*/, Response& res) {
res.set_content("Hello World!", "text/plain");
})
.get("/remote_addr", [&](const Request& req, Response& res) {
auto remote_addr = req.headers.find("REMOTE_ADDR")->second;
res.set_content(remote_addr.c_str(), "text/plain");
})
.get("/endwith%", [&](const Request& /*req*/, Response& res) {
res.set_content("Hello World!", "text/plain");
})
@ -574,6 +578,15 @@ TEST_F(ServerTest, CaseInsensitiveHeaderName)
EXPECT_EQ("Hello World!", res->body);
}
TEST_F(ServerTest, GetMethodRemoteAddr)
{
auto res = cli_.get("/remote_addr");
ASSERT_TRUE(res != nullptr);
EXPECT_EQ(200, res->status);
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
EXPECT_EQ("::1", res->body); // NOTE: depends on user's environment...
}
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
TEST_F(ServerTest, Gzip)
{