You've already forked cpp-httplib
Replace httpbin.org with httpcan.org (#2300)
* Replace httpbin.org with httpcan.org * Fix DigestAuthTest.FromHTTPWatch_Online test
This commit is contained in:
committed by
GitHub
parent
681d388247
commit
b7097f1386
@@ -1012,7 +1012,7 @@ cli.set_proxy_bearer_token_auth("pass");
|
|||||||
### Range
|
### Range
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
httplib::Client cli("httpbin.org");
|
httplib::Client cli("httpcan.org");
|
||||||
|
|
||||||
auto res = cli.Get("/range/32", {
|
auto res = cli.Get("/range/32", {
|
||||||
httplib::make_range_header({{1, 10}}) // 'Range: bytes=1-10'
|
httplib::make_range_header({{1, 10}}) // 'Range: bytes=1-10'
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ struct StopWatch {
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
string body(1024 * 5, 'a');
|
string body(1024 * 5, 'a');
|
||||||
|
|
||||||
httplib::Client cli("httpbin.org", 80);
|
httplib::Client cli("httpcan.org", 80);
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
StopWatch sw(to_string(i).c_str());
|
StopWatch sw(to_string(i).c_str());
|
||||||
|
|||||||
91
test/test.cc
91
test/test.cc
@@ -1371,7 +1371,7 @@ TEST_F(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver) {
|
|||||||
|
|
||||||
TEST(RangeTest, FromHTTPBin_Online) {
|
TEST(RangeTest, FromHTTPBin_Online) {
|
||||||
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
auto host = "httpbin.org";
|
auto host = "httpcan.org";
|
||||||
auto path = std::string{"/range/32"};
|
auto path = std::string{"/range/32"};
|
||||||
#else
|
#else
|
||||||
auto host = "nghttp2.org";
|
auto host = "nghttp2.org";
|
||||||
@@ -1473,7 +1473,7 @@ TEST(ConnectionErrorTest, InvalidHost) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(ConnectionErrorTest, InvalidHost2) {
|
TEST(ConnectionErrorTest, InvalidHost2) {
|
||||||
auto host = "httpbin.org/";
|
auto host = "httpcan.org/";
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
SSLClient cli(host);
|
SSLClient cli(host);
|
||||||
@@ -1488,7 +1488,7 @@ TEST(ConnectionErrorTest, InvalidHost2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(ConnectionErrorTest, InvalidHostCheckResultErrorToString) {
|
TEST(ConnectionErrorTest, InvalidHostCheckResultErrorToString) {
|
||||||
auto host = "httpbin.org/";
|
auto host = "httpcan.org/";
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
SSLClient cli(host);
|
SSLClient cli(host);
|
||||||
@@ -1545,7 +1545,7 @@ TEST(ConnectionErrorTest, Timeout_Online) {
|
|||||||
|
|
||||||
TEST(CancelTest, NoCancel_Online) {
|
TEST(CancelTest, NoCancel_Online) {
|
||||||
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
auto host = "httpbin.org";
|
auto host = "httpcan.org";
|
||||||
auto path = std::string{"/range/32"};
|
auto path = std::string{"/range/32"};
|
||||||
#else
|
#else
|
||||||
auto host = "nghttp2.org";
|
auto host = "nghttp2.org";
|
||||||
@@ -1569,7 +1569,7 @@ TEST(CancelTest, NoCancel_Online) {
|
|||||||
|
|
||||||
TEST(CancelTest, WithCancelSmallPayload_Online) {
|
TEST(CancelTest, WithCancelSmallPayload_Online) {
|
||||||
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
auto host = "httpbin.org";
|
auto host = "httpcan.org";
|
||||||
auto path = std::string{"/range/32"};
|
auto path = std::string{"/range/32"};
|
||||||
#else
|
#else
|
||||||
auto host = "nghttp2.org";
|
auto host = "nghttp2.org";
|
||||||
@@ -1592,7 +1592,7 @@ TEST(CancelTest, WithCancelSmallPayload_Online) {
|
|||||||
|
|
||||||
TEST(CancelTest, WithCancelLargePayload_Online) {
|
TEST(CancelTest, WithCancelLargePayload_Online) {
|
||||||
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
auto host = "httpbin.org";
|
auto host = "httpcan.org";
|
||||||
auto path = std::string{"/range/65536"};
|
auto path = std::string{"/range/65536"};
|
||||||
#else
|
#else
|
||||||
auto host = "nghttp2.org";
|
auto host = "nghttp2.org";
|
||||||
@@ -1941,7 +1941,7 @@ static std::string remove_whitespace(const std::string &input) {
|
|||||||
|
|
||||||
TEST(BaseAuthTest, FromHTTPWatch_Online) {
|
TEST(BaseAuthTest, FromHTTPWatch_Online) {
|
||||||
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
auto host = "httpbin.org";
|
auto host = "httpcan.org";
|
||||||
auto path = std::string{"/basic-auth/hello/world"};
|
auto path = std::string{"/basic-auth/hello/world"};
|
||||||
#else
|
#else
|
||||||
auto host = "nghttp2.org";
|
auto host = "nghttp2.org";
|
||||||
@@ -1998,13 +1998,12 @@ TEST(BaseAuthTest, FromHTTPWatch_Online) {
|
|||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
TEST(DigestAuthTest, FromHTTPWatch_Online) {
|
TEST(DigestAuthTest, FromHTTPWatch_Online) {
|
||||||
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
auto host = "httpbin.org";
|
auto host = "httpcan.org";
|
||||||
auto unauth_path = std::string{"/digest-auth/auth/hello/world"};
|
auto unauth_path = std::string{"/digest-auth/auth/hello/world"};
|
||||||
auto paths = std::vector<std::string>{
|
auto paths = std::vector<std::string>{
|
||||||
"/digest-auth/auth/hello/world/MD5",
|
"/digest-auth/auth/hello/world/MD5",
|
||||||
"/digest-auth/auth/hello/world/SHA-256",
|
"/digest-auth/auth/hello/world/SHA-256",
|
||||||
"/digest-auth/auth/hello/world/SHA-512",
|
"/digest-auth/auth/hello/world/SHA-512",
|
||||||
"/digest-auth/auth-int/hello/world/MD5",
|
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
auto host = "nghttp2.org";
|
auto host = "nghttp2.org";
|
||||||
@@ -2032,8 +2031,60 @@ TEST(DigestAuthTest, FromHTTPWatch_Online) {
|
|||||||
for (const auto &path : paths) {
|
for (const auto &path : paths) {
|
||||||
auto res = cli.Get(path.c_str());
|
auto res = cli.Get(path.c_str());
|
||||||
ASSERT_TRUE(res);
|
ASSERT_TRUE(res);
|
||||||
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
|
std::string algo(path.substr(path.rfind('/') + 1));
|
||||||
|
EXPECT_EQ(
|
||||||
|
remove_whitespace("{\"algorithm\":\"" + algo +
|
||||||
|
"\",\"authenticated\":true,\"user\":\"hello\"}\n"),
|
||||||
|
remove_whitespace(res->body));
|
||||||
|
#else
|
||||||
EXPECT_EQ("{\"authenticated\":true,\"user\":\"hello\"}",
|
EXPECT_EQ("{\"authenticated\":true,\"user\":\"hello\"}",
|
||||||
remove_whitespace(res->body));
|
remove_whitespace(res->body));
|
||||||
|
#endif
|
||||||
|
EXPECT_EQ(StatusCode::OK_200, res->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
|
cli.set_digest_auth("hello", "bad");
|
||||||
|
for (const auto &path : paths) {
|
||||||
|
auto res = cli.Get(path.c_str());
|
||||||
|
ASSERT_TRUE(res);
|
||||||
|
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
|
TEST(DigestAuthTest, FromHTTPWatch_Online_HTTPCan) {
|
||||||
|
auto host = "httpcan.org";
|
||||||
|
auto unauth_path = std::string{"/digest-auth/auth/hello/world"};
|
||||||
|
auto paths = std::vector<std::string>{
|
||||||
|
"/digest-auth/auth/hello/world/MD5",
|
||||||
|
"/digest-auth/auth/hello/world/SHA-256",
|
||||||
|
"/digest-auth/auth/hello/world/SHA-512",
|
||||||
|
};
|
||||||
|
|
||||||
|
auto port = 443;
|
||||||
|
SSLClient cli(host, port);
|
||||||
|
|
||||||
|
{
|
||||||
|
auto res = cli.Get(unauth_path);
|
||||||
|
ASSERT_TRUE(res);
|
||||||
|
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
cli.set_digest_auth("hello", "world");
|
||||||
|
for (const auto &path : paths) {
|
||||||
|
auto res = cli.Get(path.c_str());
|
||||||
|
ASSERT_TRUE(res);
|
||||||
|
std::string algo(path.substr(path.rfind('/') + 1));
|
||||||
|
EXPECT_EQ(
|
||||||
|
remove_whitespace("{\"algorithm\":\"" + algo +
|
||||||
|
"\",\"authenticated\":true,\"user\":\"hello\"}\n"),
|
||||||
|
remove_whitespace(res->body));
|
||||||
EXPECT_EQ(StatusCode::OK_200, res->status);
|
EXPECT_EQ(StatusCode::OK_200, res->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2044,18 +2095,18 @@ TEST(DigestAuthTest, FromHTTPWatch_Online) {
|
|||||||
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Until httpbin.org fixes issue #46, the following test is commented
|
cli.set_digest_auth("bad", "world");
|
||||||
// out. Please see https://httpbin.org/digest-auth/auth/hello/world
|
for (const auto &path : paths) {
|
||||||
// cli.set_digest_auth("bad", "world");
|
auto res = cli.Get(path.c_str());
|
||||||
// for (const auto& path : paths) {
|
ASSERT_TRUE(res);
|
||||||
// auto res = cli.Get(path.c_str());
|
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
||||||
// ASSERT_TRUE(res);
|
}
|
||||||
// EXPECT_EQ(StatusCode::BadRequest_400, res->status);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST(SpecifyServerIPAddressTest, AnotherHostname_Online) {
|
TEST(SpecifyServerIPAddressTest, AnotherHostname_Online) {
|
||||||
auto host = "google.com";
|
auto host = "google.com";
|
||||||
auto another_host = "example.com";
|
auto another_host = "example.com";
|
||||||
@@ -7924,7 +7975,7 @@ TEST(GetWithParametersTest, GetWithParameters2) {
|
|||||||
|
|
||||||
TEST(ClientDefaultHeadersTest, DefaultHeaders_Online) {
|
TEST(ClientDefaultHeadersTest, DefaultHeaders_Online) {
|
||||||
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
auto host = "httpbin.org";
|
auto host = "httpcan.org";
|
||||||
auto path = std::string{"/range/32"};
|
auto path = std::string{"/range/32"};
|
||||||
#else
|
#else
|
||||||
auto host = "nghttp2.org";
|
auto host = "nghttp2.org";
|
||||||
@@ -8440,7 +8491,7 @@ TEST(SSLClientTest, UpdateCAStore) {
|
|||||||
|
|
||||||
TEST(SSLClientTest, ServerNameIndication_Online) {
|
TEST(SSLClientTest, ServerNameIndication_Online) {
|
||||||
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
|
||||||
auto host = "httpbin.org";
|
auto host = "httpcan.org";
|
||||||
auto path = std::string{"/get"};
|
auto path = std::string{"/get"};
|
||||||
#else
|
#else
|
||||||
auto host = "nghttp2.org";
|
auto host = "nghttp2.org";
|
||||||
@@ -8684,7 +8735,7 @@ TEST(SSLClientTest, Issue2251_ClientCertFileNotMatchingKey) {
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
TEST(SSLClientTest, SetInterfaceWithINET6) {
|
TEST(SSLClientTest, SetInterfaceWithINET6) {
|
||||||
auto cli = std::make_shared<httplib::Client>("https://httpbin.org");
|
auto cli = std::make_shared<httplib::Client>("https://httpcan.org");
|
||||||
ASSERT_TRUE(cli != nullptr);
|
ASSERT_TRUE(cli != nullptr);
|
||||||
|
|
||||||
cli->set_address_family(AF_INET6);
|
cli->set_address_family(AF_INET6);
|
||||||
|
|||||||
@@ -153,13 +153,13 @@ template <typename T> void BaseAuthTestFromHTTPWatch(T &cli) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(BaseAuthTest, NoSSL) {
|
TEST(BaseAuthTest, NoSSL) {
|
||||||
Client cli("httpbin.org");
|
Client cli("httpcan.org");
|
||||||
BaseAuthTestFromHTTPWatch(cli);
|
BaseAuthTestFromHTTPWatch(cli);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
TEST(BaseAuthTest, SSL) {
|
TEST(BaseAuthTest, SSL) {
|
||||||
SSLClient cli("httpbin.org");
|
SSLClient cli("httpcan.org");
|
||||||
BaseAuthTestFromHTTPWatch(cli);
|
BaseAuthTestFromHTTPWatch(cli);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -182,14 +182,16 @@ template <typename T> void DigestAuthTestFromHTTPWatch(T &cli) {
|
|||||||
"/digest-auth/auth/hello/world/MD5",
|
"/digest-auth/auth/hello/world/MD5",
|
||||||
"/digest-auth/auth/hello/world/SHA-256",
|
"/digest-auth/auth/hello/world/SHA-256",
|
||||||
"/digest-auth/auth/hello/world/SHA-512",
|
"/digest-auth/auth/hello/world/SHA-512",
|
||||||
"/digest-auth/auth-int/hello/world/MD5",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cli.set_digest_auth("hello", "world");
|
cli.set_digest_auth("hello", "world");
|
||||||
for (auto path : paths) {
|
for (auto path : paths) {
|
||||||
auto res = cli.Get(path.c_str());
|
auto res = cli.Get(path.c_str());
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
EXPECT_EQ(normalizeJson("{\"authenticated\":true,\"user\":\"hello\"}\n"),
|
std::string algo(path.substr(path.rfind('/') + 1));
|
||||||
|
EXPECT_EQ(
|
||||||
|
normalizeJson("{\"algorithm\":\"" + algo +
|
||||||
|
"\",\"authenticated\":true,\"user\":\"hello\"}\n"),
|
||||||
normalizeJson(res->body));
|
normalizeJson(res->body));
|
||||||
EXPECT_EQ(StatusCode::OK_200, res->status);
|
EXPECT_EQ(StatusCode::OK_200, res->status);
|
||||||
}
|
}
|
||||||
@@ -201,24 +203,22 @@ template <typename T> void DigestAuthTestFromHTTPWatch(T &cli) {
|
|||||||
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Until httpbin.org fixes issue #46, the following test is commented
|
cli.set_digest_auth("bad", "world");
|
||||||
// out. Please see https://httpbin.org/digest-auth/auth/hello/world
|
for (auto path : paths) {
|
||||||
// cli.set_digest_auth("bad", "world");
|
auto res = cli.Get(path.c_str());
|
||||||
// for (auto path : paths) {
|
ASSERT_TRUE(res != nullptr);
|
||||||
// auto res = cli.Get(path.c_str());
|
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
||||||
// ASSERT_TRUE(res != nullptr);
|
}
|
||||||
// EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DigestAuthTest, SSL) {
|
TEST(DigestAuthTest, SSL) {
|
||||||
SSLClient cli("httpbin.org");
|
SSLClient cli("httpcan.org");
|
||||||
DigestAuthTestFromHTTPWatch(cli);
|
DigestAuthTestFromHTTPWatch(cli);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DigestAuthTest, NoSSL) {
|
TEST(DigestAuthTest, NoSSL) {
|
||||||
Client cli("httpbin.org");
|
Client cli("httpcan.org");
|
||||||
DigestAuthTestFromHTTPWatch(cli);
|
DigestAuthTestFromHTTPWatch(cli);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user