Skip to content

Commit 08133b5

Browse files
committed
Merge branch 'staticlibs-ssl_error_reporting'
2 parents bae40fc + 8aedbf4 commit 08133b5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

httplib.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10923,7 +10923,11 @@ inline long SSLClient::get_openssl_verify_result() const {
1092310923
inline SSL_CTX *SSLClient::ssl_context() const { return ctx_; }
1092410924

1092510925
inline bool SSLClient::create_and_connect_socket(Socket &socket, Error &error) {
10926-
return is_valid() && ClientImpl::create_and_connect_socket(socket, error);
10926+
if (!is_valid()) {
10927+
error = Error::SSLConnection;
10928+
return false;
10929+
}
10930+
return ClientImpl::create_and_connect_socket(socket, error);
1092710931
}
1092810932

1092910933
// Assumes that socket_mutex_ is locked and that there are no requests in

test/test.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8366,6 +8366,19 @@ TEST(SSLClientTest, Issue2004_Online) {
83668366
EXPECT_EQ(body.substr(0, 15), "<!doctype html>");
83678367
}
83688368

8369+
TEST(SSLClientTest, ErrorReportingWhenInvalid) {
8370+
// Create SSLClient with invalid cert/key to make is_valid() return false
8371+
SSLClient cli("localhost", 8080, "nonexistent_cert.pem",
8372+
"nonexistent_key.pem");
8373+
8374+
// is_valid() should be false due to cert loading failure
8375+
ASSERT_FALSE(cli.is_valid());
8376+
8377+
auto res = cli.Get("/");
8378+
ASSERT_FALSE(res);
8379+
EXPECT_EQ(Error::SSLConnection, res.error());
8380+
}
8381+
83698382
#if 0
83708383
TEST(SSLClientTest, SetInterfaceWithINET6) {
83718384
auto cli = std::make_shared<httplib::Client>("https://httpbin.org");

0 commit comments

Comments
 (0)