settings.hpp
Go to the documentation of this file.
/*
restinio
*/
#pragma once
#include <restinio/asio_include.hpp>
#include <restinio/exception.hpp>
#include <restinio/request_handler.hpp>
#include <restinio/traits.hpp>
#include <restinio/incoming_http_msg_limits.hpp>
#include <restinio/variant.hpp>
#include <chrono>
#include <tuple>
#include <utility>
namespace restinio
{
namespace details
{
template < typename Object >
inline auto
create_default_unique_object_instance( std::false_type )
{
return std::unique_ptr< Object >{};
}
template < typename Object >
inline auto
create_default_unique_object_instance( std::true_type )
{
return std::make_unique< Object >();
}
template < typename Object >
inline auto
create_default_shared_object_instance( std::false_type )
{
return std::shared_ptr< Object >{};
}
template < typename Object >
inline auto
create_default_shared_object_instance( std::true_type )
{
return std::make_shared< Object >();
}
} /* namespace details */
//
// create_default_unique_object_instance
//
template < typename Object>
inline auto
create_default_unique_object_instance()
{
typename std::is_default_constructible< Object >::type tag;
return details::create_default_unique_object_instance< Object >( tag );
}
template <>
inline auto
create_default_unique_object_instance< default_request_handler_t >()
{
return details::create_default_unique_object_instance< default_request_handler_t >(
std::false_type{} );
}
//
// create_default_shared_object_instance
//
template < typename Object>
inline auto
create_default_shared_object_instance()
{
typename std::is_default_constructible< Object >::type tag;
return details::create_default_shared_object_instance< Object >( tag );
}
template <>
inline auto
create_default_shared_object_instance< default_request_handler_t >()
{
return details::create_default_shared_object_instance< default_request_handler_t >(
std::false_type{} );
}
//
// ensure_created()
//
template < typename Object >
auto
ensure_created(
std::unique_ptr< Object > mb_created_one,
string_view_t fail_description )
{
if( !mb_created_one )
mb_created_one = create_default_unique_object_instance< Object >();
if( !mb_created_one )
throw exception_t{ fail_description };
return mb_created_one;
}
//
// unsure_created()
//
template < typename Object >
auto
ensure_created(
std::shared_ptr< Object > mb_created_one,
string_view_t fail_description )
{
if( !mb_created_one )
mb_created_one = create_default_shared_object_instance< Object >();
if( !mb_created_one )
throw exception_t{ fail_description };
return mb_created_one;
}
//
// socket_type_dependent_settings_t
//
template < typename Settings, typename Socket >
class socket_type_dependent_settings_t
{
protected :
~socket_type_dependent_settings_t() noexcept = default;
public :
socket_type_dependent_settings_t() noexcept = default;
socket_type_dependent_settings_t(const socket_type_dependent_settings_t &) noexcept = default;
socket_type_dependent_settings_t(socket_type_dependent_settings_t &&) noexcept = default;
socket_type_dependent_settings_t &
operator=(const socket_type_dependent_settings_t &) noexcept = default;
socket_type_dependent_settings_t &
operator=(socket_type_dependent_settings_t &&) noexcept = delete;
// No extra settings by default.
};
//
// acceptor_options_t
//
class acceptor_options_t
{
public:
acceptor_options_t( asio_ns::ip::tcp::acceptor & acceptor )
: m_acceptor{ acceptor }
{}
template< typename Option >
void
set_option( const Option & option )
{
m_acceptor.set_option( option );
}
template< typename Option >
void
set_option( const Option & option, asio_ns::error_code & ec )
{
m_acceptor.set_option( option, ec );
}
template< typename Option >
void
get_option( Option & option )
{
m_acceptor.get_option( option );
}
template< typename Option >
void
get_option( Option & option, asio_ns::error_code & ec )
{
m_acceptor.get_option( option, ec );
}
private:
asio_ns::ip::tcp::acceptor & m_acceptor;
};
using acceptor_options_setter_t = std::function< void ( acceptor_options_t & ) >;
template <>
inline auto
create_default_unique_object_instance< acceptor_options_setter_t >()
{
return std::make_unique< acceptor_options_setter_t >(
[]( acceptor_options_t & options ){
options.set_option( asio_ns::ip::tcp::acceptor::reuse_address( true ) );
} );
}
//
// socket_options_t
//
class socket_options_t
{
public:
socket_options_t(
asio_ns::basic_socket< asio_ns::ip::tcp > & socket )
: m_socket{ socket }
{}
template< typename Option >
void
set_option( const Option & option )
{
m_socket.set_option( option );
}
template< typename Option >
void
set_option( const Option & option, asio_ns::error_code & ec )
{
m_socket.set_option( option, ec );
}
template< typename Option >
void
get_option( Option & option )
{
m_socket.get_option( option );
}
template< typename Option >
void
get_option( Option & option, asio_ns::error_code & ec )
{
m_socket.get_option( option, ec );
}
private:
asio_ns::basic_socket< asio_ns::ip::tcp > & m_socket;
};
using socket_options_setter_t = std::function< void ( socket_options_t & ) >;
template <>
inline auto
create_default_unique_object_instance< socket_options_setter_t >()
{
return std::make_unique< socket_options_setter_t >( []( auto & ){} );
}
//
// cleanup_functor_t
//
using cleanup_functor_t = std::function< void(void) >;
//
// connection_state_listener_holder_t
//
template< typename Listener >
struct connection_state_listener_holder_t
{
std::shared_ptr< Listener > m_connection_state_listener;
static constexpr bool has_actual_connection_state_listener = true;
void
check_valid_connection_state_listener_pointer() const
{
if( !m_connection_state_listener )
throw exception_t{ "connection state listener is not specified" };
}
};
template<>
struct connection_state_listener_holder_t< connection_state::noop_listener_t >
{
static constexpr bool has_actual_connection_state_listener = false;
void
check_valid_connection_state_listener_pointer() const
{
// Nothing to do.
}
};
//
// ip_blocker_holder_t
//
template< typename Ip_Blocker >
struct ip_blocker_holder_t
{
static_assert(
noexcept( std::declval<Ip_Blocker>().inspect(
std::declval<ip_blocker::incoming_info_t>() ) ),
"Ip_Blocker::inspect() method should be noexcept" );
static_assert(
std::is_same<
restinio::ip_blocker::inspection_result_t,
decltype(std::declval<Ip_Blocker>().inspect(
std::declval<ip_blocker::incoming_info_t>())) >::value,
"Ip_Blocker::inspect() should return "
"restinio::ip_blocker::inspection_result_t" );
std::shared_ptr< Ip_Blocker > m_ip_blocker;
static constexpr bool has_actual_ip_blocker = true;
void
check_valid_ip_blocker_pointer() const
{
if( !m_ip_blocker )
throw exception_t{ "IP-blocker is not specified" };
}
};
template<>
struct ip_blocker_holder_t< ip_blocker::noop_ip_blocker_t >
{
static constexpr bool has_actual_ip_blocker = false;
void
check_valid_ip_blocker_pointer() const
{
// Nothing to do.
}
};
//
// acceptor_post_bind_hook_t
//
using acceptor_post_bind_hook_t = std::function<
void(asio_ns::ip::tcp::acceptor &) >;
namespace details
{
//
// no_address_specified_t
//
struct no_address_specified_t {};
//
// address_variant_t
//
using address_variant_t = variant_t<
no_address_specified_t,
std::string,
asio_ns::ip::address >;
//
// max_parallel_connections_holder_t
//
template< typename Count_Limiter >
struct max_parallel_connections_holder_t
{
static constexpr bool has_actual_max_parallel_connections = true;
std::size_t m_max_parallel_connections{
std::numeric_limits<std::size_t>::max()
};
std::size_t
max_parallel_connections() const noexcept
{
return m_max_parallel_connections;
}
void
set_max_parallel_connections( std::size_t v ) noexcept
{
m_max_parallel_connections = v;
}
};
template<>
struct max_parallel_connections_holder_t<
::restinio::connection_count_limits::noop_connection_count_limiter_t >
{
static constexpr bool has_actual_max_parallel_connections = false;
std::size_t
max_parallel_connections() const noexcept
{
return std::numeric_limits<std::size_t>::max();
}
};
} /* namespace details */
//
// basic_server_settings_t
//
template<typename Derived, typename Traits>
class basic_server_settings_t
: public socket_type_dependent_settings_t< Derived, typename Traits::stream_socket_t >
, protected connection_state_listener_holder_t<
typename Traits::connection_state_listener_t >
, protected ip_blocker_holder_t< typename Traits::ip_blocker_t >
, protected details::max_parallel_connections_holder_t<
typename connection_count_limit_types<Traits>::limiter_t >
{
using base_type_t = socket_type_dependent_settings_t<
Derived, typename Traits::stream_socket_t>;
using max_parallel_connections_holder_base_t =
details::max_parallel_connections_holder_t<
typename connection_count_limit_types<Traits>::limiter_t >;
using connection_state_listener_holder_t<
typename Traits::connection_state_listener_t
>::has_actual_connection_state_listener;
using ip_blocker_holder_t<
typename Traits::ip_blocker_t
>::has_actual_ip_blocker;
using max_parallel_connections_holder_base_t::has_actual_max_parallel_connections;
public:
basic_server_settings_t(
std::uint16_t port = 8080,
asio_ns::ip::tcp protocol = asio_ns::ip::tcp::v4() )
: base_type_t{}
, m_port{ port }
, m_protocol{ protocol }
{}
Derived &
port( std::uint16_t p ) &
{
m_port = p;
return reference_to_derived();
}
Derived &&
port( std::uint16_t p ) &&
{
return std::move( this->port( p ) );
}
RESTINIO_NODISCARD
std::uint16_t
port() const
{
return m_port;
}
Derived &
protocol( asio_ns::ip::tcp p ) &
{
m_protocol = p;
return reference_to_derived();
}
Derived &&
protocol( asio_ns::ip::tcp p ) &&
{
return std::move( this->protocol( p ) );
}
RESTINIO_NODISCARD
asio_ns::ip::tcp
protocol() const
{
return m_protocol;
}
Derived &
address( std::string addr ) &
{
m_address = std::move(addr);
return reference_to_derived();
}
Derived &&
address( std::string addr ) &&
{
return std::move( this->address( std::move( addr ) ) );
}
Derived &
address( asio_ns::ip::address addr ) &
{
m_address = addr;
return reference_to_derived();
}
Derived &&
address( asio_ns::ip::address addr ) &&
{
return std::move( this->address( addr ) );
}
RESTINIO_NODISCARD
const details::address_variant_t &
address() const
{
return m_address;
}
Derived &
buffer_size( std::size_t s ) &
{
m_buffer_size = s;
return reference_to_derived();
}
Derived &&
buffer_size( std::size_t s ) &&
{
return std::move( this->buffer_size( s ) );
}
std::size_t
buffer_size() const
{
return m_buffer_size;
}
Derived &
read_next_http_message_timelimit( std::chrono::steady_clock::duration d ) &
{
m_read_next_http_message_timelimit = std::move( d );
return reference_to_derived();
}
Derived &&
read_next_http_message_timelimit( std::chrono::steady_clock::duration d ) &&
{
return std::move( this->read_next_http_message_timelimit( std::move( d ) ) );
}
std::chrono::steady_clock::duration
read_next_http_message_timelimit() const
{
return m_read_next_http_message_timelimit;
}
Derived &
write_http_response_timelimit( std::chrono::steady_clock::duration d ) &
{
m_write_http_response_timelimit = std::move( d );
return reference_to_derived();
}
Derived &&
write_http_response_timelimit( std::chrono::steady_clock::duration d ) &&
{
return std::move( this->write_http_response_timelimit( std::move( d ) ) );
}
std::chrono::steady_clock::duration
write_http_response_timelimit() const
{
return m_write_http_response_timelimit;
}
Derived &
handle_request_timeout( std::chrono::steady_clock::duration d ) &
{
m_handle_request_timeout = std::move( d );
return reference_to_derived();
}
Derived &&
handle_request_timeout( std::chrono::steady_clock::duration d ) &&
{
return std::move( this->handle_request_timeout( std::move( d ) ) );
}
std::chrono::steady_clock::duration
handle_request_timeout() const
{
return m_handle_request_timeout;
}
Derived &
max_pipelined_requests( std::size_t mpr ) &
{
m_max_pipelined_requests = mpr;
return reference_to_derived();
}
Derived &&
max_pipelined_requests( std::size_t mpr ) &&
{
return std::move( this->max_pipelined_requests( mpr ) );
}
std::size_t
max_pipelined_requests() const
{
return m_max_pipelined_requests;
}
using request_handler_t = request_handler_type_from_traits_t< Traits >;
Derived &
request_handler( std::unique_ptr< request_handler_t > handler ) &
{
m_request_handler = std::move( handler );
return reference_to_derived();
}
template< typename... Params >
Derived &
request_handler( Params &&... params ) &
{
return set_unique_instance(
m_request_handler,
std::forward< Params >( params )... );
}
template< typename... Params >
Derived &&
request_handler( Params &&... params ) &&
{
return std::move( this->request_handler( std::forward< Params >( params )... ) );
}
std::unique_ptr< request_handler_t >
request_handler()
{
return ensure_created(
std::move( m_request_handler ),
"request handler must be set" );
}
using timer_manager_t = typename Traits::timer_manager_t;
using timer_factory_t = typename timer_manager_t::factory_t;
template< typename... Params >
Derived &
timer_manager( Params &&... params ) &
{
return set_unique_instance(
m_timer_factory,
std::forward< Params >( params )... );
}
template< typename... Params >
Derived &&
timer_manager( Params &&... params ) &&
{
return std::move( this->timer_manager( std::forward< Params >( params )... ) );
}
std::unique_ptr< timer_factory_t >
timer_factory()
{
return ensure_created(
std::move( m_timer_factory ),
"timer manager is not set" );
}
using logger_t = typename Traits::logger_t;
template< typename... Params >
Derived &
logger( Params &&... params ) &
{
return set_unique_instance(
m_logger,
std::forward< Params >( params )... );
}
template< typename... Params >
Derived &&
logger( Params &&... params ) &&
{
return std::move( this->logger( std::forward< Params >( params )... ) );
}
std::unique_ptr< logger_t >
logger()
{
return ensure_created(
std::move( m_logger ),
"logger must be set" );
}
Derived &
acceptor_options_setter( acceptor_options_setter_t aos ) &
{
if( !aos )
throw exception_t{ "acceptor options setter cannot be empty" };
return set_unique_instance(
m_acceptor_options_setter,
std::move( aos ) );
}
Derived &&
acceptor_options_setter( acceptor_options_setter_t aos ) &&
{
return std::move( this->acceptor_options_setter( std::move( aos ) ) );
}
std::unique_ptr< acceptor_options_setter_t >
acceptor_options_setter()
{
return ensure_created(
std::move( m_acceptor_options_setter ),
"acceptor options setter must be set" );
}
Derived &
socket_options_setter( socket_options_setter_t sos ) &
{
if( !sos )
throw exception_t{ "socket options setter cannot be empty" };
return set_unique_instance(
m_socket_options_setter,
std::move( sos ) );
}
Derived &&
socket_options_setter( socket_options_setter_t sos ) &&
{
return std::move( this->socket_options_setter( std::move( sos ) ) );
}
std::unique_ptr< socket_options_setter_t >
socket_options_setter()
{
return ensure_created(
std::move( m_socket_options_setter ),
"socket options setter must be set" );
}
Derived &
concurrent_accepts_count( std::size_t n ) &
{
if( 0 == n || 1024 < n )
throw exception_t{
fmt::format(
"invalid value for number of cuncurrent connects: {}",
n ) };
m_concurrent_accepts_count = n;
return reference_to_derived();
}
Derived &&
concurrent_accepts_count( std::size_t n ) &&
{
return std::move( this->concurrent_accepts_count( n ) );
}
std::size_t
concurrent_accepts_count() const
{
return m_concurrent_accepts_count;
}
Derived &
separate_accept_and_create_connect( bool do_separate ) & noexcept
{
m_separate_accept_and_create_connect = do_separate;
return reference_to_derived();
}
Derived &&
separate_accept_and_create_connect( bool do_separate ) && noexcept
{
return std::move( this->separate_accept_and_create_connect( do_separate ) );
}
bool
separate_accept_and_create_connect() const noexcept
{
return m_separate_accept_and_create_connect;
}
template< typename Func >
Derived &
cleanup_func( Func && func ) &
{
m_cleanup_functor = std::move(func);
return reference_to_derived();
}
template< typename Func >
Derived &&
cleanup_func( Func && func ) &&
{
return std::move(this->cleanup_func( std::forward<Func>(func) ));
}
RESTINIO_NODISCARD
cleanup_functor_t
giveaway_cleanup_func()
{
return std::move(m_cleanup_functor);
}
Derived &
connection_state_listener(
std::shared_ptr< typename Traits::connection_state_listener_t > listener ) &
{
static_assert(
has_actual_connection_state_listener,
"connection_state_listener(listener) can't be used "
"for the default connection_state::noop_listener_t" );
this->m_connection_state_listener = std::move(listener);
return reference_to_derived();
}
Derived &&
connection_state_listener(
std::shared_ptr< typename Traits::connection_state_listener_t > listener ) &&
{
return std::move(this->connection_state_listener(
std::move(listener)));
}
const std::shared_ptr< typename Traits::connection_state_listener_t > &
connection_state_listener() const noexcept
{
static_assert(
has_actual_connection_state_listener,
"connection_state_listener() can't be used "
"for the default connection_state::noop_listener_t" );
return this->m_connection_state_listener;
}
void
ensure_valid_connection_state_listener()
{
this->check_valid_connection_state_listener_pointer();
}
Derived &
ip_blocker(
std::shared_ptr< typename Traits::ip_blocker_t > blocker ) &
{
static_assert(
basic_server_settings_t::has_actual_ip_blocker,
"ip_blocker(blocker) can't be used "
"for the default ip_blocker::noop_ip_blocker_t" );
this->m_ip_blocker = std::move(blocker);
return reference_to_derived();
}
Derived &&
ip_blocker(
std::shared_ptr< typename Traits::ip_blocker_t > blocker ) &&
{
return std::move(this->ip_blocker(std::move(blocker)));
}
const std::shared_ptr< typename Traits::ip_blocker_t > &
ip_blocker() const noexcept
{
static_assert(
basic_server_settings_t::has_actual_ip_blocker,
"ip_blocker() can't be used "
"for the default ip_blocker::noop_ip_blocker_t" );
return this->m_ip_blocker;
}
void
ensure_valid_ip_blocker()
{
this->check_valid_ip_blocker_pointer();
}
// Acceptor post-bind hook.
Derived &
acceptor_post_bind_hook( acceptor_post_bind_hook_t hook ) &
{
if( !hook )
throw exception_t{ "acceptor_post_bind_hook cannot be empty" };
m_acceptor_post_bind_hook = std::move(hook);
return reference_to_derived();
}
Derived &&
acceptor_post_bind_hook( acceptor_post_bind_hook_t hook ) &&
{
return std::move(this->acceptor_post_bind_hook( std::move(hook) ));
}
RESTINIO_NODISCARD
acceptor_post_bind_hook_t
giveaway_acceptor_post_bind_hook()
{
return std::move(m_acceptor_post_bind_hook);
}
RESTINIO_NODISCARD
const incoming_http_msg_limits_t &
incoming_http_msg_limits() const noexcept
{
return m_incoming_http_msg_limits;
}
Derived &
incoming_http_msg_limits(
const incoming_http_msg_limits_t & limits ) & noexcept
{
m_incoming_http_msg_limits = limits;
return reference_to_derived();
}
Derived &&
incoming_http_msg_limits(
const incoming_http_msg_limits_t & limits ) && noexcept
{
return std::move(this->incoming_http_msg_limits(limits));
}
Derived &
max_parallel_connections( std::size_t value ) & noexcept
{
static_assert(
basic_server_settings_t::has_actual_max_parallel_connections,
"max_parallel_connections(value) can't be used "
"for the noop_connection_count_limiter_t" );
this->set_max_parallel_connections( value );
return reference_to_derived();
}
Derived &&
max_parallel_connections( std::size_t value ) && noexcept
{
return std::move(this->max_parallel_connections( value ));
}
using max_parallel_connections_holder_base_t::max_parallel_connections;
using extra_data_factory_t = typename Traits::extra_data_factory_t;
using extra_data_factory_handle_t = std::shared_ptr< extra_data_factory_t >;
Derived &
extra_data_factory(
extra_data_factory_handle_t factory ) &
{
this->m_extra_data_factory = std::move(factory);
return reference_to_derived();
}
Derived &&
extra_data_factory(
extra_data_factory_handle_t factory ) &&
{
return std::move(this->extra_data_factory( std::move(factory) ));
}
RESTINIO_NODISCARD
extra_data_factory_handle_t
giveaway_extra_data_factory() const noexcept
{
return ensure_created(
std::move(this->m_extra_data_factory),
"extra_data_factory is not set" );
}
private:
Derived &
reference_to_derived()
{
return static_cast<Derived &>(*this);
}
template< typename Target, typename... Params >
Derived &
set_unique_instance( std::unique_ptr< Target > & t, Params &&... params )
{
t =
std::make_unique< Target >(
std::forward< Params >( params )... );
return reference_to_derived();
}
template< typename Target, typename... Params >
Derived &
set_shared_instance( std::shared_ptr< Target > & t, Params &&... params )
{
t =
std::make_shared< Target >(
std::forward< Params >( params )... );
return reference_to_derived();
}
std::uint16_t m_port;
asio_ns::ip::tcp m_protocol;
details::address_variant_t m_address;
std::size_t m_buffer_size{ 4 * 1024 };
std::chrono::steady_clock::duration
m_read_next_http_message_timelimit{ std::chrono::seconds( 60 ) };
std::chrono::steady_clock::duration
m_write_http_response_timelimit{ std::chrono::seconds( 5 ) };
std::chrono::steady_clock::duration
m_handle_request_timeout{ std::chrono::seconds( 10 ) };
std::size_t m_max_pipelined_requests{ 1 };
std::unique_ptr< request_handler_t > m_request_handler;
std::unique_ptr< timer_factory_t > m_timer_factory;
std::unique_ptr< logger_t > m_logger;
std::unique_ptr< acceptor_options_setter_t > m_acceptor_options_setter;
acceptor_post_bind_hook_t m_acceptor_post_bind_hook{
[](asio_ns::ip::tcp::acceptor &) {}
};
std::unique_ptr< socket_options_setter_t > m_socket_options_setter;
std::size_t m_concurrent_accepts_count{ 1 };
bool m_separate_accept_and_create_connect{ false };
cleanup_functor_t m_cleanup_functor;
incoming_http_msg_limits_t m_incoming_http_msg_limits;
extra_data_factory_handle_t m_extra_data_factory;
};
//
// server_settings_t
//
template<typename Traits = default_traits_t>
class server_settings_t final
: public basic_server_settings_t< server_settings_t<Traits>, Traits >
{
using base_type_t = basic_server_settings_t<
server_settings_t<Traits>, Traits>;
public:
using base_type_t::base_type_t;
};
template < typename Traits, typename Configurator >
auto
exec_configurator( Configurator && configurator )
{
server_settings_t< Traits > result;
configurator( result );
return result;
}
} /* namespace restinio */
asio_include.hpp
nonstd::variants::variant
Definition: variant.hpp:1301
restinio::acceptor_options_t
An adapter for setting acceptor options before running server.
Definition: settings.hpp:185
restinio::acceptor_options_t::set_option
void set_option(const Option &option, asio_ns::error_code &ec)
Definition: settings.hpp:202
restinio::acceptor_options_t::set_option
void set_option(const Option &option)
API for setting/getting options.
Definition: settings.hpp:195
restinio::acceptor_options_t::get_option
void get_option(Option &option, asio_ns::error_code &ec)
Definition: settings.hpp:216
restinio::acceptor_options_t::get_option
void get_option(Option &option)
Definition: settings.hpp:209
restinio::acceptor_options_t::m_acceptor
asio_ns::ip::tcp::acceptor & m_acceptor
Definition: settings.hpp:223
restinio::acceptor_options_t::acceptor_options_t
acceptor_options_t(asio_ns::ip::tcp::acceptor &acceptor)
Definition: settings.hpp:187
restinio::basic_server_settings_t
Basic container for http_server settings.
Definition: settings.hpp:556
restinio::basic_server_settings_t::incoming_http_msg_limits
RESTINIO_NODISCARD const incoming_http_msg_limits_t & incoming_http_msg_limits() const noexcept
Getter of optional limits for incoming HTTP messages.
Definition: settings.hpp:1412
restinio::basic_server_settings_t::timer_factory_t
typename timer_manager_t::factory_t timer_factory_t
Definition: settings.hpp:884
restinio::basic_server_settings_t::ip_blocker
const std::shared_ptr< typename Traits::ip_blocker_t > & ip_blocker() const noexcept
Get reference to IP-blocker.
Definition: settings.hpp:1297
restinio::basic_server_settings_t::m_request_handler
std::unique_ptr< request_handler_t > m_request_handler
Request handler.
Definition: settings.hpp:1713
restinio::basic_server_settings_t::giveaway_extra_data_factory
RESTINIO_NODISCARD extra_data_factory_handle_t giveaway_extra_data_factory() const noexcept
Extractor for extra-data-factory.
Definition: settings.hpp:1644
restinio::basic_server_settings_t::m_acceptor_options_setter
std::unique_ptr< acceptor_options_setter_t > m_acceptor_options_setter
Acceptor options setter.
Definition: settings.hpp:1722
restinio::basic_server_settings_t::concurrent_accepts_count
std::size_t concurrent_accepts_count() const
Definition: settings.hpp:1022
restinio::basic_server_settings_t::m_socket_options_setter
std::unique_ptr< socket_options_setter_t > m_socket_options_setter
Socket options setter.
Definition: settings.hpp:1735
restinio::basic_server_settings_t::address
RESTINIO_NODISCARD const details::address_variant_t & address() const
Definition: settings.hpp:717
restinio::basic_server_settings_t::logger_t
typename Traits::logger_t logger_t
Logger.
Definition: settings.hpp:913
restinio::basic_server_settings_t::port
Derived & port(std::uint16_t p) &
Server endpoint.
Definition: settings.hpp:586
restinio::basic_server_settings_t::handle_request_timeout
Derived && handle_request_timeout(std::chrono::steady_clock::duration d) &&
Definition: settings.hpp:808
restinio::basic_server_settings_t::ip_blocker
Derived & ip_blocker(std::shared_ptr< typename Traits::ip_blocker_t > blocker) &
Setter for IP-blocker.
Definition: settings.hpp:1237
restinio::basic_server_settings_t::concurrent_accepts_count
Derived && concurrent_accepts_count(std::size_t n) &&
Definition: settings.hpp:1016
restinio::basic_server_settings_t::buffer_size
Derived & buffer_size(std::size_t s) &
Size of buffer for io operations.
Definition: settings.hpp:730
restinio::basic_server_settings_t::concurrent_accepts_count
Derived & concurrent_accepts_count(std::size_t n) &
Max number of running concurrent accepts.
Definition: settings.hpp:1003
restinio::basic_server_settings_t::separate_accept_and_create_connect
Derived && separate_accept_and_create_connect(bool do_separate) &&noexcept
Definition: settings.hpp:1046
restinio::basic_server_settings_t::cleanup_func
Derived && cleanup_func(Func &&func) &&
Definition: settings.hpp:1070
restinio::basic_server_settings_t::max_parallel_connections
Derived & max_parallel_connections(std::size_t value) &noexcept
Setter for connection count limit.
Definition: settings.hpp:1501
restinio::basic_server_settings_t::socket_options_setter
std::unique_ptr< socket_options_setter_t > socket_options_setter()
Definition: settings.hpp:988
restinio::basic_server_settings_t::extra_data_factory
Derived && extra_data_factory(extra_data_factory_handle_t factory) &&
Setter for extra-data-factory.
Definition: settings.hpp:1632
restinio::basic_server_settings_t::protocol
RESTINIO_NODISCARD asio_ns::ip::tcp protocol() const
Definition: settings.hpp:620
restinio::basic_server_settings_t::request_handler
Derived & request_handler(Params &&... params) &
Definition: settings.hpp:856
restinio::basic_server_settings_t::socket_options_setter
Derived && socket_options_setter(socket_options_setter_t sos) &&
Definition: settings.hpp:982
restinio::basic_server_settings_t::ensure_valid_connection_state_listener
void ensure_valid_connection_state_listener()
Internal method for checking presence of state listener object.
Definition: settings.hpp:1200
restinio::basic_server_settings_t::m_port
std::uint16_t m_port
Server endpoint.
Definition: settings.hpp:1685
restinio::basic_server_settings_t::logger
Derived && logger(Params &&... params) &&
Definition: settings.hpp:926
restinio::basic_server_settings_t::m_logger
std::unique_ptr< logger_t > m_logger
Logger.
Definition: settings.hpp:1719
restinio::basic_server_settings_t::max_parallel_connections
Derived && max_parallel_connections(std::size_t value) &&noexcept
Setter for connection count limit.
Definition: settings.hpp:1536
restinio::basic_server_settings_t::timer_manager
Derived && timer_manager(Params &&... params) &&
Definition: settings.hpp:897
restinio::basic_server_settings_t::write_http_response_timelimit
Derived & write_http_response_timelimit(std::chrono::steady_clock::duration d) &
A period of time wait for response to be written to socket.
Definition: settings.hpp:779
restinio::basic_server_settings_t::extra_data_factory_handle_t
std::shared_ptr< extra_data_factory_t > extra_data_factory_handle_t
Type of shared-pointer to extra-data-factory.
Definition: settings.hpp:1556
restinio::basic_server_settings_t::m_extra_data_factory
extra_data_factory_handle_t m_extra_data_factory
User-data-factory for server.
Definition: settings.hpp:1757
restinio::basic_server_settings_t::cleanup_func
Derived & cleanup_func(Func &&func) &
Cleanup function.
Definition: settings.hpp:1062
restinio::basic_server_settings_t::request_handler
std::unique_ptr< request_handler_t > request_handler()
Definition: settings.hpp:872
restinio::basic_server_settings_t::acceptor_options_setter
Derived && acceptor_options_setter(acceptor_options_setter_t aos) &&
Definition: settings.hpp:954
restinio::basic_server_settings_t::connection_state_listener
Derived && connection_state_listener(std::shared_ptr< typename Traits::connection_state_listener_t > listener) &&
Setter for connection state listener.
Definition: settings.hpp:1164
restinio::basic_server_settings_t::protocol
Derived & protocol(asio_ns::ip::tcp p) &
Definition: settings.hpp:606
restinio::basic_server_settings_t::request_handler
Derived & request_handler(std::unique_ptr< request_handler_t > handler) &
Definition: settings.hpp:848
restinio::basic_server_settings_t::basic_server_settings_t
basic_server_settings_t(std::uint16_t port=8080, asio_ns::ip::tcp protocol=asio_ns::ip::tcp::v4())
Definition: settings.hpp:575
restinio::basic_server_settings_t::read_next_http_message_timelimit
Derived && read_next_http_message_timelimit(std::chrono::steady_clock::duration d) &&
Definition: settings.hpp:764
restinio::basic_server_settings_t::incoming_http_msg_limits
Derived & incoming_http_msg_limits(const incoming_http_msg_limits_t &limits) &noexcept
Setter of optional limits for incoming HTTP messages.
Definition: settings.hpp:1440
restinio::basic_server_settings_t::m_protocol
asio_ns::ip::tcp m_protocol
Definition: settings.hpp:1686
restinio::basic_server_settings_t::ip_blocker
Derived && ip_blocker(std::shared_ptr< typename Traits::ip_blocker_t > blocker) &&
Setter for IP-blocker.
Definition: settings.hpp:1282
restinio::basic_server_settings_t::max_pipelined_requests
Derived && max_pipelined_requests(std::size_t mpr) &&
Definition: settings.hpp:830
restinio::basic_server_settings_t::m_incoming_http_msg_limits
incoming_http_msg_limits_t m_incoming_http_msg_limits
Limits for incoming HTTP messages.
Definition: settings.hpp:1750
restinio::basic_server_settings_t::buffer_size
std::size_t buffer_size() const
Definition: settings.hpp:743
restinio::basic_server_settings_t::handle_request_timeout
Derived & handle_request_timeout(std::chrono::steady_clock::duration d) &
A period of time that is given for a handler to create response.
Definition: settings.hpp:801
restinio::basic_server_settings_t::reference_to_derived
Derived & reference_to_derived()
Definition: settings.hpp:1656
restinio::basic_server_settings_t::m_timer_factory
std::unique_ptr< timer_factory_t > m_timer_factory
Timers factory.
Definition: settings.hpp:1716
restinio::basic_server_settings_t::timer_manager
Derived & timer_manager(Params &&... params) &
Definition: settings.hpp:888
restinio::basic_server_settings_t::request_handler
Derived && request_handler(Params &&... params) &&
Definition: settings.hpp:866
restinio::basic_server_settings_t::address
Derived && address(std::string addr) &&
Definition: settings.hpp:663
restinio::basic_server_settings_t::handle_request_timeout
std::chrono::steady_clock::duration handle_request_timeout() const
Definition: settings.hpp:814
restinio::basic_server_settings_t::logger
Derived & logger(Params &&... params) &
Definition: settings.hpp:917
restinio::basic_server_settings_t::acceptor_options_setter
std::unique_ptr< acceptor_options_setter_t > acceptor_options_setter()
Definition: settings.hpp:960
restinio::basic_server_settings_t::address
Derived & address(asio_ns::ip::address addr) &
Definition: settings.hpp:688
restinio::basic_server_settings_t::ensure_valid_ip_blocker
void ensure_valid_ip_blocker()
Internal method for checking presence of IP-blocker object.
Definition: settings.hpp:1316
restinio::basic_server_settings_t::acceptor_options_setter
Derived & acceptor_options_setter(acceptor_options_setter_t aos) &
Acceptor options setter.
Definition: settings.hpp:943
restinio::basic_server_settings_t::extra_data_factory
Derived & extra_data_factory(extra_data_factory_handle_t factory) &
Setter for extra-data-factory.
Definition: settings.hpp:1592
restinio::basic_server_settings_t::write_http_response_timelimit
Derived && write_http_response_timelimit(std::chrono::steady_clock::duration d) &&
Definition: settings.hpp:786
restinio::basic_server_settings_t::giveaway_cleanup_func
RESTINIO_NODISCARD cleanup_functor_t giveaway_cleanup_func()
Definition: settings.hpp:1083
restinio::basic_server_settings_t::read_next_http_message_timelimit
std::chrono::steady_clock::duration read_next_http_message_timelimit() const
Definition: settings.hpp:770
restinio::basic_server_settings_t::max_pipelined_requests
Derived & max_pipelined_requests(std::size_t mpr) &
Max pipelined requests able to receive on single connection.
Definition: settings.hpp:823
restinio::basic_server_settings_t::set_unique_instance
Derived & set_unique_instance(std::unique_ptr< Target > &t, Params &&... params)
Definition: settings.hpp:1663
restinio::basic_server_settings_t::timer_manager_t
typename Traits::timer_manager_t timer_manager_t
Timers manager.
Definition: settings.hpp:883
restinio::basic_server_settings_t::extra_data_factory_t
typename Traits::extra_data_factory_t extra_data_factory_t
The actual type of extra-data-factory.
Definition: settings.hpp:1551
restinio::basic_server_settings_t::set_shared_instance
Derived & set_shared_instance(std::shared_ptr< Target > &t, Params &&... params)
Definition: settings.hpp:1674
restinio::basic_server_settings_t::connection_state_listener
const std::shared_ptr< typename Traits::connection_state_listener_t > & connection_state_listener() const noexcept
Get reference to connection state listener.
Definition: settings.hpp:1180
restinio::basic_server_settings_t::max_pipelined_requests
std::size_t max_pipelined_requests() const
Definition: settings.hpp:836
restinio::basic_server_settings_t::has_actual_max_parallel_connections
static constexpr bool has_actual_max_parallel_connections
Definition: settings.hpp:483
restinio::basic_server_settings_t::acceptor_post_bind_hook
Derived && acceptor_post_bind_hook(acceptor_post_bind_hook_t hook) &&
A setter for post-bind callback.
Definition: settings.hpp:1375
restinio::basic_server_settings_t::m_cleanup_functor
cleanup_functor_t m_cleanup_functor
Optional cleanup functor.
Definition: settings.hpp:1743
restinio::basic_server_settings_t::port
Derived && port(std::uint16_t p) &&
Definition: settings.hpp:593
restinio::basic_server_settings_t::timer_factory
std::unique_ptr< timer_factory_t > timer_factory()
Definition: settings.hpp:903
restinio::basic_server_settings_t::address
Derived && address(asio_ns::ip::address addr) &&
Definition: settings.hpp:710
restinio::basic_server_settings_t::socket_options_setter
Derived & socket_options_setter(socket_options_setter_t sos) &
Socket options setter.
Definition: settings.hpp:971
restinio::basic_server_settings_t::acceptor_post_bind_hook
Derived & acceptor_post_bind_hook(acceptor_post_bind_hook_t hook) &
A setter for post-bind callback.
Definition: settings.hpp:1346
restinio::basic_server_settings_t::incoming_http_msg_limits
Derived && incoming_http_msg_limits(const incoming_http_msg_limits_t &limits) &&noexcept
Setter of optional limits for incoming HTTP messages.
Definition: settings.hpp:1470
restinio::basic_server_settings_t::write_http_response_timelimit
std::chrono::steady_clock::duration write_http_response_timelimit() const
Definition: settings.hpp:792
restinio::basic_server_settings_t::m_address
details::address_variant_t m_address
Definition: settings.hpp:1691
restinio::basic_server_settings_t::request_handler_t
request_handler_type_from_traits_t< Traits > request_handler_t
Request handler.
Definition: settings.hpp:845
restinio::basic_server_settings_t::buffer_size
Derived && buffer_size(std::size_t s) &&
Definition: settings.hpp:737
restinio::basic_server_settings_t::separate_accept_and_create_connect
Derived & separate_accept_and_create_connect(bool do_separate) &noexcept
Do separate an accept operation and connection instantiation.
Definition: settings.hpp:1039
restinio::basic_server_settings_t::read_next_http_message_timelimit
Derived & read_next_http_message_timelimit(std::chrono::steady_clock::duration d) &
}
Definition: settings.hpp:757
restinio::basic_server_settings_t::port
RESTINIO_NODISCARD std::uint16_t port() const
Definition: settings.hpp:600
restinio::basic_server_settings_t::giveaway_acceptor_post_bind_hook
RESTINIO_NODISCARD acceptor_post_bind_hook_t giveaway_acceptor_post_bind_hook()
A getter for post-bind callback.
Definition: settings.hpp:1392
restinio::basic_server_settings_t::address
Derived & address(std::string addr) &
Definition: settings.hpp:643
restinio::basic_server_settings_t::connection_state_listener
Derived & connection_state_listener(std::shared_ptr< typename Traits::connection_state_listener_t > listener) &
Setter for connection state listener.
Definition: settings.hpp:1120
restinio::basic_server_settings_t::protocol
Derived && protocol(asio_ns::ip::tcp p) &&
Definition: settings.hpp:613
restinio::basic_server_settings_t::separate_accept_and_create_connect
bool separate_accept_and_create_connect() const noexcept
Definition: settings.hpp:1052
restinio::basic_server_settings_t::logger
std::unique_ptr< logger_t > logger()
Definition: settings.hpp:932
restinio::connection_count_limits::noop_connection_count_limiter_t
An implementation of connection count limiter for the case when connection count is not limited.
Definition: connection_count_limiter.hpp:271
restinio::exception_t
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
restinio::incoming_http_msg_limits_t
A type of holder of limits related to an incoming HTTP message.
Definition: incoming_http_msg_limits.hpp:69
restinio::server_settings_t
A fluent style interface for setting http server params.
Definition: settings.hpp:1768
restinio::socket_options_t
An adapter for setting acceptor options before running server.
Definition: settings.hpp:249
restinio::socket_options_t::set_option
void set_option(const Option &option, asio_ns::error_code &ec)
Definition: settings.hpp:268
restinio::socket_options_t::m_socket
asio_ns::basic_socket< asio_ns::ip::tcp > & m_socket
A reference on the most base class with interface of setting options.
Definition: settings.hpp:290
restinio::socket_options_t::get_option
void get_option(Option &option)
Definition: settings.hpp:275
restinio::socket_options_t::get_option
void get_option(Option &option, asio_ns::error_code &ec)
Definition: settings.hpp:282
restinio::socket_options_t::socket_options_t
socket_options_t(asio_ns::basic_socket< asio_ns::ip::tcp > &socket)
Definition: settings.hpp:251
restinio::socket_options_t::set_option
void set_option(const Option &option)
API for setting/getting options.
Definition: settings.hpp:261
restinio::socket_type_dependent_settings_t
Extra settings needed for working with socket.
Definition: settings.hpp:155
restinio::socket_type_dependent_settings_t::~socket_type_dependent_settings_t
~socket_type_dependent_settings_t() noexcept=default
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
exception.hpp
incoming_http_msg_limits.hpp
Stuff related to limits of an incoming HTTP message.
nonstd::optional_lite::std11::false_type
bool_constant< false > false_type
Definition: optional.hpp:460
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:465
nonstd::optional_lite::std11::true_type
bool_constant< true > true_type
Definition: optional.hpp:459
restinio::details::create_default_unique_object_instance
auto create_default_unique_object_instance(std::false_type)
Default instantiation for a specific type.
Definition: settings.hpp:34
restinio::details::create_default_shared_object_instance
auto create_default_shared_object_instance(std::false_type)
Default instantiation for a specific type.
Definition: settings.hpp:49
restinio::ip_blocker::inspection_result_t
inspection_result_t
Enumeration of result of inspecting new incoming connection.
Definition: ip_blocker.hpp:31
restinio
Definition: asio_include.hpp:21
restinio::ensure_created
auto ensure_created(std::unique_ptr< Object > mb_created_one, string_view_t fail_description)
Ensure that object was created.
Definition: settings.hpp:114
restinio::create_default_unique_object_instance< acceptor_options_setter_t >
auto create_default_unique_object_instance< acceptor_options_setter_t >()
Definition: settings.hpp:230
restinio::acceptor_post_bind_hook_t
std::function< void(asio_ns::ip::tcp::acceptor &) > acceptor_post_bind_hook_t
A type of callback to be called after a successful invocation of bind() function for the acceptor.
Definition: settings.hpp:435
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::create_default_shared_object_instance
auto create_default_shared_object_instance()
Default instantiation for a specific type.
Definition: settings.hpp:92
restinio::cleanup_functor_t
std::function< void(void) > cleanup_functor_t
Type of holder for user's cleanup function.
Definition: settings.hpp:308
restinio::exec_configurator
auto exec_configurator(Configurator &&configurator)
Definition: settings.hpp:1777
restinio::create_default_shared_object_instance< default_request_handler_t >
auto create_default_shared_object_instance< default_request_handler_t >()
Default instantiation for default_request_handler_t.
Definition: settings.hpp:101
restinio::socket_options_setter_t
std::function< void(socket_options_t &) > socket_options_setter_t
Definition: settings.hpp:293
restinio::request_handler_type_from_traits_t
typename details::actual_request_handler_type_detector< typename Traits::request_handler_t, typename Traits::extra_data_factory_t >::request_handler_t request_handler_type_from_traits_t
A metafunction for extraction a request-handler type from server's traits.
Definition: traits.hpp:379
restinio::create_default_unique_object_instance
auto create_default_unique_object_instance()
Default instantiation for a specific type.
Definition: settings.hpp:70
restinio::create_default_unique_object_instance< default_request_handler_t >
auto create_default_unique_object_instance< default_request_handler_t >()
Default instantiation for default_request_handler_t.
Definition: settings.hpp:79
restinio::acceptor_options_setter_t
std::function< void(acceptor_options_t &) > acceptor_options_setter_t
Definition: settings.hpp:226
restinio::create_default_unique_object_instance< socket_options_setter_t >
auto create_default_unique_object_instance< socket_options_setter_t >()
Definition: settings.hpp:297
request_handler.hpp
restinio::connection_count_limit_types::limiter_t
typename std::conditional< Traits::use_connection_count_limiter, connection_count_limits::connection_count_limiter_t< typename Traits::strand_t >, connection_count_limits::noop_connection_count_limiter_t >::type limiter_t
Definition: connection_count_limiter.hpp:466
restinio::connection_state_listener_holder_t< connection_state::noop_listener_t >::check_valid_connection_state_listener_pointer
void check_valid_connection_state_listener_pointer() const
Definition: settings.hpp:355
restinio::connection_state_listener_holder_t
A special class for holding actual connection state listener.
Definition: settings.hpp:324
restinio::connection_state_listener_holder_t::m_connection_state_listener
std::shared_ptr< Listener > m_connection_state_listener
Definition: settings.hpp:325
restinio::connection_state_listener_holder_t::check_valid_connection_state_listener_pointer
void check_valid_connection_state_listener_pointer() const
Checks that pointer to state listener is not null.
Definition: settings.hpp:334
restinio::details::max_parallel_connections_holder_t< ::restinio::connection_count_limits::noop_connection_count_limiter_t >::max_parallel_connections
std::size_t max_parallel_connections() const noexcept
Definition: settings.hpp:525
restinio::details::max_parallel_connections_holder_t
A special type for holding the value of maximum allowed count of parallel connections.
Definition: settings.hpp:482
restinio::details::max_parallel_connections_holder_t::set_max_parallel_connections
void set_max_parallel_connections(std::size_t v) noexcept
Definition: settings.hpp:501
restinio::details::max_parallel_connections_holder_t::max_parallel_connections
std::size_t max_parallel_connections() const noexcept
Definition: settings.hpp:495
restinio::details::no_address_specified_t
A special indicator for the case when IP address for a server is not set explicitly.
Definition: settings.hpp:449
restinio::ip_blocker_holder_t< ip_blocker::noop_ip_blocker_t >::check_valid_ip_blocker_pointer
void check_valid_ip_blocker_pointer() const
Definition: settings.hpp:419
restinio::ip_blocker_holder_t
A special class for holding actual IP-blocker object.
Definition: settings.hpp:375
restinio::ip_blocker_holder_t::check_valid_ip_blocker_pointer
void check_valid_ip_blocker_pointer() const
Checks that pointer to IP-blocker is not null.
Definition: settings.hpp:398
restinio::ip_blocker_holder_t::m_ip_blocker
std::shared_ptr< Ip_Blocker > m_ip_blocker
Definition: settings.hpp:379
restinio::ip_blocker_holder_t< Traits::ip_blocker_t >::has_actual_ip_blocker
static constexpr bool has_actual_ip_blocker
Definition: settings.hpp:391
traits.hpp
variant.hpp
const
#define const
Definition: zconf.h:230