Skip to content

Commit b7097f1

Browse files
authored
Replace httpbin.org with httpcan.org (#2300)
* Replace httpbin.org with httpcan.org * Fix DigestAuthTest.FromHTTPWatch_Online test
1 parent 681d388 commit b7097f1

File tree

4 files changed

+88
-37
lines changed

4 files changed

+88
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ cli.set_proxy_bearer_token_auth("pass");
10121012
### Range
10131013

10141014
```cpp
1015-
httplib::Client cli("httpbin.org");
1015+
httplib::Client cli("httpcan.org");
10161016

10171017
auto res = cli.Get("/range/32", {
10181018
httplib::make_range_header({{1, 10}}) // 'Range: bytes=1-10'

example/benchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct StopWatch {
2121
int main(void) {
2222
string body(1024 * 5, 'a');
2323

24-
httplib::Client cli("httpbin.org", 80);
24+
httplib::Client cli("httpcan.org", 80);
2525

2626
for (int i = 0; i < 3; i++) {
2727
StopWatch sw(to_string(i).c_str());

test/test.cc

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ TEST_F(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver) {
13711371

13721372
TEST(RangeTest, FromHTTPBin_Online) {
13731373
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
1374-
auto host = "httpbin.org";
1374+
auto host = "httpcan.org";
13751375
auto path = std::string{"/range/32"};
13761376
#else
13771377
auto host = "nghttp2.org";
@@ -1473,7 +1473,7 @@ TEST(ConnectionErrorTest, InvalidHost) {
14731473
}
14741474

14751475
TEST(ConnectionErrorTest, InvalidHost2) {
1476-
auto host = "httpbin.org/";
1476+
auto host = "httpcan.org/";
14771477

14781478
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
14791479
SSLClient cli(host);
@@ -1488,7 +1488,7 @@ TEST(ConnectionErrorTest, InvalidHost2) {
14881488
}
14891489

14901490
TEST(ConnectionErrorTest, InvalidHostCheckResultErrorToString) {
1491-
auto host = "httpbin.org/";
1491+
auto host = "httpcan.org/";
14921492

14931493
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
14941494
SSLClient cli(host);
@@ -1545,7 +1545,7 @@ TEST(ConnectionErrorTest, Timeout_Online) {
15451545

15461546
TEST(CancelTest, NoCancel_Online) {
15471547
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
1548-
auto host = "httpbin.org";
1548+
auto host = "httpcan.org";
15491549
auto path = std::string{"/range/32"};
15501550
#else
15511551
auto host = "nghttp2.org";
@@ -1569,7 +1569,7 @@ TEST(CancelTest, NoCancel_Online) {
15691569

15701570
TEST(CancelTest, WithCancelSmallPayload_Online) {
15711571
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
1572-
auto host = "httpbin.org";
1572+
auto host = "httpcan.org";
15731573
auto path = std::string{"/range/32"};
15741574
#else
15751575
auto host = "nghttp2.org";
@@ -1592,7 +1592,7 @@ TEST(CancelTest, WithCancelSmallPayload_Online) {
15921592

15931593
TEST(CancelTest, WithCancelLargePayload_Online) {
15941594
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
1595-
auto host = "httpbin.org";
1595+
auto host = "httpcan.org";
15961596
auto path = std::string{"/range/65536"};
15971597
#else
15981598
auto host = "nghttp2.org";
@@ -1941,7 +1941,7 @@ static std::string remove_whitespace(const std::string &input) {
19411941

19421942
TEST(BaseAuthTest, FromHTTPWatch_Online) {
19431943
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
1944-
auto host = "httpbin.org";
1944+
auto host = "httpcan.org";
19451945
auto path = std::string{"/basic-auth/hello/world"};
19461946
#else
19471947
auto host = "nghttp2.org";
@@ -1998,13 +1998,12 @@ TEST(BaseAuthTest, FromHTTPWatch_Online) {
19981998
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
19991999
TEST(DigestAuthTest, FromHTTPWatch_Online) {
20002000
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
2001-
auto host = "httpbin.org";
2001+
auto host = "httpcan.org";
20022002
auto unauth_path = std::string{"/digest-auth/auth/hello/world"};
20032003
auto paths = std::vector<std::string>{
20042004
"/digest-auth/auth/hello/world/MD5",
20052005
"/digest-auth/auth/hello/world/SHA-256",
20062006
"/digest-auth/auth/hello/world/SHA-512",
2007-
"/digest-auth/auth-int/hello/world/MD5",
20082007
};
20092008
#else
20102009
auto host = "nghttp2.org";
@@ -2032,8 +2031,60 @@ TEST(DigestAuthTest, FromHTTPWatch_Online) {
20322031
for (const auto &path : paths) {
20332032
auto res = cli.Get(path.c_str());
20342033
ASSERT_TRUE(res);
2034+
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
2035+
std::string algo(path.substr(path.rfind('/') + 1));
2036+
EXPECT_EQ(
2037+
remove_whitespace("{\"algorithm\":\"" + algo +
2038+
"\",\"authenticated\":true,\"user\":\"hello\"}\n"),
2039+
remove_whitespace(res->body));
2040+
#else
20352041
EXPECT_EQ("{\"authenticated\":true,\"user\":\"hello\"}",
20362042
remove_whitespace(res->body));
2043+
#endif
2044+
EXPECT_EQ(StatusCode::OK_200, res->status);
2045+
}
2046+
2047+
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
2048+
cli.set_digest_auth("hello", "bad");
2049+
for (const auto &path : paths) {
2050+
auto res = cli.Get(path.c_str());
2051+
ASSERT_TRUE(res);
2052+
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
2053+
}
2054+
#endif
2055+
}
2056+
}
2057+
2058+
#ifndef CPPHTTPLIB_DEFAULT_HTTPBIN
2059+
TEST(DigestAuthTest, FromHTTPWatch_Online_HTTPCan) {
2060+
auto host = "httpcan.org";
2061+
auto unauth_path = std::string{"/digest-auth/auth/hello/world"};
2062+
auto paths = std::vector<std::string>{
2063+
"/digest-auth/auth/hello/world/MD5",
2064+
"/digest-auth/auth/hello/world/SHA-256",
2065+
"/digest-auth/auth/hello/world/SHA-512",
2066+
};
2067+
2068+
auto port = 443;
2069+
SSLClient cli(host, port);
2070+
2071+
{
2072+
auto res = cli.Get(unauth_path);
2073+
ASSERT_TRUE(res);
2074+
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
2075+
}
2076+
2077+
{
2078+
2079+
cli.set_digest_auth("hello", "world");
2080+
for (const auto &path : paths) {
2081+
auto res = cli.Get(path.c_str());
2082+
ASSERT_TRUE(res);
2083+
std::string algo(path.substr(path.rfind('/') + 1));
2084+
EXPECT_EQ(
2085+
remove_whitespace("{\"algorithm\":\"" + algo +
2086+
"\",\"authenticated\":true,\"user\":\"hello\"}\n"),
2087+
remove_whitespace(res->body));
20372088
EXPECT_EQ(StatusCode::OK_200, res->status);
20382089
}
20392090

@@ -2044,18 +2095,18 @@ TEST(DigestAuthTest, FromHTTPWatch_Online) {
20442095
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
20452096
}
20462097

2047-
// NOTE: Until httpbin.org fixes issue #46, the following test is commented
2048-
// out. Please see https://httpbin.org/digest-auth/auth/hello/world
2049-
// cli.set_digest_auth("bad", "world");
2050-
// for (const auto& path : paths) {
2051-
// auto res = cli.Get(path.c_str());
2052-
// ASSERT_TRUE(res);
2053-
// EXPECT_EQ(StatusCode::BadRequest_400, res->status);
2054-
// }
2098+
cli.set_digest_auth("bad", "world");
2099+
for (const auto &path : paths) {
2100+
auto res = cli.Get(path.c_str());
2101+
ASSERT_TRUE(res);
2102+
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
2103+
}
20552104
}
20562105
}
20572106
#endif
20582107

2108+
#endif
2109+
20592110
TEST(SpecifyServerIPAddressTest, AnotherHostname_Online) {
20602111
auto host = "google.com";
20612112
auto another_host = "example.com";
@@ -7924,7 +7975,7 @@ TEST(GetWithParametersTest, GetWithParameters2) {
79247975

79257976
TEST(ClientDefaultHeadersTest, DefaultHeaders_Online) {
79267977
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
7927-
auto host = "httpbin.org";
7978+
auto host = "httpcan.org";
79287979
auto path = std::string{"/range/32"};
79297980
#else
79307981
auto host = "nghttp2.org";
@@ -8440,7 +8491,7 @@ TEST(SSLClientTest, UpdateCAStore) {
84408491

84418492
TEST(SSLClientTest, ServerNameIndication_Online) {
84428493
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
8443-
auto host = "httpbin.org";
8494+
auto host = "httpcan.org";
84448495
auto path = std::string{"/get"};
84458496
#else
84468497
auto host = "nghttp2.org";
@@ -8684,7 +8735,7 @@ TEST(SSLClientTest, Issue2251_ClientCertFileNotMatchingKey) {
86848735

86858736
#if 0
86868737
TEST(SSLClientTest, SetInterfaceWithINET6) {
8687-
auto cli = std::make_shared<httplib::Client>("https://httpbin.org");
8738+
auto cli = std::make_shared<httplib::Client>("https://httpcan.org");
86888739
ASSERT_TRUE(cli != nullptr);
86898740

86908741
cli->set_address_family(AF_INET6);

test/test_proxy.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ template <typename T> void BaseAuthTestFromHTTPWatch(T &cli) {
153153
}
154154

155155
TEST(BaseAuthTest, NoSSL) {
156-
Client cli("httpbin.org");
156+
Client cli("httpcan.org");
157157
BaseAuthTestFromHTTPWatch(cli);
158158
}
159159

160160
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
161161
TEST(BaseAuthTest, SSL) {
162-
SSLClient cli("httpbin.org");
162+
SSLClient cli("httpcan.org");
163163
BaseAuthTestFromHTTPWatch(cli);
164164
}
165165
#endif
@@ -182,15 +182,17 @@ template <typename T> void DigestAuthTestFromHTTPWatch(T &cli) {
182182
"/digest-auth/auth/hello/world/MD5",
183183
"/digest-auth/auth/hello/world/SHA-256",
184184
"/digest-auth/auth/hello/world/SHA-512",
185-
"/digest-auth/auth-int/hello/world/MD5",
186185
};
187186

188187
cli.set_digest_auth("hello", "world");
189188
for (auto path : paths) {
190189
auto res = cli.Get(path.c_str());
191190
ASSERT_TRUE(res != nullptr);
192-
EXPECT_EQ(normalizeJson("{\"authenticated\":true,\"user\":\"hello\"}\n"),
193-
normalizeJson(res->body));
191+
std::string algo(path.substr(path.rfind('/') + 1));
192+
EXPECT_EQ(
193+
normalizeJson("{\"algorithm\":\"" + algo +
194+
"\",\"authenticated\":true,\"user\":\"hello\"}\n"),
195+
normalizeJson(res->body));
194196
EXPECT_EQ(StatusCode::OK_200, res->status);
195197
}
196198

@@ -201,24 +203,22 @@ template <typename T> void DigestAuthTestFromHTTPWatch(T &cli) {
201203
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
202204
}
203205

204-
// NOTE: Until httpbin.org fixes issue #46, the following test is commented
205-
// out. Please see https://httpbin.org/digest-auth/auth/hello/world
206-
// cli.set_digest_auth("bad", "world");
207-
// for (auto path : paths) {
208-
// auto res = cli.Get(path.c_str());
209-
// ASSERT_TRUE(res != nullptr);
210-
// EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
211-
// }
206+
cli.set_digest_auth("bad", "world");
207+
for (auto path : paths) {
208+
auto res = cli.Get(path.c_str());
209+
ASSERT_TRUE(res != nullptr);
210+
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
211+
}
212212
}
213213
}
214214

215215
TEST(DigestAuthTest, SSL) {
216-
SSLClient cli("httpbin.org");
216+
SSLClient cli("httpcan.org");
217217
DigestAuthTestFromHTTPWatch(cli);
218218
}
219219

220220
TEST(DigestAuthTest, NoSSL) {
221-
Client cli("httpbin.org");
221+
Client cli("httpcan.org");
222222
DigestAuthTestFromHTTPWatch(cli);
223223
}
224224
#endif

0 commit comments

Comments
 (0)