aboutsummaryrefslogtreecommitdiffstats
path: root/include/http_server.h
diff options
context:
space:
mode:
authorJaeseung Ha <ipknhama@gmail.com>2015-09-20 22:06:00 +0900
committerJaeseung Ha <ipknhama@gmail.com>2015-09-20 22:06:00 +0900
commite4708671bcfd2514edaa1a8e0bd5fa58f00c5fd1 (patch)
treeb47fc83d73c9b6031f75e576e8e633b93eee8901 /include/http_server.h
parent5282c9d4aae7ae1450a76fa29ddf837c8eb2f56d (diff)
downloadcrow-e4708671bcfd2514edaa1a8e0bd5fa58f00c5fd1.tar.gz
crow-e4708671bcfd2514edaa1a8e0bd5fa58f00c5fd1.zip
implement HTTPS support
- define CROW_ENABLE_SSL to use - close #88
Diffstat (limited to 'include/http_server.h')
-rw-r--r--include/http_server.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/include/http_server.h b/include/http_server.h
index 143b58d..80ef7a4 100644
--- a/include/http_server.h
+++ b/include/http_server.h
@@ -2,6 +2,9 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/asio.hpp>
+#ifdef CROW_ENABLE_SSL
+#include <boost/asio/ssl.hpp>
+#endif
#include <cstdint>
#include <atomic>
#include <future>
@@ -18,17 +21,18 @@ namespace crow
using namespace boost;
using tcp = asio::ip::tcp;
- template <typename Handler, typename ... Middlewares>
+ template <typename Handler, typename Adaptor = SocketAdaptor, typename ... Middlewares>
class Server
{
public:
- Server(Handler* handler, uint16_t port, std::tuple<Middlewares...>* middlewares = nullptr, uint16_t concurrency = 1)
+ Server(Handler* handler, uint16_t port, std::tuple<Middlewares...>* middlewares = nullptr, uint16_t concurrency = 1, typename Adaptor::context* adaptor_ctx = nullptr)
: acceptor_(io_service_, tcp::endpoint(asio::ip::address(), port)),
signals_(io_service_, SIGINT, SIGTERM),
handler_(handler),
concurrency_(concurrency),
port_(port),
- middlewares_(middlewares)
+ middlewares_(middlewares),
+ adaptor_ctx_(adaptor_ctx)
{
}
@@ -137,10 +141,10 @@ namespace crow
void do_accept()
{
asio::io_service& is = pick_io_service();
- auto p = new Connection<Handler, Middlewares...>(
+ auto p = new Connection<Adaptor, Handler, Middlewares...>(
is, handler_, server_name_, middlewares_,
- get_cached_date_str_pool_[roundrobin_index_], *timer_queue_pool_[roundrobin_index_]
- );
+ get_cached_date_str_pool_[roundrobin_index_], *timer_queue_pool_[roundrobin_index_],
+ adaptor_ctx_);
acceptor_.async_accept(p->socket(),
[this, p, &is](boost::system::error_code ec)
{
@@ -170,5 +174,11 @@ namespace crow
unsigned int roundrobin_index_{};
std::tuple<Middlewares...>* middlewares_;
+
+#ifdef CROW_ENABLE_SSL
+ bool use_ssl_{false};
+ boost::asio::ssl::context ssl_context_{boost::asio::ssl::context::sslv23};
+#endif
+ typename Adaptor::context* adaptor_ctx_;
};
}