Add a config option allowing to disable SSL.

This commit is contained in:
Chunting Gu
2019-04-15 10:07:04 +08:00
parent d9509bda4a
commit 5e1b14e74d
7 changed files with 65 additions and 28 deletions
+4 -1
View File
@@ -3,7 +3,7 @@
// Compile configurations.
// Set 0 to disable logging.
// Set 1/0 to enable/disable logging.
#define WEBCC_ENABLE_LOG 1
#if WEBCC_ENABLE_LOG
@@ -11,4 +11,7 @@
#define WEBCC_LOG_LEVEL 2
#endif
// Set 1/0 to enable/disable SSL/HTTPS.
#define WEBCC_ENABLE_SSL 1
#endif // WEBCC_CONFIG_H_
+7
View File
@@ -2,11 +2,18 @@
#define WEBCC_CONFIG_H_
// Compile configurations.
// This file is auto-generated by CMake during configuration
// from config.h.in.
// Set 1/0 to enable/disable logging.
#define WEBCC_ENABLE_LOG @WEBCC_ENABLE_LOG@
#if WEBCC_ENABLE_LOG
// 0:VERB, 1:INFO, 2:WARN, 3:ERRO or 4:FATA
#define WEBCC_LOG_LEVEL @WEBCC_LOG_LEVEL@
#endif
// Set 1/0 to enable/disable SSL/HTTPS.
#define WEBCC_ENABLE_SSL @WEBCC_ENABLE_SSL@
#endif // WEBCC_CONFIG_H_
+5
View File
@@ -73,8 +73,13 @@ void HttpClient::Close() {
Error HttpClient::Connect(HttpRequestPtr request) {
if (request->url().scheme() == "https") {
#if WEBCC_ENABLE_SSL
socket_.reset(new HttpSslSocket{ io_context_, ssl_verify_ });
return DoConnect(request, kPort443);
#else
LOG_ERRO("SSL/HTTPS support is not enabled.");
return kSchemaError;
#endif // WEBCC_ENABLE_SSL
} else {
socket_.reset(new HttpSocket{ io_context_ });
return DoConnect(request, kPort80);
+6 -2
View File
@@ -6,8 +6,6 @@
#include "webcc/logger.h"
namespace ssl = boost::asio::ssl;
namespace webcc {
// -----------------------------------------------------------------------------
@@ -37,6 +35,10 @@ void HttpSocket::Close(boost::system::error_code* ec) {
// -----------------------------------------------------------------------------
#if WEBCC_ENABLE_SSL
namespace ssl = boost::asio::ssl;
HttpSslSocket::HttpSslSocket(boost::asio::io_context& io_context,
bool ssl_verify)
: ssl_context_(ssl::context::sslv23),
@@ -89,4 +91,6 @@ void HttpSslSocket::Handshake(const std::string& host,
}
}
#endif // WEBCC_ENABLE_SSL
} // namespace webcc
+9 -1
View File
@@ -4,10 +4,14 @@
#include <vector>
#include "boost/asio/ip/tcp.hpp"
#include "boost/asio/ssl.hpp"
#include "webcc/config.h"
#include "webcc/http_request.h"
#if WEBCC_ENABLE_SSL
#include "boost/asio/ssl.hpp"
#endif // WEBCC_ENABLE_SSL
namespace webcc {
// -----------------------------------------------------------------------------
@@ -58,6 +62,8 @@ private:
// -----------------------------------------------------------------------------
#if WEBCC_ENABLE_SSL
class HttpSslSocket : public HttpSocketBase {
public:
explicit HttpSslSocket(boost::asio::io_context& io_context,
@@ -85,6 +91,8 @@ private:
bool ssl_verify_;
};
#endif // WEBCC_ENABLE_SSL
} // namespace webcc
#endif // WEBCC_HTTP_SOCKET_H_