/*
* COPYRIGHT (C) 2017-2021, zhllxt
*
* author : zhllxt
* email : 37792738@qq.com
*
* Distributed under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
* (See accompanying file LICENSE or see )
*/
#if defined(ASIO2_USE_SSL)
#ifndef __ASIO2_HTTPS_SERVER_HPP__
#define __ASIO2_HTTPS_SERVER_HPP__
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include
#include
#include
namespace asio2::detail
{
ASIO2_CLASS_FORWARD_DECLARE_BASE;
ASIO2_CLASS_FORWARD_DECLARE_TCP_BASE;
ASIO2_CLASS_FORWARD_DECLARE_TCP_SERVER;
template
class https_server_impl_t
: public tcps_server_impl_t
, public http_router_t
{
ASIO2_CLASS_FRIEND_DECLARE_BASE;
ASIO2_CLASS_FRIEND_DECLARE_TCP_BASE;
ASIO2_CLASS_FRIEND_DECLARE_TCP_SERVER;
public:
using super = tcps_server_impl_t ;
using self = https_server_impl_t;
using session_type = session_t;
public:
/**
* @constructor
*/
template
explicit https_server_impl_t(
asio::ssl::context::method method = asio::ssl::context::sslv23,
Args&&... args
)
: super(method, std::forward(args)...)
{
}
/**
* @destructor
*/
~https_server_impl_t()
{
this->stop();
}
/**
* @function : start the server
* @param host A string identifying a location. May be a descriptive name or
* a numeric address string.
* @param service A string identifying the requested service. This may be a
* descriptive name or a numeric string corresponding to a port number.
*/
template
inline bool start(String&& host, StrOrInt&& service, Args&&... args)
{
return this->derived()._do_start(std::forward(host), std::forward(service),
condition_helper::make_condition('0', std::forward(args)...));
}
public:
/**
* @function : bind recv listener
* @param : fun - a user defined callback function
* Function signature : void(std::shared_ptr& session_ptr,
* http::request& req, http::response& rep)
* or : void(http::request& req, http::response& rep)
*/
template
inline derived_t & bind_recv(F&& fun, C&&... obj)
{
if constexpr (is_template_callable_v&, http::request&, http::response&>)
{
this->is_arg0_session_ = true;
this->listener_.bind(event_type::recv, observer_t&,
http::request&, http::response&>(std::forward(fun), std::forward(obj)...));
}
else
{
this->is_arg0_session_ = false;
this->listener_.bind(event_type::recv, observer_t<
http::request&, http::response&>(std::forward(fun), std::forward(obj)...));
}
return (this->derived());
}
/**
* @function : bind websocket upgrade listener
* @param : fun - a user defined callback function
* Function signature : void(std::shared_ptr& session_ptr, asio::error_code ec)
*/
template
inline derived_t & bind_upgrade(F&& fun, C&&... obj)
{
this->listener_.bind(event_type::upgrade, observer_t&, error_code>
(std::forward(fun), std::forward(obj)...));
return (this->derived());
}
protected:
template
inline std::shared_ptr _make_session(Args&&... args)
{
return super::_make_session(std::forward(args)..., *this,
this->root_directory_, this->is_arg0_session_, this->support_websocket_);
}
protected:
bool is_arg0_session_ = false;
};
}
namespace asio2
{
template
class https_server_t : public detail::https_server_impl_t, session_t>
{
public:
using detail::https_server_impl_t, session_t>::https_server_impl_t;
};
using https_server = https_server_t;
}
#include
#endif // !__ASIO2_HTTPS_SERVER_HPP__
#endif