Added a unit test for REMOTE_ADDR
This commit is contained in:
parent
9d2fe9e6c8
commit
4e391fdae6
13
test/test.cc
13
test/test.cc
@ -201,6 +201,10 @@ protected:
|
|||||||
svr_.get("/hi", [&](const Request& /*req*/, Response& res) {
|
svr_.get("/hi", [&](const Request& /*req*/, Response& res) {
|
||||||
res.set_content("Hello World!", "text/plain");
|
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) {
|
.get("/endwith%", [&](const Request& /*req*/, Response& res) {
|
||||||
res.set_content("Hello World!", "text/plain");
|
res.set_content("Hello World!", "text/plain");
|
||||||
})
|
})
|
||||||
@ -574,6 +578,15 @@ TEST_F(ServerTest, CaseInsensitiveHeaderName)
|
|||||||
EXPECT_EQ("Hello World!", res->body);
|
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
|
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
|
||||||
TEST_F(ServerTest, Gzip)
|
TEST_F(ServerTest, Gzip)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user