RESTinio

Public Types | Static Public Attributes | List of all members
restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket > Struct Template Reference

`#include <traits.hpp>`

## Public Types
using | http_methods_mapper_t = default_http_methods_t
| A type for HTTP methods mapping. More...
using | connection_state_listener_t = connection_state::noop_listener_t
| A type for connection state listener. More...
using | ip_blocker_t = ip_blocker::noop_ip_blocker_t
| A type for IP-blocker. More...
using | timer_manager_t = Timer_Manager
using | logger_t = Logger
using | request_handler_t = Request_Handler
using | strand_t = Strand
using | stream_socket_t = Socket
using | extra_data_factory_t = no_extra_data_factory_t
| The type of extra-data-factory. More...

## Static Public Attributes
static constexpr bool | use_connection_count_limiter = false
| A flag that enables or disables the usage of connection count limiter. More...

## Detailed Description

template<typename Timer_Manager, typename Logger, typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>
struct restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >

Examples
  sample/async_handling_with_sobjectizer/main.cpp, sample/chained_handlers/main.cpp, sample/connection_state/main.cpp, sample/express_router/main.cpp, sample/express_router_tutorial/main.cpp, sample/extra_data_factory/main.cpp, sample/file_upload/main.cpp, sample/hello_world/main.cpp, sample/hello_world_https/main.cpp, sample/hello_world_sendfile/main.cpp, sample/hello_world_sendfile_https/main.cpp, sample/ip_blocker/main.cpp, sample/sendfiles/main.cpp, sample/shared_tls_context/main.cpp, sample/tls_inspector/main.cpp, sample/websocket/main.cpp, sample/websocket_detailed/main.cpp, and sample/websocket_wss/main.cpp.

Definition at line 146 of file traits.hpp.

## Member Typedef Documentation

## ◆ connection_state_listener_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::connection_state_listener_t = connection_state::noop_listener_t

A type for connection state listener.

By default RESTinio doesn't inform about changes with connection state. But if a user specify its type of connection state listener then RESTinio will call this listener object when the state of connection changes.

An example:

// Definition of user's state listener.
class my_state_listener {
...
public:
...
void state_changed(const restinio::connection_state::notice_t & notice) noexcept {
... // some reaction to state change.
}
};
// Definition of custom traits for HTTP server.
struct my_server_traits : public restinio::default_traits_t {
using connection_state_listener_t = my_state_listener;
};
restinio::connection_state::notice_t
An object with info about connection to be passed to state listener.
Definition: connection_state_listener.hpp:225
restinio::traits_t
Definition: traits.hpp:147
restinio::traits_t::connection_state_listener_t
connection_state::noop_listener_t connection_state_listener_t
A type for connection state listener.
Definition: traits.hpp:213

Since
  v.0.5.1

Definition at line 213 of file traits.hpp.

## ◆ extra_data_factory_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::extra_data_factory_t = no_extra_data_factory_t

The type of extra-data-factory.

By the default RESTinio doesn't hold any additional data for a request object. But if a user has to store some user-specific data inside a request object the user has to do the following steps:

The first one is the definition of factory type that should look like:

class some_extra_data_factory {
public:
using data_t = ...;
void make_within(restinio::extra_data_buffer_t<data_t> buf);
};
restinio::extra_data_buffer_t
Helper for holding a pointer to a buffer where a new object of type Extra_Data should be constructed.
Definition: request_handler.hpp:52

Where the name `data_t` should define a name of type to incorporated into request object. And the method `make_within` should call a placement new for type `data_t` to construct a new object of `data_t` inside the buffer `buf`:

void some_extra_data_factory::make_within(
restinio::extra_data_buffer_t<data_t> buf) {
new(buf.get()) data_t{...};
}
restinio::extra_data_buffer_t::get
RESTINIO_NODISCARD void * get() const noexcept
Definition: request_handler.hpp:60

The second step is the definition of extra-data-factory in server's traits:

struct my_traits : public restinio::default_traits_t {
using extra_data_factory_t = some_extra_data_factory;
};
restinio::traits_t::extra_data_factory_t
no_extra_data_factory_t extra_data_factory_t
The type of extra-data-factory.
Definition: traits.hpp:357

The third step is the creation of the extra-data-factory instance and passing it to server settings:

restino::run(on_thread_pool<my_traits>(16)
.port(...)
.address(...)
.extra_data_factory(std::make_shared<some_extra_data_factory>(..))
.request_handler(...)
...
);
restinio::run
void run(asio_ns::io_context &ioctx, run_on_this_thread_settings_t< Traits > &&settings)
Helper function for running http server until ctrl+c is hit.
Definition: http_server_run.hpp:216

Please note that the third step is not necessary if extra-data-factory type is DefaultConstructible. In that case an instance of extra-data-factory will be created automatically.

Please note that if RESTinio's server is used with express-like or easy_parser-based routers then `request_handler_t` should be defined with the respect to extra-data-factory type:

struct my_extra_data_factory {
struct data_t {...};
void make_within(restinio::extra_data_buffer_t<data_t> buf) {
new(buf.get()) data_t{};
}
};
using my_router = restinio::router::generic_express_router_t<
restinio::router::std_regex_engine_t,
my_extra_data_factory
>;
struct my_traits : public restinio::default_traits_t {
using extra_data_factory_t = my_extra_data_factory;
using request_handler_t = my_router;
};
restinio::router::generic_express_router_t
Generic Express.js style router.
Definition: express.hpp:612
restinio::router::std_regex_engine_t
Regex engine implementation for using with standard regex implementation.
Definition: std_regex_engine.hpp:25
restinio::traits_t::request_handler_t
Request_Handler request_handler_t
Definition: traits.hpp:251

Since
  v.0.6.13

Definition at line 357 of file traits.hpp.

## ◆ http_methods_mapper_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::http_methods_mapper_t = default_http_methods_t

A type for HTTP methods mapping.

If RESTinio is used with vanila version of http_parser then the default value of http_methods_mapper_t is enough. But if a user uses modified version of http_parser with support of additional, not-standard HTTP methods then the user should provide its http_methods_mapper. For example:

// Definition for non-standard HTTP methods.
// Note: values of HTTP_ENCODE and HTTP_DECODE are from modified
// http_parser version.
constexpr const restinio::http_method_id_t http_encode(HTTP_ENCODE, "ENCODE");
constexpr const restinio::http_method_id_t http_decode(HTTP_DECODE, "DECODE");
// Definition of non-standard http_method_mapper.
struct my_http_method_mapper {
inline constexpr restinio::http_method_id_t
from_nodejs(int value) noexcept {
switch(value) {
case HTTP_ENCODE: return http_encode;
case HTTP_DECODE: return http_decode;
default: return restinio::default_http_methods_t::from_nodejs(value);
}
}
};
...
// Make a custom traits with non-standard http_method_mapper.
struct my_server_traits : public restinio::default_traits_t {
using http_methods_mapper_t = my_http_method_mapper;
};
restinio::default_http_methods_t::from_nodejs
static constexpr http_method_id_t from_nodejs(int value) noexcept
Definition: http_headers.hpp:1835
restinio::http_method_id_t
A type for representation of HTTP method ID.
Definition: http_headers.hpp:1744
restinio::traits_t::http_methods_mapper_t
default_http_methods_t http_methods_mapper_t
A type for HTTP methods mapping.
Definition: traits.hpp:183

Since
  v.0.5.0

Definition at line 183 of file traits.hpp.

## ◆ ip_blocker_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::ip_blocker_t = ip_blocker::noop_ip_blocker_t

A type for IP-blocker.

By default RESTinio's accepts all incoming connections. But since v.0.5.1 a user can specify IP-blocker object that will be called for every new connection. This IP-blocker can deny or allow a new connection.

Type of that IP-blocker object is specified by typedef ip_blocker_t.

An example:

// Definition of user's IP-blocker.
class my_ip_blocker {
...
public:
...
restinio::ip_blocker::inspection_result_t
state_changed(const restinio::ip_blocker::incoming_info_t & info) noexcept {
... // some checking for new connection.
}
};
// Definition of custom traits for HTTP server.
struct my_server_traits : public restinio::default_traits_t {
using ip_blocker_t = my_ip_blocker;
};
restinio::ip_blocker::incoming_info_t
An information about new incoming connection to be passed to IP-blocker object.
Definition: ip_blocker.hpp:64
restinio::ip_blocker::inspection_result_t
inspection_result_t
Enumeration of result of inspecting new incoming connection.
Definition: ip_blocker.hpp:31
restinio::traits_t::ip_blocker_t
ip_blocker::noop_ip_blocker_t ip_blocker_t
A type for IP-blocker.
Definition: traits.hpp:247

Since
  v.0.5.1

Definition at line 247 of file traits.hpp.

## ◆ logger_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::logger_t = Logger

Definition at line 250 of file traits.hpp.

## ◆ request_handler_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::request_handler_t = Request_Handler

Definition at line 251 of file traits.hpp.

## ◆ strand_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::strand_t = Strand

Definition at line 252 of file traits.hpp.

## ◆ stream_socket_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::stream_socket_t = Socket

Definition at line 253 of file traits.hpp.

## ◆ timer_manager_t

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

using restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::timer_manager_t = Timer_Manager

Definition at line 249 of file traits.hpp.

## Member Data Documentation

## ◆ use_connection_count_limiter

template<typename Timer_Manager , typename Logger , typename Request_Handler = details::autodetect_request_handler_type, typename Strand = default_strand_t, typename Socket = asio_ns::ip::tcp::socket>

constexpr bool restinio::traits_t< Timer_Manager, Logger, Request_Handler, Strand, Socket >::use_connection_count_limiter = false
| static constexpr

A flag that enables or disables the usage of connection count limiter.

Since v.0.6.12 RESTinio allows to limit the number of active parallel connections to a server. But the usage of this limit should be turned on explicitly. For example:

struct my_traits : public restinio::default_traits_t {
static constexpr bool use_connection_count_limiter = true;
};
restinio::traits_t::use_connection_count_limiter
static constexpr bool use_connection_count_limiter
A flag that enables or disables the usage of connection count limiter.
Definition: traits.hpp:278

In that case there will be `max_parallel_connections` method in server_settings_t type. That method should be explicitly called to set a specific limit (by the default there is no limit at all):

restinio::server_settings_t<my_traits> settings;
settings.max_parallel_connections(1000u);
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::server_settings_t
A fluent style interface for setting http server params.
Definition: settings.hpp:1768

Since
  v.0.6.12

Definition at line 278 of file traits.hpp.

The documentation for this struct was generated from the following file:

- restinio/traits.hpp