Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -8510,8 +8510,8 @@ inline ClientImpl::ClientImpl(const std::string &host, int port)
inline ClientImpl::ClientImpl(const std::string &host, int port,
const std::string &client_cert_path,
const std::string &client_key_path)
: host_(detail::escape_abstract_namespace_unix_domain(host)), port_(port),
host_and_port_(adjust_host_string(host_) + ":" + std::to_string(port)),
: host_(adjust_host_string(detail::escape_abstract_namespace_unix_domain(host))), port_(port),
host_and_port_(host_ + ":" + std::to_string(port)),
client_cert_path_(client_cert_path), client_key_path_(client_key_path) {}

inline ClientImpl::~ClientImpl() {
Expand Down
20 changes: 14 additions & 6 deletions test/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,7 @@ TEST(RedirectFromPageWithContentIP6, Redirect) {
res.set_content("Hello World!", "text/plain");
});

auto th = std::thread([&]() { svr.listen("::1", 1234); });
auto th = std::thread([&]() { svr.listen("[::1]", 1234); });
auto se = detail::scope_exit([&] {
svr.stop();
th.join();
Expand Down Expand Up @@ -2374,7 +2374,7 @@ TEST(BindServerTest, DISABLED_BindDualStack) {
EXPECT_EQ("Hello World!", res->body);
}
{
Client cli("::1", PORT);
Client cli("[::1]", PORT);

auto res = cli.Get("/1");
ASSERT_TRUE(res);
Expand Down Expand Up @@ -3650,7 +3650,7 @@ void performance_test(const char *host) {

TEST(BenchmarkTest, localhost) { performance_test("localhost"); }

TEST(BenchmarkTest, v6) { performance_test("::1"); }
TEST(BenchmarkTest, v6) { performance_test("[::1]"); }

TEST_F(ServerTest, GetEmptyFile) {
auto res = cli_.Get("/empty_file");
Expand Down Expand Up @@ -4987,15 +4987,15 @@ TEST_F(ServerTest, GetMethodRemoteAddr) {
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
EXPECT_TRUE(res->body == "::1" || res->body == "127.0.0.1");
EXPECT_TRUE(res->body == "[::1]" || res->body == "127.0.0.1");
}

TEST_F(ServerTest, GetMethodLocalAddr) {
auto res = cli_.Get("/local_addr");
ASSERT_TRUE(res);
EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
EXPECT_TRUE(res->body == std::string("::1:").append(to_string(PORT)) ||
EXPECT_TRUE(res->body == std::string("[::1]:").append(to_string(PORT)) ||
res->body == std::string("127.0.0.1:").append(to_string(PORT)));
}

Expand Down Expand Up @@ -7401,7 +7401,7 @@ TEST(SNI_AutoDetectionTest, SNI_Logic) {
}

{
SSLClient cli("::1", PORT);
SSLClient cli("[::1]", PORT);
cli.enable_server_certificate_verification(false);
auto res = cli.Get("/sni?expected=");
ASSERT_TRUE(res);
Expand Down Expand Up @@ -10285,6 +10285,14 @@ TEST(UniversalClientImplTest, Ipv6LiteralAddress) {
EXPECT_EQ(cli.port(), port);
}

TEST(UniversalClientImplHostTest, Ipv6LiteralAddressHost) {
std::string host = "[::1]";
std::string ipV6TestURL = "http://" + host;

Client cli(ipV6TestURL);
EXPECT_EQ(cli.host(), host);
}

TEST(FileSystemTest, FileAndDirExistenceCheck) {
auto file_path = "./www/dir/index.html";
auto dir_path = "./www/dir";
Expand Down