@@ -854,6 +854,9 @@ enum class Error {
854
854
UnsupportedMultipartBoundaryChars,
855
855
Compression,
856
856
ConnectionTimeout,
857
+
858
+ // For internal use only
859
+ SSLPeerCouldBeClosed_,
857
860
};
858
861
859
862
std::string to_string (const Error error);
@@ -1126,8 +1129,6 @@ class ClientImpl {
1126
1129
bool is_open () const { return sock != INVALID_SOCKET; }
1127
1130
};
1128
1131
1129
- Result send_ (Request &&req);
1130
-
1131
1132
virtual bool create_and_connect_socket (Socket &socket, Error &error);
1132
1133
1133
1134
// All of:
@@ -1228,6 +1229,9 @@ class ClientImpl {
1228
1229
Logger logger_;
1229
1230
1230
1231
private:
1232
+ bool send_ (Request &req, Response &res, Error &error);
1233
+ Result send_ (Request &&req);
1234
+
1231
1235
socket_t create_client_socket (Error &error) const ;
1232
1236
bool read_response_line (Stream &strm, const Request &req, Response &res);
1233
1237
bool write_request (Stream &strm, Request &req, bool close_connection,
@@ -6278,7 +6282,15 @@ inline bool ClientImpl::read_response_line(Stream &strm, const Request &req,
6278
6282
6279
6283
inline bool ClientImpl::send (Request &req, Response &res, Error &error) {
6280
6284
std::lock_guard<std::recursive_mutex> request_mutex_guard (request_mutex_);
6285
+ auto ret = send_ (req, res, error);
6286
+ if (error == Error::SSLPeerCouldBeClosed_) {
6287
+ assert (!ret);
6288
+ ret = send_ (req, res, error);
6289
+ }
6290
+ return ret;
6291
+ }
6281
6292
6293
+ inline bool ClientImpl::send_ (Request &req, Response &res, Error &error) {
6282
6294
{
6283
6295
std::lock_guard<std::mutex> guard (socket_mutex_);
6284
6296
@@ -6289,13 +6301,6 @@ inline bool ClientImpl::send(Request &req, Response &res, Error &error) {
6289
6301
auto is_alive = false ;
6290
6302
if (socket_.is_open ()) {
6291
6303
is_alive = detail::is_socket_alive (socket_.sock );
6292
- #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
6293
- if (is_ssl () && is_alive) {
6294
- char buf[1 ];
6295
- auto n = SSL_peek (socket_.ssl , buf, 1 );
6296
- if (n <= 0 ) { is_alive = false ; }
6297
- }
6298
- #endif
6299
6304
if (!is_alive) {
6300
6305
// Attempt to avoid sigpipe by shutting down nongracefully if it seems
6301
6306
// like the other side has already closed the connection Also, there
@@ -6757,6 +6762,16 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
6757
6762
// Send request
6758
6763
if (!write_request (strm, req, close_connection, error)) { return false ; }
6759
6764
6765
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
6766
+ if (is_ssl ()) {
6767
+ char buf[1 ];
6768
+ if (SSL_peek (socket_.ssl , buf, 1 ) == 0 ) {
6769
+ error = Error::SSLPeerCouldBeClosed_;
6770
+ return false ;
6771
+ }
6772
+ }
6773
+ #endif
6774
+
6760
6775
// Receive response and headers
6761
6776
if (!read_response_line (strm, req, res) ||
6762
6777
!detail::read_headers (strm, res.headers )) {
0 commit comments