Use go-httplibbin

This commit is contained in:
yhirose committed 2026-03-27 22:26:14 -04:00
1 parent a77284a634
commit ceefc14e7d
2 files changed
+71 -112

No files matched your search

+44 -84
View File
@@ -1449,13 +1449,8 @@ TEST_F(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver) {
} }
TEST(RangeTest, FromHTTPBin_Online) { TEST(RangeTest, FromHTTPBin_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN auto host = "httpbingo.org";
auto host = "httpcan.org";
auto path = std::string{"/range/32"}; auto path = std::string{"/range/32"};
#else
auto host = "nghttp2.org";
auto path = std::string{"/httpbin/range/32"};
#endif
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
auto port = 443; auto port = 443;
@@ -1489,12 +1484,16 @@ TEST(RangeTest, FromHTTPBin_Online) {
EXPECT_EQ(StatusCode::PartialContent_206, res->status); EXPECT_EQ(StatusCode::PartialContent_206, res->status);
} }
// go-httpbin (httpbingo.org) returns 206 even when the range covers the
// entire resource, while the original httpbin returned 200. Both are
// acceptable per RFC 9110 §15.3.7, so we accept either status code.
{ {
Headers headers = {make_range_header({{0, 31}})}; Headers headers = {make_range_header({{0, 31}})};
auto res = cli.Get(path, headers); auto res = cli.Get(path, headers);
ASSERT_TRUE(res); ASSERT_TRUE(res);
EXPECT_EQ("abcdefghijklmnopqrstuvwxyzabcdef", res->body); EXPECT_EQ("abcdefghijklmnopqrstuvwxyzabcdef", res->body);
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_TRUE(res->status == StatusCode::OK_200 ||
res->status == StatusCode::PartialContent_206);
} }
{ {
@@ -1502,14 +1501,17 @@ TEST(RangeTest, FromHTTPBin_Online) {
auto res = cli.Get(path, headers); auto res = cli.Get(path, headers);
ASSERT_TRUE(res); ASSERT_TRUE(res);
EXPECT_EQ("abcdefghijklmnopqrstuvwxyzabcdef", res->body); EXPECT_EQ("abcdefghijklmnopqrstuvwxyzabcdef", res->body);
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_TRUE(res->status == StatusCode::OK_200 ||
res->status == StatusCode::PartialContent_206);
} }
// go-httpbin returns 206 with clamped range for over-range requests,
// while the original httpbin returned 416. Both behaviors are observed
// in real servers, so we only verify the request succeeds.
{ {
Headers headers = {make_range_header({{0, 32}})}; Headers headers = {make_range_header({{0, 32}})};
auto res = cli.Get(path, headers); auto res = cli.Get(path, headers);
ASSERT_TRUE(res); ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::RangeNotSatisfiable_416, res->status);
} }
} }
@@ -1623,13 +1625,8 @@ TEST(ConnectionErrorTest, Timeout_Online) {
} }
TEST(CancelTest, NoCancel_Online) { TEST(CancelTest, NoCancel_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN auto host = "httpbingo.org";
auto host = "httpcan.org";
auto path = std::string{"/range/32"}; auto path = std::string{"/range/32"};
#else
auto host = "nghttp2.org";
auto path = std::string{"/httpbin/range/32"};
#endif
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
auto port = 443; auto port = 443;
@@ -1647,13 +1644,11 @@ TEST(CancelTest, NoCancel_Online) {
} }
TEST(CancelTest, WithCancelSmallPayload_Online) { TEST(CancelTest, WithCancelSmallPayload_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN // Use /bytes with a large payload so that the DownloadProgress callback
auto host = "httpcan.org"; // (which only fires for Content-Length responses) is invoked before the
auto path = std::string{"/range/32"}; // entire body is received, giving cancellation a chance to fire.
#else auto host = "httpbingo.org";
auto host = "nghttp2.org"; auto path = std::string{"/bytes/524288"};
auto path = std::string{"/httpbin/range/32"};
#endif
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
auto port = 443; auto port = 443;
@@ -1670,13 +1665,8 @@ TEST(CancelTest, WithCancelSmallPayload_Online) {
} }
TEST(CancelTest, WithCancelLargePayload_Online) { TEST(CancelTest, WithCancelLargePayload_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN auto host = "httpbingo.org";
auto host = "httpcan.org"; auto path = std::string{"/bytes/524288"};
auto path = std::string{"/range/65536"};
#else
auto host = "nghttp2.org";
auto path = std::string{"/httpbin/range/65536"};
#endif
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
auto port = 443; auto port = 443;
@@ -2027,13 +2017,8 @@ static std::string remove_whitespace(const std::string &input) {
} }
TEST(BaseAuthTest, FromHTTPWatch_Online) { TEST(BaseAuthTest, FromHTTPWatch_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN auto host = "httpbingo.org";
auto host = "httpcan.org";
auto path = std::string{"/basic-auth/hello/world"}; auto path = std::string{"/basic-auth/hello/world"};
#else
auto host = "nghttp2.org";
auto path = std::string{"/httpbin/basic-auth/hello/world"};
#endif
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
auto port = 443; auto port = 443;
@@ -2053,8 +2038,9 @@ TEST(BaseAuthTest, FromHTTPWatch_Online) {
auto res = auto res =
cli.Get(path, {make_basic_authentication_header("hello", "world")}); cli.Get(path, {make_basic_authentication_header("hello", "world")});
ASSERT_TRUE(res); ASSERT_TRUE(res);
EXPECT_EQ("{\"authenticated\":true,\"user\":\"hello\"}", auto body = remove_whitespace(res->body);
remove_whitespace(res->body)); EXPECT_TRUE(body.find("\"authenticated\":true") != std::string::npos);
EXPECT_TRUE(body.find("\"user\":\"hello\"") != std::string::npos);
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
@@ -2062,8 +2048,9 @@ TEST(BaseAuthTest, FromHTTPWatch_Online) {
cli.set_basic_auth("hello", "world"); cli.set_basic_auth("hello", "world");
auto res = cli.Get(path); auto res = cli.Get(path);
ASSERT_TRUE(res); ASSERT_TRUE(res);
EXPECT_EQ("{\"authenticated\":true,\"user\":\"hello\"}", auto body = remove_whitespace(res->body);
remove_whitespace(res->body)); EXPECT_TRUE(body.find("\"authenticated\":true") != std::string::npos);
EXPECT_TRUE(body.find("\"user\":\"hello\"") != std::string::npos);
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
@@ -2084,24 +2071,12 @@ TEST(BaseAuthTest, FromHTTPWatch_Online) {
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
TEST(DigestAuthTest, FromHTTPWatch_Online) { TEST(DigestAuthTest, FromHTTPWatch_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN auto host = "httpbingo.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",
}; };
#else
auto host = "nghttp2.org";
auto unauth_path = std::string{"/httpbin/digest-auth/auth/hello/world"};
auto paths = std::vector<std::string>{
"/httpbin/digest-auth/auth/hello/world/MD5",
"/httpbin/digest-auth/auth/hello/world/SHA-256",
"/httpbin/digest-auth/auth/hello/world/SHA-512",
"/httpbin/digest-auth/auth-int/hello/world/MD5",
};
#endif
auto port = 443; auto port = 443;
SSLClient cli(host, port); SSLClient cli(host, port);
@@ -2118,27 +2093,18 @@ 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 auto body = remove_whitespace(res->body);
std::string algo(path.substr(path.rfind('/') + 1)); EXPECT_TRUE(body.find("\"authenticated\":true") != std::string::npos);
EXPECT_EQ( EXPECT_TRUE(body.find("\"user\":\"hello\"") != std::string::npos);
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); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN
cli.set_digest_auth("hello", "bad"); cli.set_digest_auth("hello", "bad");
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);
EXPECT_EQ(StatusCode::Unauthorized_401, res->status); EXPECT_EQ(StatusCode::Unauthorized_401, res->status);
} }
#endif
} }
} }
@@ -2178,7 +2144,8 @@ TEST(SpecifyServerIPAddressTest, RealHostname_Online) {
} }
TEST(AbsoluteRedirectTest, Redirect_Online) { TEST(AbsoluteRedirectTest, Redirect_Online) {
auto host = "nghttp2.org"; auto host = "httpbingo.org";
auto path = std::string{"/absolute-redirect/3"};
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
SSLClient cli(host); SSLClient cli(host);
@@ -2187,13 +2154,14 @@ TEST(AbsoluteRedirectTest, Redirect_Online) {
#endif #endif
cli.set_follow_location(true); cli.set_follow_location(true);
auto res = cli.Get("/httpbin/absolute-redirect/3"); auto res = cli.Get(path);
ASSERT_TRUE(res); ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
TEST(RedirectTest, Redirect_Online) { TEST(RedirectTest, Redirect_Online) {
auto host = "nghttp2.org"; auto host = "httpbingo.org";
auto path = std::string{"/redirect/3"};
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
SSLClient cli(host); SSLClient cli(host);
@@ -2202,13 +2170,14 @@ TEST(RedirectTest, Redirect_Online) {
#endif #endif
cli.set_follow_location(true); cli.set_follow_location(true);
auto res = cli.Get("/httpbin/redirect/3"); auto res = cli.Get(path);
ASSERT_TRUE(res); ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
TEST(RelativeRedirectTest, Redirect_Online) { TEST(RelativeRedirectTest, Redirect_Online) {
auto host = "nghttp2.org"; auto host = "httpbingo.org";
auto path = std::string{"/relative-redirect/3"};
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
SSLClient cli(host); SSLClient cli(host);
@@ -2217,13 +2186,14 @@ TEST(RelativeRedirectTest, Redirect_Online) {
#endif #endif
cli.set_follow_location(true); cli.set_follow_location(true);
auto res = cli.Get("/httpbin/relative-redirect/3"); auto res = cli.Get(path);
ASSERT_TRUE(res); ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
TEST(TooManyRedirectTest, Redirect_Online) { TEST(TooManyRedirectTest, Redirect_Online) {
auto host = "nghttp2.org"; auto host = "httpbingo.org";
auto path = std::string{"/redirect/21"};
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
SSLClient cli(host); SSLClient cli(host);
@@ -2232,7 +2202,7 @@ TEST(TooManyRedirectTest, Redirect_Online) {
#endif #endif
cli.set_follow_location(true); cli.set_follow_location(true);
auto res = cli.Get("/httpbin/redirect/21"); auto res = cli.Get(path);
ASSERT_TRUE(!res); ASSERT_TRUE(!res);
EXPECT_EQ(Error::ExceedRedirectCount, res.error()); EXPECT_EQ(Error::ExceedRedirectCount, res.error());
} }
@@ -8372,13 +8342,8 @@ TEST(GetWithParametersTest, GetWithParameters2) {
} }
TEST(ClientDefaultHeadersTest, DefaultHeaders_Online) { TEST(ClientDefaultHeadersTest, DefaultHeaders_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN auto host = "httpbingo.org";
auto host = "httpcan.org";
auto path = std::string{"/range/32"}; auto path = std::string{"/range/32"};
#else
auto host = "nghttp2.org";
auto path = std::string{"/httpbin/range/32"};
#endif
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
SSLClient cli(host); SSLClient cli(host);
@@ -9669,13 +9634,8 @@ TEST(SSLClientTest, UpdateCAStoreWithPem_Online) {
} }
TEST(SSLClientTest, ServerNameIndication_Online) { TEST(SSLClientTest, ServerNameIndication_Online) {
#ifdef CPPHTTPLIB_DEFAULT_HTTPBIN auto host = "httpbingo.org";
auto host = "httpcan.org";
auto path = std::string{"/get"}; auto path = std::string{"/get"};
#else
auto host = "nghttp2.org";
auto path = std::string{"/httpbin/get"};
#endif
SSLClient cli(host, 443); SSLClient cli(host, 443);
auto res = cli.Get(path); auto res = cli.Get(path);
+27 -28
View File
@@ -16,29 +16,29 @@ std::string normalizeJson(const std::string &json) {
template <typename T> void ProxyTest(T &cli, bool basic) { template <typename T> void ProxyTest(T &cli, bool basic) {
cli.set_proxy("localhost", basic ? 3128 : 3129); cli.set_proxy("localhost", basic ? 3128 : 3129);
auto res = cli.Get("/httpbin/get"); auto res = cli.Get("/get");
ASSERT_TRUE(res != nullptr); ASSERT_TRUE(res != nullptr);
EXPECT_EQ(StatusCode::ProxyAuthenticationRequired_407, res->status); EXPECT_EQ(StatusCode::ProxyAuthenticationRequired_407, res->status);
} }
TEST(ProxyTest, NoSSLBasic) { TEST(ProxyTest, NoSSLBasic) {
Client cli("nghttp2.org"); Client cli("httpbingo.org");
ProxyTest(cli, true); ProxyTest(cli, true);
} }
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
TEST(ProxyTest, SSLBasic) { TEST(ProxyTest, SSLBasic) {
SSLClient cli("nghttp2.org"); SSLClient cli("httpbingo.org");
ProxyTest(cli, true); ProxyTest(cli, true);
} }
TEST(ProxyTest, NoSSLDigest) { TEST(ProxyTest, NoSSLDigest) {
Client cli("nghttp2.org"); Client cli("httpbingo.org");
ProxyTest(cli, false); ProxyTest(cli, false);
} }
TEST(ProxyTest, SSLDigest) { TEST(ProxyTest, SSLDigest) {
SSLClient cli("nghttp2.org"); SSLClient cli("httpbingo.org");
ProxyTest(cli, false); ProxyTest(cli, false);
} }
#endif #endif
@@ -63,24 +63,24 @@ void RedirectProxyText(T &cli, const char *path, bool basic) {
} }
TEST(RedirectTest, HTTPBinNoSSLBasic) { TEST(RedirectTest, HTTPBinNoSSLBasic) {
Client cli("nghttp2.org"); Client cli("httpbingo.org");
RedirectProxyText(cli, "/httpbin/redirect/2", true); RedirectProxyText(cli, "/redirect/2", true);
} }
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
TEST(RedirectTest, HTTPBinNoSSLDigest) { TEST(RedirectTest, HTTPBinNoSSLDigest) {
Client cli("nghttp2.org"); Client cli("httpbingo.org");
RedirectProxyText(cli, "/httpbin/redirect/2", false); RedirectProxyText(cli, "/redirect/2", false);
} }
TEST(RedirectTest, HTTPBinSSLBasic) { TEST(RedirectTest, HTTPBinSSLBasic) {
SSLClient cli("nghttp2.org"); SSLClient cli("httpbingo.org");
RedirectProxyText(cli, "/httpbin/redirect/2", true); RedirectProxyText(cli, "/redirect/2", true);
} }
TEST(RedirectTest, HTTPBinSSLDigest) { TEST(RedirectTest, HTTPBinSSLDigest) {
SSLClient cli("nghttp2.org"); SSLClient cli("httpbingo.org");
RedirectProxyText(cli, "/httpbin/redirect/2", false); RedirectProxyText(cli, "/redirect/2", false);
} }
#endif #endif
@@ -290,26 +290,25 @@ template <typename T> void KeepAliveTest(T &cli, bool basic) {
#endif #endif
{ {
auto res = cli.Get("/httpbin/get"); auto res = cli.Get("/get");
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
{ {
auto res = cli.Get("/httpbin/redirect/2"); auto res = cli.Get("/redirect/2");
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
{ {
std::vector<std::string> paths = { std::vector<std::string> paths = {
"/httpbin/digest-auth/auth/hello/world/MD5", "/digest-auth/auth/hello/world/MD5",
"/httpbin/digest-auth/auth/hello/world/SHA-256", "/digest-auth/auth/hello/world/SHA-256",
"/httpbin/digest-auth/auth/hello/world/SHA-512",
"/httpbin/digest-auth/auth-int/hello/world/MD5",
}; };
for (auto path : paths) { for (auto path : paths) {
auto res = cli.Get(path.c_str()); auto res = cli.Get(path.c_str());
EXPECT_EQ(normalizeJson("{\"authenticated\":true,\"user\":\"hello\"}\n"), auto body = normalizeJson(res->body);
normalizeJson(res->body)); EXPECT_TRUE(body.find("\"authenticated\":true") != std::string::npos);
EXPECT_TRUE(body.find("\"user\":\"hello\"") != std::string::npos);
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
} }
@@ -317,7 +316,7 @@ template <typename T> void KeepAliveTest(T &cli, bool basic) {
{ {
int count = 10; int count = 10;
while (count--) { while (count--) {
auto res = cli.Get("/httpbin/get"); auto res = cli.Get("/get");
EXPECT_EQ(StatusCode::OK_200, res->status); EXPECT_EQ(StatusCode::OK_200, res->status);
} }
} }
@@ -325,22 +324,22 @@ template <typename T> void KeepAliveTest(T &cli, bool basic) {
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
TEST(KeepAliveTest, NoSSLWithBasic) { TEST(KeepAliveTest, NoSSLWithBasic) {
Client cli("nghttp2.org"); Client cli("httpbingo.org");
KeepAliveTest(cli, true); KeepAliveTest(cli, true);
} }
TEST(KeepAliveTest, SSLWithBasic) { TEST(KeepAliveTest, SSLWithBasic) {
SSLClient cli("nghttp2.org"); SSLClient cli("httpbingo.org");
KeepAliveTest(cli, true); KeepAliveTest(cli, true);
} }
TEST(KeepAliveTest, NoSSLWithDigest) { TEST(KeepAliveTest, NoSSLWithDigest) {
Client cli("nghttp2.org"); Client cli("httpbingo.org");
KeepAliveTest(cli, false); KeepAliveTest(cli, false);
} }
TEST(KeepAliveTest, SSLWithDigest) { TEST(KeepAliveTest, SSLWithDigest) {
SSLClient cli("nghttp2.org"); SSLClient cli("httpbingo.org");
KeepAliveTest(cli, false); KeepAliveTest(cli, false);
} }
#endif #endif
@@ -349,11 +348,11 @@ TEST(KeepAliveTest, SSLWithDigest) {
#ifdef CPPHTTPLIB_SSL_ENABLED #ifdef CPPHTTPLIB_SSL_ENABLED
TEST(ProxyTest, SSLOpenStream) { TEST(ProxyTest, SSLOpenStream) {
SSLClient cli("nghttp2.org"); SSLClient cli("httpbingo.org");
cli.set_proxy("localhost", 3128); cli.set_proxy("localhost", 3128);
cli.set_proxy_basic_auth("hello", "world"); cli.set_proxy_basic_auth("hello", "world");
auto handle = cli.open_stream("GET", "/httpbin/get"); auto handle = cli.open_stream("GET", "/get");
ASSERT_TRUE(handle.response); ASSERT_TRUE(handle.response);
EXPECT_EQ(StatusCode::OK_200, handle.response->status); EXPECT_EQ(StatusCode::OK_200, handle.response->status);