From d0090b158f4d5da571271c4b04252b3b8aef0155 Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 13 Dec 2018 19:37:44 -0500 Subject: [PATCH] fix #112 --- httplib.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/httplib.h b/httplib.h index 878f16d..7d4c7a0 100644 --- a/httplib.h +++ b/httplib.h @@ -320,6 +320,7 @@ private: void write_request(Stream& strm, Request& req); virtual bool read_and_close_socket(socket_t sock, Request& req, Response& res); + virtual bool is_ssl() const; }; #ifdef CPPHTTPLIB_OPENSSL_SUPPORT @@ -358,7 +359,7 @@ class SSLClient : public Client { public: SSLClient( const char* host, - int port = 80, + int port = 443, time_t timeout_sec = 300); virtual ~SSLClient(); @@ -367,6 +368,7 @@ public: private: virtual bool read_and_close_socket(socket_t sock, Request& req, Response& res); + virtual bool is_ssl() const; SSL_CTX* ctx_; std::mutex ctx_mutex_; @@ -2036,7 +2038,19 @@ inline void Client::write_request(Stream& strm, Request& req) path.c_str()); // Headers - req.set_header("Host", host_and_port_.c_str()); + if (is_ssl()) { + if (port_ == 443) { + req.set_header("Host", host_.c_str()); + } else { + req.set_header("Host", host_and_port_.c_str()); + } + } else { + if (port_ == 80) { + req.set_header("Host", host_.c_str()); + } else { + req.set_header("Host", host_and_port_.c_str()); + } + } if (!req.has_header("Accept")) { req.set_header("Accept", "*/*"); @@ -2118,6 +2132,11 @@ inline bool Client::read_and_close_socket(socket_t sock, Request& req, Response& }); } +inline bool Client::is_ssl() const +{ + return false; +} + inline std::shared_ptr Client::Get(const char* path, Progress progress) { return Get(path, Headers(), progress); @@ -2441,6 +2460,11 @@ inline bool SSLClient::read_and_close_socket(socket_t sock, Request& req, Respon return process_request(strm, req, res, connection_close); }); } + +inline bool SSLClient::is_ssl() const +{ + return true; +} #endif } // namespace httplib