@@ -1582,6 +1582,9 @@ class ClientImpl {
1582
1582
bool send_ (Request &req, Response &res, Error &error);
1583
1583
Result send_ (Request &&req);
1584
1584
1585
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1586
+ bool is_ssl_peer_could_be_closed (SSL *ssl) const ;
1587
+ #endif
1585
1588
socket_t create_client_socket (Error &error) const ;
1586
1589
bool read_response_line (Stream &strm, const Request &req,
1587
1590
Response &res) const ;
@@ -7415,6 +7418,14 @@ inline bool ClientImpl::send(Request &req, Response &res, Error &error) {
7415
7418
return ret;
7416
7419
}
7417
7420
7421
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
7422
+ inline bool ClientImpl::is_ssl_peer_could_be_closed (SSL *ssl) const {
7423
+ char buf[1 ];
7424
+ return !SSL_peek (ssl, buf, 1 ) &&
7425
+ SSL_get_error (ssl, 0 ) == SSL_ERROR_ZERO_RETURN;
7426
+ }
7427
+ #endif
7428
+
7418
7429
inline bool ClientImpl::send_ (Request &req, Response &res, Error &error) {
7419
7430
{
7420
7431
std::lock_guard<std::mutex> guard (socket_mutex_);
@@ -7426,6 +7437,15 @@ inline bool ClientImpl::send_(Request &req, Response &res, Error &error) {
7426
7437
auto is_alive = false ;
7427
7438
if (socket_.is_open ()) {
7428
7439
is_alive = detail::is_socket_alive (socket_.sock );
7440
+
7441
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
7442
+ if (is_alive && is_ssl ()) {
7443
+ if (is_ssl_peer_could_be_closed (socket_.ssl )) {
7444
+ is_alive = false ;
7445
+ }
7446
+ }
7447
+ #endif
7448
+
7429
7449
if (!is_alive) {
7430
7450
// Attempt to avoid sigpipe by shutting down nongracefully if it seems
7431
7451
// like the other side has already closed the connection Also, there
@@ -7922,9 +7942,7 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
7922
7942
if (is_ssl ()) {
7923
7943
auto is_proxy_enabled = !proxy_host_.empty () && proxy_port_ != -1 ;
7924
7944
if (!is_proxy_enabled) {
7925
- char buf[1 ];
7926
- if (SSL_peek (socket_.ssl , buf, 1 ) == 0 &&
7927
- SSL_get_error (socket_.ssl , 0 ) == SSL_ERROR_ZERO_RETURN) {
7945
+ if (is_ssl_peer_could_be_closed (socket_.ssl )) {
7928
7946
error = Error::SSLPeerCouldBeClosed_;
7929
7947
return false ;
7930
7948
}
0 commit comments