From 1ebb8412c594a091750f1b614d6aae3964c0db44 Mon Sep 17 00:00:00 2001
From: yhirose <yuji.hirose.bug@gmail.com>
Date: Tue, 7 Mar 2023 08:15:16 -0500
Subject: [PATCH] Use SSL_ERROR_ZERO_RETURN to check if the SSL peer is closed.

---
 httplib.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/httplib.h b/httplib.h
index 2317276..699c1fb 100644
--- a/httplib.h
+++ b/httplib.h
@@ -6765,7 +6765,8 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
   if (is_ssl()) {
     char buf[1];
-    if (SSL_peek(socket_.ssl, buf, 1) == 0) {
+    if (SSL_peek(socket_.ssl, buf, 1) == 0 &&
+        SSL_get_error(socket_.ssl, 0) == SSL_ERROR_ZERO_RETURN) {
       error = Error::SSLPeerCouldBeClosed_;
       return false;
     }