mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
fix #112
This commit is contained in:
parent
86b3dfc480
commit
d0090b158f
1 changed files with 26 additions and 2 deletions
28
httplib.h
28
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<Response> 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
|
||||
|
|
Loading…
Reference in a new issue