Loading...
Searching...
No Matches
restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory > Class Template Reference

A holder of variable-size chain of synchronous handlers. More...

`#include <growable_size.hpp>`

## Classes

class | builder_t
| A builder of an instance of growable_size_chain. More...
struct | creation_token_t

## Public Member Functions

| growable_size_chain_t ()=delete
RESTINIO_NODISCARD request_handling_status_t | operator() (const actual_request_handle_t &req) const

## Private Types

using | actual_request_handle_t = generic_request_handle_t< typename Extra_Data_Factory::data_t >
using | handler_holder_t = std::function< request_handling_status_t(const actual_request_handle_t &) >

## Private Member Functions

| growable_size_chain_t (creation_token_t)
| The main constructor.

## Private Attributes

std::vector< handler_holder_t > | m_handlers

## Friends

class | builder_t

## Detailed Description

template<typename Extra_Data_Factory = no_extra_data_factory_t>
class restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >

A holder of variable-size chain of synchronous handlers.

Note
  Once a list of handler is filled and an instance of growable_size_chain_t is created that instance can't be changed: a new handler can't be added, and an old handler can be removed. The creation of growable_size_chain_t instance is performed by the help of growable_size_chain_t::builder_t class.

Usage example for the case when there is no extra-data in a request object.

struct my_traits : public restinio::default_traits_t {
using request_handler_t = restinio::sync_chain::growable_size_chain_t;
};
// The first handler in the chain.
restinio::request_handling_status_t headers_checker(
const restinio::request_handle_t & req )
{
... // Checks values of HTTP-fields and rejects invalid requests.
}
// The second handler in the chain.
restinio::request_handling_status_t authentificator(
const restinio::request_handle_t & req )
{
... // Checks user's credentials and rejects requests from
// non-authentificated users.
}
// The last handler in the chain.
restinio::request_handling_status_t actual_handler(
const restinio::request_handle_t & req )
{
... // Actual processing.
}
// Building of a chain.
restinio::sync_chain::growable_size_chain_t::builder_t builder;
if(config.force_headers_checking())
builder.add(headers_checker);
if(config.force_user_authentification())
builder.add(authentificator);
builder.add(actual_handler);
restinio::run(
on_thread_pool<my_traits>(16)
.address(...)
.port(...)
.request_handler(builder.release())
);
restinio::sync_chain::growable_size_chain_t::builder_t
A builder of an instance of growable_size_chain.
Definition: growable_size.hpp:184
restinio::sync_chain::growable_size_chain_t::builder_t::add
void add(Handler &&handler)
Add a new handler to the chain.
Definition: growable_size.hpp:209
restinio::sync_chain::growable_size_chain_t::builder_t::release
RESTINIO_NODISCARD std::unique_ptr< growable_size_chain_t > release() noexcept
Stop adding of new handlers and acquire the chain instance.
Definition: growable_size.hpp:199
restinio::sync_chain::growable_size_chain_t
A holder of variable-size chain of synchronous handlers.
Definition: growable_size.hpp:159
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
restinio::request_handling_status_t
request_handling_status_t
Request handling status.
Definition: common_types.hpp:26
restinio::request_handle_t
std::shared_ptr< request_t > request_handle_t
An alias for handle for incoming request without additional extra-data.
Definition: request_handler.hpp:471
config_s
Definition: deflate.c:120
restinio::traits_t
Definition: traits.hpp:147

Usage example for the case when some extra-data is incorporated into a request object.

struct my_extra_data_factory {
// A data formed by checker of HTTP-fields.
struct request_specific_fields_t {...};
// A data formed by user-authentificator.
struct user_info_t {...};
// A data to be incorporated into a request object.
using data_t = std::tuple<
std::optional<request_specific_fields_t>,
std::optional<user_info_t>>;
void make_within(restinio::extra_data_buffer_t<data_t> buf) {
new(buf.get()) data_t{};
}
};
struct my_traits : public restinio::default_traits_t {
using extra_data_factory_t = my_extra_data_factory;
using request_handler_t = restinio::sync_chain::growable_size_chain_t<
extra_data_factory>;
};
using my_request_handle_t =
restinio::generic_request_handle_t<my_extra_data_factory::data_t>;
// The first handler in the chain.
restinio::request_handling_status_t headers_checker(
const my_request_handle_t & req )
{
... // Checks values of HTTP-fields and rejects invalid requests.
}
// The second handler in the chain.
restinio::request_handling_status_t authentificator(
const my_request_handle_t & req )
{
... // Checks user's credentials and rejects requests from
// non-authentificated users.
}
// The last handler in the chain.
restinio::request_handling_status_t actual_handler(
const my_request_handle_t & req )
{
auto & field_values = std::get<
std::optional<my_extra_data_factory::request_specific_fields_t>>(req->extra_data());
auto & user_info = std::get<
std::optional<my_extra_data_factory::user_info_t>>(req->extra_data());
... // Actual processing.
}
// Building of a chain.
restinio::sync_chain::growable_size_chain_t::builder_t builder;
if(config.force_headers_checking())
builder.add(headers_checker);
if(config.force_user_authentification())
builder.add(authentificator);
builder.add(actual_handler);
restinio::run(
on_thread_pool<my_traits>(16)
.address(...)
.port(...)
.request_handler(builder.release())
);
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:54
restinio::extra_data_buffer_t::get
RESTINIO_NODISCARD void * get() const noexcept
Definition: request_handler.hpp:62
restinio::generic_request_handle_t
std::shared_ptr< generic_request_t< Extra_Data > > generic_request_handle_t
An alias for shared-pointer to incoming request.
Definition: request_handler.hpp:455

Template Parameters

  Extra_Data_Factory | The type of extra-data-factory specified in the server's traits.

Since
  v.0.6.13

Examples
  sample/extra_data_factory/main.cpp.

Definition at line 158 of file growable_size.hpp.

## Member Typedef Documentation

## actual_request_handle_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>

using restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::actual_request_handle_t = generic_request_handle_t< typename Extra_Data_Factory::data_t >

private

Definition at line 227 of file growable_size.hpp.

## handler_holder_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>

using restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::handler_holder_t = std::function< request_handling_status_t(const actual_request_handle_t &) >

private

Definition at line 230 of file growable_size.hpp.

## Constructor & Destructor Documentation

## growable_size_chain_t() [1/2]

template<typename Extra_Data_Factory = no_extra_data_factory_t>

restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::growable_size_chain_t | ( | creation_token_t |  | ) |

inline private

The main constructor.

It has that form because the default constructor is public and marked as deleted.

Definition at line 242 of file growable_size.hpp.

## growable_size_chain_t() [2/2]

template<typename Extra_Data_Factory = no_extra_data_factory_t>

restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::growable_size_chain_t | ( |  | ) |

delete

Note
  The default constructor is disable because an instance of that class should be created and filled by using builder_t.

## Member Function Documentation

## operator()()

template<typename Extra_Data_Factory = no_extra_data_factory_t>

RESTINIO_NODISCARD request_handling_status_t restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::operator() | ( | const actual_request_handle_t & | req | ) | const

inline

Definition at line 254 of file growable_size.hpp.

## Friends And Related Function Documentation

## builder_t

template<typename Extra_Data_Factory = no_extra_data_factory_t>

friend class builder_t

friend

Definition at line 165 of file growable_size.hpp.

## Member Data Documentation

## m_handlers

template<typename Extra_Data_Factory = no_extra_data_factory_t>

std::vector< handler_holder_t > restinio::sync_chain::growable_size_chain_t< Extra_Data_Factory >::m_handlers

private

Definition at line 234 of file growable_size.hpp.

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

- restinio/sync_chain/growable_size.hpp