added Support for NO_BOOST
This commit is contained in:
parent
3f8fcc0c31
commit
d50bcabf8e
6 changed files with 256 additions and 157 deletions
|
|
@ -2,12 +2,16 @@
|
|||
#define SERVER_HTTPS_HPP
|
||||
|
||||
#include "server_http.hpp"
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#ifdef NO_BOOST
|
||||
# include <asio/ssl.hpp>
|
||||
#else
|
||||
# include <boost/asio/ssl.hpp>
|
||||
#endif
|
||||
#include <openssl/ssl.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace SimpleWeb {
|
||||
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> HTTPS;
|
||||
typedef asio_ns::ssl::stream<asio_ns::ip::tcp::socket> HTTPS;
|
||||
|
||||
template<>
|
||||
class Server<HTTPS> : public ServerBase<HTTPS> {
|
||||
|
|
@ -25,14 +29,14 @@ namespace SimpleWeb {
|
|||
}
|
||||
|
||||
Server(const std::string& cert_file, const std::string& private_key_file, const std::string& verify_file=std::string()):
|
||||
ServerBase<HTTPS>::ServerBase(443), context(boost::asio::ssl::context::tlsv12) {
|
||||
ServerBase<HTTPS>::ServerBase(443), context(asio_ns::ssl::context::tlsv12) {
|
||||
context.use_certificate_chain_file(cert_file);
|
||||
context.use_private_key_file(private_key_file, boost::asio::ssl::context::pem);
|
||||
context.use_private_key_file(private_key_file, asio_ns::ssl::context::pem);
|
||||
|
||||
if(verify_file.size()>0) {
|
||||
context.load_verify_file(verify_file);
|
||||
context.set_verify_mode(boost::asio::ssl::verify_peer | boost::asio::ssl::verify_fail_if_no_peer_cert |
|
||||
boost::asio::ssl::verify_client_once);
|
||||
context.set_verify_mode(asio_ns::ssl::verify_peer | asio_ns::ssl::verify_fail_if_no_peer_cert |
|
||||
asio_ns::ssl::verify_client_once);
|
||||
set_session_id_context=true;
|
||||
}
|
||||
}
|
||||
|
|
@ -49,27 +53,27 @@ namespace SimpleWeb {
|
|||
}
|
||||
|
||||
protected:
|
||||
boost::asio::ssl::context context;
|
||||
asio_ns::ssl::context context;
|
||||
|
||||
void accept() {
|
||||
//Create new socket for this connection
|
||||
//Shared_ptr is used to pass temporary objects to the asynchronous functions
|
||||
auto socket=std::make_shared<HTTPS>(*io_service, context);
|
||||
|
||||
acceptor->async_accept((*socket).lowest_layer(), [this, socket](const boost::system::error_code& ec) {
|
||||
acceptor->async_accept((*socket).lowest_layer(), [this, socket](const error_ns::error_code& ec) {
|
||||
//Immediately start accepting a new connection (if io_service hasn't been stopped)
|
||||
if (ec != boost::asio::error::operation_aborted)
|
||||
if (ec != asio_ns::error::operation_aborted)
|
||||
accept();
|
||||
|
||||
|
||||
if(!ec) {
|
||||
boost::asio::ip::tcp::no_delay option(true);
|
||||
asio_ns::ip::tcp::no_delay option(true);
|
||||
socket->lowest_layer().set_option(option);
|
||||
|
||||
//Set timeout on the following boost::asio::ssl::stream::async_handshake
|
||||
//Set timeout on the following asio_ns::ssl::stream::async_handshake
|
||||
auto timer=get_timeout_timer(socket, config.timeout_request);
|
||||
socket->async_handshake(boost::asio::ssl::stream_base::server, [this, socket, timer]
|
||||
(const boost::system::error_code& ec) {
|
||||
socket->async_handshake(asio_ns::ssl::stream_base::server, [this, socket, timer]
|
||||
(const error_ns::error_code& ec) {
|
||||
if(timer)
|
||||
timer->cancel();
|
||||
if(!ec)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue