From 88569844ea79bf352a845a6c5d09f176ef3ab133 Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 16 Aug 2022 10:58:59 +0200 Subject: [PATCH] Improved SSL_R_SHORT_READ check --- client_http.hpp | 11 +++++++---- client_https.hpp | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index 06ef9ae..e12fcd2 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -670,15 +670,18 @@ namespace SimpleWeb { }); } + /// Ignore end of file error codes + virtual error_code clean_error_code(const error_code &ec) { + return ec == error::eof ? error_code() : ec; + } + void read_content(const std::shared_ptr &session) { asio::async_read(*session->connection->socket, session->response->streambuf, [this, session](const error_code &ec_, std::size_t /*bytes_transferred*/) { auto lock = session->connection->handler_runner->continue_lock(); if(!lock) return; -# define SSL_R_SHORT_READ 219 - auto ec = ec_ == error::eof ? error_code() : ec_; - if((ec.value() & 0xff) == SSL_R_SHORT_READ) - ec = error_code(); + + auto ec = clean_error_code(ec_); if(!ec) { { diff --git a/client_https.hpp b/client_https.hpp index eccf0f5..9458723 100644 --- a/client_https.hpp +++ b/client_https.hpp @@ -57,6 +57,11 @@ namespace SimpleWeb { protected: asio::ssl::context context; + /// Ignore for end of file and SSL_R_SHORT_READ error codes + error_code clean_error_code(const error_code &ec) override { + return ec == error::eof || ec == asio::ssl::error::stream_truncated ? error_code() : ec; + } + std::shared_ptr create_connection() noexcept override { return std::make_shared(handler_runner, *io_service, context); }