Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ cli.set_proxy_bearer_token_auth("pass");
### Range

```cpp
httplib::Client cli("httpbin.org");
httplib::Client cli("httpcan.org");

auto res = cli.Get("/range/32", {
httplib::make_range_header({{1, 10}}) // 'Range: bytes=1-10'
Expand Down
2 changes: 1 addition & 1 deletion example/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct StopWatch {
int main(void) {
string body(1024 * 5, 'a');

httplib::Client cli("httpbin.org", 80);
httplib::Client cli("httpcan.org", 80);

for (int i = 0; i < 3; i++) {
StopWatch sw(to_string(i).c_str());
Expand Down
91 changes: 71 additions & 20 deletions test/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ TEST_F(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver) {

TEST(RangeTest, FromHTTPBin_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
auto host = "httpbin.org";
auto host = "httpcan.org";
auto path = std::string{"/range/32"};
#else
auto host = "nghttp2.org";
Expand Down Expand Up @@ -1473,7 +1473,7 @@ TEST(ConnectionErrorTest, InvalidHost) {
}

TEST(ConnectionErrorTest, InvalidHost2) {
auto host = "httpbin.org/";
auto host = "httpcan.org/";

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
SSLClient cli(host);
Expand All @@ -1488,7 +1488,7 @@ TEST(ConnectionErrorTest, InvalidHost2) {
}

TEST(ConnectionErrorTest, InvalidHostCheckResultErrorToString) {
auto host = "httpbin.org/";
auto host = "httpcan.org/";

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
SSLClient cli(host);
Expand Down Expand Up @@ -1545,7 +1545,7 @@ TEST(ConnectionErrorTest, Timeout_Online) {

TEST(CancelTest, NoCancel_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
auto host = "httpbin.org";
auto host = "httpcan.org";
auto path = std::string{"/range/32"};
#else
auto host = "nghttp2.org";
Expand All @@ -1569,7 +1569,7 @@ TEST(CancelTest, NoCancel_Online) {

TEST(CancelTest, WithCancelSmallPayload_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
auto host = "httpbin.org";
auto host = "httpcan.org";
auto path = std::string{"/range/32"};
#else
auto host = "nghttp2.org";
Expand All @@ -1592,7 +1592,7 @@ TEST(CancelTest, WithCancelSmallPayload_Online) {

TEST(CancelTest, WithCancelLargePayload_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
auto host = "httpbin.org";
auto host = "httpcan.org";
auto path = std::string{"/range/65536"};
#else
auto host = "nghttp2.org";
Expand Down Expand Up @@ -1941,7 +1941,7 @@ static std::string remove_whitespace(const std::string &input) {

TEST(BaseAuthTest, FromHTTPWatch_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
auto host = "httpbin.org";
auto host = "httpcan.org";
auto path = std::string{"/basic-auth/hello/world"};
#else
auto host = "nghttp2.org";
Expand Down Expand Up @@ -1998,13 +1998,12 @@ TEST(BaseAuthTest, FromHTTPWatch_Online) {
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
TEST(DigestAuthTest, FromHTTPWatch_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
auto host = "httpbin.org";
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",
"/digest-auth/auth-int/hello/world/MD5",
};
#else
auto host = "nghttp2.org";
Expand Down Expand Up @@ -2032,8 +2031,60 @@ TEST(DigestAuthTest, FromHTTPWatch_Online) {
for (const auto &path : paths) {
auto res = cli.Get(path.c_str());
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\"}",
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);
}

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

// NOTE: Until httpbin.org fixes issue #46, the following test is commented
// out. Please see https://httpbin.org/digest-auth/auth/hello/world
// cli.set_digest_auth("bad", "world");
// for (const auto& path : paths) {
// auto res = cli.Get(path.c_str());
// ASSERT_TRUE(res);
// EXPECT_EQ(StatusCode::BadRequest_400, res->status);
// }
cli.set_digest_auth("bad", "world");
for (const auto &path : paths) {
auto res = cli.Get(path.c_str());
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
}
}
}
#endif

#endif

TEST(SpecifyServerIPAddressTest, AnotherHostname_Online) {
auto host = "google.com";
auto another_host = "example.com";
Expand Down Expand Up @@ -7924,7 +7975,7 @@ TEST(GetWithParametersTest, GetWithParameters2) {

TEST(ClientDefaultHeadersTest, DefaultHeaders_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
auto host = "httpbin.org";
auto host = "httpcan.org";
auto path = std::string{"/range/32"};
#else
auto host = "nghttp2.org";
Expand Down Expand Up @@ -8440,7 +8491,7 @@ TEST(SSLClientTest, UpdateCAStore) {

TEST(SSLClientTest, ServerNameIndication_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
auto host = "httpbin.org";
auto host = "httpcan.org";
auto path = std::string{"/get"};
#else
auto host = "nghttp2.org";
Expand Down Expand Up @@ -8684,7 +8735,7 @@ TEST(SSLClientTest, Issue2251_ClientCertFileNotMatchingKey) {

#if 0
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);

cli->set_address_family(AF_INET6);
Expand Down
30 changes: 15 additions & 15 deletions test/test_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ template <typename T> void BaseAuthTestFromHTTPWatch(T &cli) {
}

TEST(BaseAuthTest, NoSSL) {
Client cli("httpbin.org");
Client cli("httpcan.org");
BaseAuthTestFromHTTPWatch(cli);
}

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
TEST(BaseAuthTest, SSL) {
SSLClient cli("httpbin.org");
SSLClient cli("httpcan.org");
BaseAuthTestFromHTTPWatch(cli);
}
#endif
Expand All @@ -182,15 +182,17 @@ template <typename T> void DigestAuthTestFromHTTPWatch(T &cli) {
"/digest-auth/auth/hello/world/MD5",
"/digest-auth/auth/hello/world/SHA-256",
"/digest-auth/auth/hello/world/SHA-512",
"/digest-auth/auth-int/hello/world/MD5",
};

cli.set_digest_auth("hello", "world");
for (auto path : paths) {
auto res = cli.Get(path.c_str());
ASSERT_TRUE(res != nullptr);
EXPECT_EQ(normalizeJson("{\"authenticated\":true,\"user\":\"hello\"}\n"),
normalizeJson(res->body));
std::string algo(path.substr(path.rfind('/') + 1));
EXPECT_EQ(
normalizeJson("{\"algorithm\":\"" + algo +
"\",\"authenticated\":true,\"user\":\"hello\"}\n"),
normalizeJson(res->body));
EXPECT_EQ(StatusCode::OK_200, res->status);
}

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

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

TEST(DigestAuthTest, SSL) {
SSLClient cli("httpbin.org");
SSLClient cli("httpcan.org");
DigestAuthTestFromHTTPWatch(cli);
}

TEST(DigestAuthTest, NoSSL) {
Client cli("httpbin.org");
Client cli("httpcan.org");
DigestAuthTestFromHTTPWatch(cli);
}
#endif
Expand Down
Loading