mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 09:18:27 +00:00
Fix #44
This commit is contained in:
parent
a0f50911e1
commit
5536d4c1ff
2 changed files with 79 additions and 15 deletions
58
test/test.cc
58
test/test.cc
|
@ -121,7 +121,7 @@ TEST(GetHeaderValueTest, Range)
|
|||
void testChunkedEncoding(httplib::HttpVersion ver)
|
||||
{
|
||||
auto host = "www.httpwatch.com";
|
||||
auto sec = 5;
|
||||
auto sec = 2;
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
auto port = 443;
|
||||
|
@ -186,6 +186,60 @@ TEST(RangeTest, FromHTTPBin)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(ConnectionErrorTest, InvalidHost)
|
||||
{
|
||||
auto host = "abcde.com";
|
||||
auto sec = 2;
|
||||
auto ver = httplib::HttpVersion::v1_1;
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
auto port = 443;
|
||||
httplib::SSLClient cli(host, port, sec, ver);
|
||||
#else
|
||||
auto port = 80;
|
||||
httplib::Client cli(host, port, sec, ver);
|
||||
#endif
|
||||
|
||||
auto res = cli.get("/");
|
||||
ASSERT_TRUE(res == nullptr);
|
||||
}
|
||||
|
||||
TEST(ConnectionErrorTest, InvalidPort)
|
||||
{
|
||||
auto host = "localhost";
|
||||
auto sec = 2;
|
||||
auto ver = httplib::HttpVersion::v1_1;
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
auto port = 44380;
|
||||
httplib::SSLClient cli(host, port, sec, ver);
|
||||
#else
|
||||
auto port = 8080;
|
||||
httplib::Client cli(host, port, sec, ver);
|
||||
#endif
|
||||
|
||||
auto res = cli.get("/");
|
||||
ASSERT_TRUE(res == nullptr);
|
||||
}
|
||||
|
||||
TEST(ConnectionErrorTest, Timeout)
|
||||
{
|
||||
auto host = "google.com";
|
||||
auto sec = 2;
|
||||
auto ver = httplib::HttpVersion::v1_1;
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
auto port = 44380;
|
||||
httplib::SSLClient cli(host, port, sec, ver);
|
||||
#else
|
||||
auto port = 8080;
|
||||
httplib::Client cli(host, port, sec, ver);
|
||||
#endif
|
||||
|
||||
auto res = cli.get("/");
|
||||
ASSERT_TRUE(res == nullptr);
|
||||
}
|
||||
|
||||
class ServerTest : public ::testing::Test {
|
||||
protected:
|
||||
ServerTest()
|
||||
|
@ -584,7 +638,7 @@ TEST_F(ServerTest, GetMethodRemoteAddr)
|
|||
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...
|
||||
EXPECT_TRUE(res->body == "::1" || res->body == "127.0.0.1");
|
||||
}
|
||||
|
||||
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue