@@ -1582,6 +1582,9 @@ class ClientImpl {
15821582 bool send_ (Request &req, Response &res, Error &error);
15831583 Result send_ (Request &&req);
15841584
1585+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1586+ bool is_ssl_peer_could_be_closed (SSL *ssl) const ;
1587+ #endif
15851588 socket_t create_client_socket (Error &error) const ;
15861589 bool read_response_line (Stream &strm, const Request &req,
15871590 Response &res) const ;
@@ -7415,6 +7418,14 @@ inline bool ClientImpl::send(Request &req, Response &res, Error &error) {
74157418 return ret;
74167419}
74177420
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+
74187429inline bool ClientImpl::send_ (Request &req, Response &res, Error &error) {
74197430 {
74207431 std::lock_guard<std::mutex> guard (socket_mutex_);
@@ -7426,6 +7437,15 @@ inline bool ClientImpl::send_(Request &req, Response &res, Error &error) {
74267437 auto is_alive = false ;
74277438 if (socket_.is_open ()) {
74287439 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+
74297449 if (!is_alive) {
74307450 // Attempt to avoid sigpipe by shutting down nongracefully if it seems
74317451 // like the other side has already closed the connection Also, there
@@ -7922,9 +7942,7 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
79227942 if (is_ssl ()) {
79237943 auto is_proxy_enabled = !proxy_host_.empty () && proxy_port_ != -1 ;
79247944 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 )) {
79287946 error = Error::SSLPeerCouldBeClosed_;
79297947 return false ;
79307948 }
0 commit comments