extract a new class SslClient

This commit is contained in:
Chunting Gu
2021-06-23 10:03:11 +08:00
parent 326a3ea215
commit d294cda3c1
13 changed files with 410 additions and 281 deletions
+9 -16
View File
@@ -15,21 +15,18 @@
#include "webcc/request.h"
#include "webcc/response.h"
#include "webcc/response_parser.h"
#include "webcc/socket.h"
#include "webcc/socket_base.h"
namespace webcc {
class Client;
using ClientPtr = std::shared_ptr<Client>;
// Synchronous HTTP & HTTPS client.
// A request won't return until the response is received or timeout occurs.
class Client {
public:
// TODO
#if WEBCC_ENABLE_SSL
Client(boost::asio::io_context& io_context,
boost::asio::ssl::context& ssl_context);
#else
explicit Client(boost::asio::io_context& io_context);
#endif
Client(const Client&) = delete;
Client& operator=(const Client&) = delete;
@@ -84,10 +81,12 @@ public:
response_parser_.Init(nullptr, false);
}
private:
protected:
void DoClose();
void AsyncConnect();
// TODO: Rename
// TODO: Add class ClientBase ?
virtual void AsyncConnect();
void AsyncResolve(string_view default_port);
@@ -113,13 +112,9 @@ private:
void FinishRequest();
private:
protected:
boost::asio::io_context& io_context_;
#if WEBCC_ENABLE_SSL
boost::asio::ssl::context& ssl_context_;
#endif
std::unique_ptr<SocketBase> socket_;
boost::asio::ip::tcp::resolver resolver_;
@@ -164,8 +159,6 @@ private:
Error error_;
};
using ClientPtr = std::shared_ptr<Client>;
} // namespace webcc
#endif // WEBCC_CLIENT_H_