RESTinio
settings.hpp
Go to the documentation of this file.
1 /*
2  restinio
3 */
4 
5 /*!
6  HTTP-Server configuration.
7 */
8 
9 #pragma once
10 
11 #include <restinio/asio_include.hpp>
12 
13 #include <restinio/exception.hpp>
14 #include <restinio/request_handler.hpp>
15 #include <restinio/traits.hpp>
16 
17 #include <restinio/incoming_http_msg_limits.hpp>
18 
19 #include <chrono>
20 #include <variant>
21 #include <tuple>
22 #include <utility>
23 
24 namespace restinio
25 {
26 
27 namespace details
28 {
29 
30 //! Default instantiation for a specific type.
31 template < typename Object >
32 inline auto
34 {
35  return std::unique_ptr< Object >{};
36 }
37 
38 template < typename Object >
39 inline auto
41 {
42  return std::make_unique< Object >();
43 }
44 
45 //! Default instantiation for a specific type.
46 template < typename Object >
47 inline auto
49 {
50  return std::shared_ptr< Object >{};
51 }
52 
53 template < typename Object >
54 inline auto
56 {
57  return std::make_shared< Object >();
58 }
59 
60 } /* namespace details */
61 
62 //
63 // create_default_unique_object_instance
64 //
65 
66 //! Default instantiation for a specific type.
67 template < typename Object>
68 inline auto
70 {
71  typename std::is_default_constructible< Object >::type tag;
72  return details::create_default_unique_object_instance< Object >( tag );
73 }
74 
75 //! Default instantiation for default_request_handler_t.
76 template <>
77 inline auto
79 {
81  std::false_type{} );
82 }
83 
84 //
85 // create_default_shared_object_instance
86 //
87 
88 //! Default instantiation for a specific type.
89 template < typename Object>
90 inline auto
92 {
95 }
96 
97 //! Default instantiation for default_request_handler_t.
98 template <>
99 inline auto
101 {
103  std::false_type{} );
104 }
105 
106 //
107 // ensure_created()
108 //
109 
110 //! Ensure that object was created.
111 template < typename Object >
112 auto
116 {
117  if( !mb_created_one )
119 
120  if( !mb_created_one )
121  throw exception_t{ fail_description };
122 
123  return mb_created_one;
124 }
125 
126 //
127 // unsure_created()
128 //
129 
130 //! Ensure that object was created.
131 template < typename Object >
132 auto
136 {
137  if( !mb_created_one )
139 
140  if( !mb_created_one )
141  throw exception_t{ fail_description };
142 
143  return mb_created_one;
144 }
145 
146 
147 //
148 // socket_type_dependent_settings_t
149 //
150 
151 //! Extra settings needed for working with socket.
152 template < typename Settings, typename Socket >
154 {
155 protected :
156  ~socket_type_dependent_settings_t() noexcept = default;
157 
158 public :
159  socket_type_dependent_settings_t() noexcept = default;
160 
163 
165  operator=(const socket_type_dependent_settings_t &) noexcept = default;
166 
168  operator=(socket_type_dependent_settings_t &&) noexcept = delete;
169 
170  // No extra settings by default.
171 };
172 
173 //
174 // acceptor_options_t
175 //
176 
177 //! An adapter for setting acceptor options before running server.
178 /*!
179  Class hides an acceptor object and opens only set/get options API.
180  It is used as an argument for a user defined function-object
181  that can set custom options for acceptor.
182 */
184 {
185  public:
186  acceptor_options_t( asio_ns::ip::tcp::acceptor & acceptor )
187  : m_acceptor{ acceptor }
188  {}
189 
190  //! API for setting/getting options.
191  //! \{
192  template< typename Option >
193  void
194  set_option( const Option & option )
195  {
197  }
198 
199  template< typename Option >
200  void
201  set_option( const Option & option, asio_ns::error_code & ec )
202  {
204  }
205 
206  template< typename Option >
207  void
208  get_option( Option & option )
209  {
211  }
212 
213  template< typename Option >
214  void
215  get_option( Option & option, asio_ns::error_code & ec )
216  {
218  }
219  //! \}
220 
221  private:
223 };
224 
226 
227 template <>
228 inline auto
230 {
232  []( acceptor_options_t & options ){
234  } );
235 }
236 
237 //
238 // socket_options_t
239 //
240 
241 //! An adapter for setting acceptor options before running server.
242 /*!
243  Class hides a socket object and opens only set/get options API.
244  It is used as an argument for a user defined function-object
245  that can set custom options for socket.
246 */
248 {
249  public:
251  //! A reference on the most base class with interface of setting options.
253  : m_socket{ socket }
254  {}
255 
256  //! API for setting/getting options.
257  //! \{
258  template< typename Option >
259  void
261  {
263  }
264 
265  template< typename Option >
266  void
268  {
270  }
271 
272  template< typename Option >
273  void
275  {
277  }
278 
279  template< typename Option >
280  void
282  {
284  }
285  //! \}
286 
287  private:
288  //! A reference on the most base class with interface of setting options.
290 };
291 
293 
294 template <>
295 inline auto
297 {
298  return std::make_unique< socket_options_setter_t >( []( auto & ){} );
299 }
300 
301 //
302 // cleanup_functor_t
303 //
304 /*!
305  * \brief Type of holder for user's cleanup function.
306  */
307 using cleanup_functor_t = std::function< void(void) >;
308 
309 //
310 // connection_state_listener_holder_t
311 //
312 /*!
313  * @brief A special class for holding actual connection state listener.
314  *
315  * This class holds shared pointer to actual connection state listener
316  * and provides an actual implementation of
317  * check_valid_connection_state_listener_pointer() method.
318  *
319  * @since v.0.5.1
320  */
321 template< typename Listener >
323 {
325 
326  static constexpr bool has_actual_connection_state_listener = true;
327 
328  //! Checks that pointer to state listener is not null.
329  /*!
330  * Throws an exception if m_connection_state_listener is nullptr.
331  */
332  void
334  {
336  throw exception_t{ "connection state listener is not specified" };
337  }
338 };
339 
340 /*!
341  * @brief A special class for case when no-op state listener is used.
342  *
343  * Doesn't hold anything and contains empty
344  * check_valid_connection_state_listener_pointer() method.
345  *
346  * @since v.0.5.1
347  */
348 template<>
350 {
351  static constexpr bool has_actual_connection_state_listener = false;
352 
353  void
355  {
356  // Nothing to do.
357  }
358 };
359 
360 //
361 // ip_blocker_holder_t
362 //
363 /*!
364  * @brief A special class for holding actual IP-blocker object.
365  *
366  * This class holds shared pointer to actual IP-blocker
367  * and provides an actual implementation of
368  * check_valid_ip_blocker_pointer() method.
369  *
370  * @since v.0.5.1
371  */
372 template< typename Ip_Blocker >
374 {
375  static_assert(
376  noexcept( std::declval<Ip_Blocker>().inspect(
378  "Ip_Blocker::inspect() method should be noexcept" );
379 
380  static_assert(
381  std::is_same<
383  decltype(std::declval<Ip_Blocker>().inspect(
385  "Ip_Blocker::inspect() should return "
386  "restinio::ip_blocker::inspection_result_t" );
387 
389 
390  static constexpr bool has_actual_ip_blocker = true;
391 
392  //! Checks that pointer to IP-blocker is not null.
393  /*!
394  * Throws an exception if m_ip_blocker is nullptr.
395  */
396  void
398  {
399  if( !m_ip_blocker )
400  throw exception_t{ "IP-blocker is not specified" };
401  }
402 };
403 
404 /*!
405  * @brief A special class for case when no-op IP-blocker is used.
406  *
407  * Doesn't hold anything and contains empty
408  * check_valid_ip_blocker_pointer() method.
409  *
410  * @since v.0.5.1
411  */
412 template<>
414 {
415  static constexpr bool has_actual_ip_blocker = false;
416 
417  void
419  {
420  // Nothing to do.
421  }
422 };
423 
424 //
425 // acceptor_post_bind_hook_t
426 //
427 /*!
428  * @brief A type of callback to be called after a successful invocation
429  * of bind() function for the acceptor.
430  *
431  * @since v.0.6.11
432  */
434  void(asio_ns::ip::tcp::acceptor &) >;
435 
436 namespace details
437 {
438 
439 //
440 // no_address_specified_t
441 //
442 /*!
443  * @brief A special indicator for the case when IP address for a server
444  * is not set explicitly.
445  *
446  * @since v.0.6.11
447  */
449 
450 //
451 // address_variant_t
452 //
453 /*!
454  * @brief A type of variant for holding IP address for a server in
455  * various representations.
456  *
457  * @since v.0.6.11
458  */
459 using address_variant_t = std::variant<
461  std::string,
463 
464 //
465 // max_parallel_connections_holder_t
466 //
467 /*!
468  * @brief A special type for holding the value of maximum allowed
469  * count of parallel connections.
470  *
471  * This type is intended to be used as a mixin for
472  * server_settings_t type.
473  *
474  * Holds the value and provides the actual implementations for
475  * getter and setter of that value.
476  *
477  * @since v.0.6.12
478  */
479 template< typename Count_Limiter >
481 {
482  static constexpr bool has_actual_max_parallel_connections = true;
483 
484  /*!
485  * @brief Actual value of the limit.
486  *
487  * By the default the count of parallel connection is not limited.
488  */
491  };
492 
493  std::size_t
494  max_parallel_connections() const noexcept
495  {
497  }
498 
499  void
500  set_max_parallel_connections( std::size_t v ) noexcept
501  {
503  }
504 };
505 
506 /*!
507  * @brief A specialization of max_parallel_connections_holder for the case
508  * when connection count isn't limited.
509  *
510  * Doesn't hold anything. Hasn't a setter.
511  *
512  * The getter returns a value that means that there is no connection
513  * count limit at all.
514  *
515  * @since v.0.6.12
516  */
517 template<>
520 {
521  static constexpr bool has_actual_max_parallel_connections = false;
522 
523  std::size_t
524  max_parallel_connections() const noexcept
525  {
526  return std::numeric_limits<std::size_t>::max();
527  }
528 };
529 
530 } /* namespace details */
531 
532 //
533 // basic_server_settings_t
534 //
535 
536 //! Basic container for http_server settings.
537 /*!
538  * It exists to provide ablity to create various derived classes
539  * like server_settings_t, run_on_this_thread_settings_t,
540  * run_on_this_thread_settings_t and so on.
541  *
542  * \tparam Derived A drived type. Reference to this derived type
543  * will be returned by setters.
544  *
545  * \tparam Traits A type with traits for http_server.
546  */
547 template<typename Derived, typename Traits>
551  typename Traits::connection_state_listener_t >
552  , protected ip_blocker_holder_t< typename Traits::ip_blocker_t >
555 {
558 
562 
564  typename Traits::connection_state_listener_t
565  >::has_actual_connection_state_listener;
566 
567  using ip_blocker_holder_t<
568  typename Traits::ip_blocker_t
569  >::has_actual_ip_blocker;
570 
572 
573  public:
575  std::uint16_t port = 8080,
576  asio_ns::ip::tcp protocol = asio_ns::ip::tcp::v4() )
577  : base_type_t{}
578  , m_port{ port }
579  , m_protocol{ protocol }
580  {}
581 
582  //! Server endpoint.
583  //! \{
584  Derived &
585  port( std::uint16_t p ) &
586  {
587  m_port = p;
588  return reference_to_derived();
589  }
590 
591  Derived &&
592  port( std::uint16_t p ) &&
593  {
594  return std::move( this->port( p ) );
595  }
596 
597  [[nodiscard]]
598  std::uint16_t
599  port() const
600  {
601  return m_port;
602  }
603 
604  Derived &
605  protocol( asio_ns::ip::tcp p ) &
606  {
607  m_protocol = p;
608  return reference_to_derived();
609  }
610 
611  Derived &&
612  protocol( asio_ns::ip::tcp p ) &&
613  {
614  return std::move( this->protocol( p ) );
615  }
616 
617  [[nodiscard]]
618  asio_ns::ip::tcp
619  protocol() const
620  {
621  return m_protocol;
622  }
623 
624  /*!
625  * Sets the IP address for a server in textual form.
626  *
627  * Usage example:
628  * @code
629  * using my_server_t = restinio::http_server_t< my_server_traits_t >;
630  * my_server_t server{
631  * restinio::own_io_context(),
632  * [](auto & settings) {
633  * settings.port(8080);
634  * settings.address("192.168.1.1");
635  * settings.request_handler(...);
636  * ...
637  * }
638  * };
639  * @endcode
640  */
641  Derived &
642  address( std::string addr ) &
643  {
644  m_address = std::move(addr);
645  return reference_to_derived();
646  }
647 
648  /*!
649  * Sets the IP address for a server in textual form.
650  *
651  * Usage example:
652  * @code
653  * restinio::run(
654  * restinio::on_this_thread()
655  * .port(...)
656  * .address("192.168.1.1")
657  * .request_handler(...)
658  * );
659  * @endcode
660  */
661  Derived &&
662  address( std::string addr ) &&
663  {
664  return std::move( this->address( std::move( addr ) ) );
665  }
666 
667  /*!
668  * Sets the IP address for a server in binary form.
669  *
670  * Usage example:
671  * @code
672  * auto actual_ip = asio::ip::address::from_string(app.config().ip_addr());
673  * ...
674  * using my_server_t = restinio::http_server_t< my_server_traits_t >;
675  * my_server_t server{
676  * restinio::own_io_context(),
677  * [actual_ip](auto & settings) {
678  * settings.port(8080);
679  * settings.address(actual_ip);
680  * settings.request_handler(...);
681  * ...
682  * }
683  * };
684  * @endcode
685  */
686  Derived &
687  address( asio_ns::ip::address addr ) &
688  {
689  m_address = addr;
690  return reference_to_derived();
691  }
692 
693  /*!
694  * Sets the IP address for a server in binary form.
695  *
696  * Usage example:
697  * @code
698  * auto actual_ip = asio::ip::address::from_string(app.config().ip_addr());
699  * ...
700  * restinio::run(
701  * restinio::on_this_thread()
702  * .port(...)
703  * .address(actual_ip)
704  * .request_handler(...)
705  * );
706  * @endcode
707  */
708  Derived &&
709  address( asio_ns::ip::address addr ) &&
710  {
711  return std::move( this->address( addr ) );
712  }
713 
714  [[nodiscard]]
715  const details::address_variant_t &
716  address() const
717  {
718  return m_address;
719  }
720  //! \}
721 
722  //! Size of buffer for io operations.
723  /*!
724  It limits a size of chunk that can be read from socket in a single
725  read operattion (async read).
726  */
727  //! {
728  Derived &
729  buffer_size( std::size_t s ) &
730  {
731  m_buffer_size = s;
732  return reference_to_derived();
733  }
734 
735  Derived &&
736  buffer_size( std::size_t s ) &&
737  {
738  return std::move( this->buffer_size( s ) );
739  }
740 
741  std::size_t
742  buffer_size() const
743  {
744  return m_buffer_size;
745  }
746  //! }
747 
748  //! A period for holding connection before completely receiving
749  //! new http-request. Starts counting since connection is establised
750  //! or a previous request was responsed.
751  /*!
752  Generaly it defines timeout for keep-alive connections.
753  */
754  //! \{
755  Derived &
756  read_next_http_message_timelimit( std::chrono::steady_clock::duration d ) &
757  {
759  return reference_to_derived();
760  }
761 
762  Derived &&
763  read_next_http_message_timelimit( std::chrono::steady_clock::duration d ) &&
764  {
765  return std::move( this->read_next_http_message_timelimit( std::move( d ) ) );
766  }
767 
770  {
772  }
773  //! \}
774 
775  //! A period of time wait for response to be written to socket.
776  //! \{
777  Derived &
778  write_http_response_timelimit( std::chrono::steady_clock::duration d ) &
779  {
781  return reference_to_derived();
782  }
783 
784  Derived &&
785  write_http_response_timelimit( std::chrono::steady_clock::duration d ) &&
786  {
787  return std::move( this->write_http_response_timelimit( std::move( d ) ) );
788  }
789 
792  {
794  }
795  //! \}
796 
797  //! A period of time that is given for a handler to create response.
798  //! \{
799  Derived &
800  handle_request_timeout( std::chrono::steady_clock::duration d ) &
801  {
803  return reference_to_derived();
804  }
805 
806  Derived &&
807  handle_request_timeout( std::chrono::steady_clock::duration d ) &&
808  {
809  return std::move( this->handle_request_timeout( std::move( d ) ) );
810  }
811 
814  {
816  }
817  //! \}
818 
819  //! Max pipelined requests able to receive on single connection.
820  //! \{
821  Derived &
822  max_pipelined_requests( std::size_t mpr ) &
823  {
825  return reference_to_derived();
826  }
827 
828  Derived &&
829  max_pipelined_requests( std::size_t mpr ) &&
830  {
831  return std::move( this->max_pipelined_requests( mpr ) );
832  }
833 
834  std::size_t
836  {
838  }
839  //! \}
840 
841 
842  //! Request handler.
843  //! \{
845 
846  Derived &
847  request_handler( std::unique_ptr< request_handler_t > handler ) &
848  {
850  return reference_to_derived();
851  }
852 
853  template< typename... Params >
854  Derived &
855  request_handler( Params &&... params ) &
856  {
857  return set_unique_instance(
859  std::forward< Params >( params )... );
860  }
861 
862 
863  template< typename... Params >
864  Derived &&
865  request_handler( Params &&... params ) &&
866  {
867  return std::move( this->request_handler( std::forward< Params >( params )... ) );
868  }
869 
872  {
873  return ensure_created(
875  "request handler must be set" );
876  }
877  //! \}
878 
879 
880  //! \name Timers manager.
881  //! \{
882  /*!
883  * @brief Short alias for timer_manager type.
884  */
885  using timer_manager_t = typename Traits::timer_manager_t;
886  /*!
887  * @brief Short alias for type of a factory that creates
888  * instances of timer_manager.
889  */
890  using timer_factory_t = typename timer_manager_t::factory_t;
891 
892  /*!
893  * @brief Creates a factory object that will be used for creation
894  * of an actual timer_manager instance.
895  *
896  * An instance of @a Traits::timer_manager_t::factory_t is created
897  * dynamically. All @a params are passed to std::make_unique call
898  * and will be forwarded to the constructor of @a timer_factory_t.
899  *
900  * Usage example:
901  * @code
902  * struct my_traits : public restinio::traits_t<
903  * restinio::asio_timer_manager_t, my_logger >
904  * {
905  * using request_handler_t = ...; // Some request handler type.
906  * };
907  * ...
908  * restinio::run(
909  * restinio::on_this_thread<my_traits>()
910  * .port(8080)
911  * .address("localhost")
912  * .timer_manager(std::chrono::milliseconds{250})
913  * .request_handler(...));
914  * @endcode
915  */
916  template< typename... Params >
917  Derived &
918  timer_manager( Params &&... params ) &
919  {
920  return set_unique_instance(
922  std::forward< Params >( params )... );
923  }
924 
925  /*!
926  * @brief Creates a factory object that will be used for creation
927  * of an actual timer_manager instance.
928  *
929  * For more information and usage example see the documentation
930  * for another overload.
931  */
932  template< typename... Params >
933  Derived &&
934  timer_manager( Params &&... params ) &&
935  {
936  return std::move( this->timer_manager( std::forward< Params >( params )... ) );
937  }
938 
941  {
942  return ensure_created(
944  "timer manager is not set" );
945  }
946  //! \}
947 
948  //! \name Logger.
949  //! \{
950  using logger_t = typename Traits::logger_t;
951 
952  template< typename... Params >
953  Derived &
954  logger( Params &&... params ) &
955  {
956  return set_unique_instance(
957  m_logger,
958  std::forward< Params >( params )... );
959  }
960 
961  template< typename... Params >
962  Derived &&
963  logger( Params &&... params ) &&
964  {
965  return std::move( this->logger( std::forward< Params >( params )... ) );
966  }
967 
970  {
971  return ensure_created(
972  std::move( m_logger ),
973  "logger must be set" );
974  }
975  //! \}
976 
977  //! \name Acceptor options setter.
978  //! \{
979  Derived &
980  acceptor_options_setter( acceptor_options_setter_t aos ) &
981  {
982  if( !aos )
983  throw exception_t{ "acceptor options setter cannot be empty" };
984 
985  return set_unique_instance(
987  std::move( aos ) );
988  }
989 
990  Derived &&
991  acceptor_options_setter( acceptor_options_setter_t aos ) &&
992  {
993  return std::move( this->acceptor_options_setter( std::move( aos ) ) );
994  }
995 
998  {
999  return ensure_created(
1001  "acceptor options setter must be set" );
1002  }
1003  //! \}
1004 
1005  //! \name Socket options setter.
1006  //! \{
1007  Derived &
1008  socket_options_setter( socket_options_setter_t sos ) &
1009  {
1010  if( !sos )
1011  throw exception_t{ "socket options setter cannot be empty" };
1012 
1013  return set_unique_instance(
1015  std::move( sos ) );
1016  }
1017 
1018  Derived &&
1019  socket_options_setter( socket_options_setter_t sos ) &&
1020  {
1021  return std::move( this->socket_options_setter( std::move( sos ) ) );
1022  }
1023 
1026  {
1027  return ensure_created(
1029  "socket options setter must be set" );
1030  }
1031  //! \}
1032 
1033  //! Max number of running concurrent accepts.
1034  /*!
1035  When running server on N threads
1036  then up to N accepts can be handled concurrently.
1037  */
1038  //! \{
1039  Derived &
1040  concurrent_accepts_count( std::size_t n ) &
1041  {
1042  if( 0 == n || 1024 < n )
1043  throw exception_t{
1044  fmt::format(
1046  "invalid value for number of cuncurrent connects: {}" ),
1047  n ) };
1048 
1050  return reference_to_derived();
1051  }
1052 
1053  Derived &&
1054  concurrent_accepts_count( std::size_t n ) &&
1055  {
1056  return std::move( this->concurrent_accepts_count( n ) );
1057  }
1058 
1059  std::size_t
1061  {
1063  }
1064  //! \}
1065 
1066  //! Do separate an accept operation and connection instantiation.
1067  /*!
1068  For the cases when a lot of connection can be fired by clients
1069  in a short time interval, it is vital to accept connections
1070  and initiate new accept operations as quick as possible.
1071  So creating connection instance that involves allocations
1072  and initialization can be done in a context that
1073  is independent to acceptors one.
1074  */
1075  //! \{
1076  Derived &
1077  separate_accept_and_create_connect( bool do_separate ) & noexcept
1078  {
1080  return reference_to_derived();
1081  }
1082 
1083  Derived &&
1084  separate_accept_and_create_connect( bool do_separate ) && noexcept
1085  {
1087  }
1088 
1089  bool
1091  {
1093  }
1094  //! \}
1095 
1096  //! \name Cleanup function.
1097  //! \{
1098  template< typename Func >
1099  Derived &
1100  cleanup_func( Func && func ) &
1101  {
1103  return reference_to_derived();
1104  }
1105 
1106  template< typename Func >
1107  Derived &&
1108  cleanup_func( Func && func ) &&
1109  {
1110  return std::move(this->cleanup_func( std::forward<Func>(func) ));
1111  }
1112 
1113  /*!
1114  * @note
1115  * This method is intended to be used by RESTinio and it can be
1116  * changed or removed in future versions of RESTinio without any
1117  * notice.
1118  */
1119  [[nodiscard]]
1122  {
1123  return std::move(m_cleanup_functor);
1124  }
1125  //! \}
1126 
1127  /*!
1128  * @brief Setter for connection state listener.
1129  *
1130  * @note connection_state_listener() method should be called if
1131  * user specify its type for connection_state_listener_t traits.
1132  * For example:
1133  * @code
1134  * class my_state_listener_t {
1135  * ...
1136  * public:
1137  * ...
1138  * void state_changed(const restinio::connection_state::notice_t & notice) noexcept {
1139  * ...
1140  * }
1141  * };
1142  *
1143  * struct my_traits_t : public restinio::default_traits_t {
1144  * using connection_state_listener_t = my_state_listener_t;
1145  * };
1146  *
1147  * restinio::server_setting_t<my_traits_t> settings;
1148  * setting.connection_state_listener( std::make_shared<my_state_listener_t>(...) );
1149  * ...
1150  * @endcode
1151  *
1152  * @attention This method can't be called if the default no-op
1153  * state listener is used in server traits.
1154  *
1155  * @since v.0.5.1
1156  */
1157  Derived &
1159  std::shared_ptr< typename Traits::connection_state_listener_t > listener ) &
1160  {
1161  static_assert(
1163  "connection_state_listener(listener) can't be used "
1164  "for the default connection_state::noop_listener_t" );
1165 
1167  return reference_to_derived();
1168  }
1169 
1170  /*!
1171  * @brief Setter for connection state listener.
1172  *
1173  * @note connection_state_listener() method should be called if
1174  * user specify its type for connection_state_listener_t traits.
1175  * For example:
1176  * @code
1177  * class my_state_listener_t {
1178  * ...
1179  * public:
1180  * ...
1181  * void state_changed(const restinio::connection_state::notice_t & notice) noexcept {
1182  * ...
1183  * }
1184  * };
1185  *
1186  * struct my_traits_t : public restinio::default_traits_t {
1187  * using connection_state_listener_t = my_state_listener_t;
1188  * };
1189  *
1190  * restinio::run( restinio::on_this_thread<my_traits_t>()
1191  * .connection_state_listener( std::make_shared<my_state_listener_t>(...) )
1192  * .port(...)
1193  * ...);
1194  * @endcode
1195  *
1196  * @attention This method can't be called if the default no-op
1197  * state listener is used in server traits.
1198  *
1199  * @since v.0.5.1
1200  */
1201  Derived &&
1203  std::shared_ptr< typename Traits::connection_state_listener_t > listener ) &&
1204  {
1205  return std::move(this->connection_state_listener(
1206  std::move(listener)));
1207  }
1208 
1209  /*!
1210  * @brief Get reference to connection state listener.
1211  *
1212  * @attention This method can't be called if the default no-op
1213  * state listener is used in server traits.
1214  *
1215  * @since v.0.5.1
1216  */
1217  const std::shared_ptr< typename Traits::connection_state_listener_t > &
1218  connection_state_listener() const noexcept
1219  {
1220  static_assert(
1222  "connection_state_listener() can't be used "
1223  "for the default connection_state::noop_listener_t" );
1224 
1225  return this->m_connection_state_listener;
1226  }
1227 
1228  /*!
1229  * @brief Internal method for checking presence of state listener
1230  * object.
1231  *
1232  * If a user specifies custom state listener type but doesn't
1233  * set a pointer to listener object that method throws an exception.
1234  *
1235  * @since v.0.5.1
1236  */
1237  void
1239  {
1241  }
1242 
1243  /*!
1244  * @brief Setter for IP-blocker.
1245  *
1246  * @note ip_blocker() method should be called if
1247  * user specify its type for ip_blocker_t traits.
1248  * For example:
1249  * @code
1250  * class my_ip_blocker_t {
1251  * ...
1252  * public:
1253  * ...
1254  * restinio::ip_blocker::inspection_result_t
1255  * inspect(const restinio::ip_blocker::incoming_info_t & info) noexcept {
1256  * ...
1257  * }
1258  * };
1259  *
1260  * struct my_traits_t : public restinio::default_traits_t {
1261  * using ip_blocker_t = my_ip_blocker_t;
1262  * };
1263  *
1264  * restinio::server_setting_t<my_traits_t> settings;
1265  * setting.ip_blocker( std::make_shared<my_ip_blocker_t>(...) );
1266  * ...
1267  * @endcode
1268  *
1269  * @attention This method can't be called if the default no-op
1270  * IP-blocker is used in server traits.
1271  *
1272  * @since v.0.5.1
1273  */
1274  Derived &
1276  std::shared_ptr< typename Traits::ip_blocker_t > blocker ) &
1277  {
1278  static_assert(
1280  "ip_blocker(blocker) can't be used "
1281  "for the default ip_blocker::noop_ip_blocker_t" );
1282 
1283  this->m_ip_blocker = std::move(blocker);
1284  return reference_to_derived();
1285  }
1286 
1287  /*!
1288  * @brief Setter for IP-blocker.
1289  *
1290  * @note ip_blocker() method should be called if
1291  * user specify its type for ip_blocker_t traits.
1292  * For example:
1293  * @code
1294  * class my_ip_blocker_t {
1295  * ...
1296  * public:
1297  * ...
1298  * restinio::ip_blocker::inspection_result_t
1299  * inspect(const restinio::ip_blocker::incoming_info_t & info) noexcept {
1300  * ...
1301  * }
1302  * };
1303  *
1304  * struct my_traits_t : public restinio::default_traits_t {
1305  * using ip_blocker_t = my_ip_blocker_t;
1306  * };
1307  *
1308  * restinio::run( restinio::on_this_thread<my_traits_t>()
1309  * .ip_blocker( std::make_shared<my_ip_blocker_t>(...) )
1310  * .port(...)
1311  * ...);
1312  * @endcode
1313  *
1314  * @attention This method can't be called if the default no-op
1315  * state listener is used in server traits.
1316  *
1317  * @since v.0.5.1
1318  */
1319  Derived &&
1321  std::shared_ptr< typename Traits::ip_blocker_t > blocker ) &&
1322  {
1323  return std::move(this->ip_blocker(std::move(blocker)));
1324  }
1325 
1326  /*!
1327  * @brief Get reference to IP-blocker.
1328  *
1329  * @attention This method can't be called if the default no-op
1330  * IP-blocker is used in server traits.
1331  *
1332  * @since v.0.5.1
1333  */
1334  const std::shared_ptr< typename Traits::ip_blocker_t > &
1335  ip_blocker() const noexcept
1336  {
1337  static_assert(
1339  "ip_blocker() can't be used "
1340  "for the default ip_blocker::noop_ip_blocker_t" );
1341 
1342  return this->m_ip_blocker;
1343  }
1344 
1345  /*!
1346  * @brief Internal method for checking presence of IP-blocker object.
1347  *
1348  * If a user specifies custom IP-blocker type but doesn't
1349  * set a pointer to blocker object that method throws an exception.
1350  *
1351  * @since v.0.5.1
1352  */
1353  void
1355  {
1357  }
1358 
1359  // Acceptor post-bind hook.
1360  /*!
1361  * @brief A setter for post-bind callback.
1362  *
1363  * Usage example:
1364  * @code
1365  * using my_server_t = restinio::http_server_t< my_server_traits_t >;
1366  * my_server_t server{
1367  * restinio::own_io_context(),
1368  * [](auto & settings) {
1369  * settings.port(...);
1370  * settings.address(...);
1371  * settings.acceptor_post_bind_hook(
1372  * [](asio::ip::tcp::acceptor & acceptor) {
1373  * ...
1374  * })
1375  * settings.request_handler(...);
1376  * ...
1377  * }
1378  * };
1379  * @endcode
1380  *
1381  * @since v.0.6.11
1382  */
1383  Derived &
1384  acceptor_post_bind_hook( acceptor_post_bind_hook_t hook ) &
1385  {
1386  if( !hook )
1387  throw exception_t{ "acceptor_post_bind_hook cannot be empty" };
1388 
1390  return reference_to_derived();
1391  }
1392 
1393  /*!
1394  * @brief A setter for post-bind callback.
1395  *
1396  * Usage example:
1397  * @code
1398  * restinio::run(
1399  * restinio::on_this_thread()
1400  * .port(...)
1401  * .address(...)
1402  * .acceptor_post_bind_hook(
1403  * [](asio::ip::tcp::acceptor & acceptor) {
1404  * ...
1405  * })
1406  * .request_handler(...)
1407  * );
1408  * @endcode
1409  *
1410  * @since v.0.6.11
1411  */
1412  Derived &&
1413  acceptor_post_bind_hook( acceptor_post_bind_hook_t hook ) &&
1414  {
1415  return std::move(this->acceptor_post_bind_hook( std::move(hook) ));
1416  }
1417 
1418  /*!
1419  * @brief A getter for post-bind callback.
1420  *
1421  * @note
1422  * This method is intended to be used by RESTinio and it can be
1423  * changed or removed in future versions of RESTinio without any
1424  * notice.
1425  *
1426  * @since v.0.6.11
1427  */
1428  [[nodiscard]]
1431  {
1433  }
1434 
1435  /*!
1436  * @brief Getter of optional limits for incoming HTTP messages.
1437  *
1438  * In v.0.6.12 if the limits for incoming HTTP messages are not
1439  * set explicitely then a defaultly constructed instance of
1440  * incoming_http_msg_limits_t is used. This means the absence of
1441  * any limits.
1442  *
1443  * But if the limits were set by using appropriate setters then
1444  * a reference to an instance with user-defined limits is returned.
1445  *
1446  * @since v.0.6.12
1447  */
1448  [[nodiscard]]
1450  incoming_http_msg_limits() const noexcept
1451  {
1453  }
1454 
1455  /*!
1456  * @brief Setter of optional limits for incoming HTTP messages.
1457  *
1458  * Usage example:
1459  * @code
1460  * struct my_traits : public restinio::default_traits_t { ... };
1461  * restinio::server_settings_t<my_traits> settings;
1462  * settings.incoming_http_msg_limits(
1463  * restinio::incoming_http_msg_limits_t{}
1464  * .max_url_size(8000u)
1465  * .max_field_name_size(2048u)
1466  * .max_field_value_size(4096u)
1467  * );
1468  * ...
1469  * auto server = restinio::run_async(
1470  * restinio::own_io_context(),
1471  * std::move(settings),
1472  * std::thread::hardware_concurrency());
1473  * @endcode
1474  *
1475  * @since v.0.6.12
1476  */
1477  Derived &
1479  const incoming_http_msg_limits_t & limits ) & noexcept
1480  {
1482  return reference_to_derived();
1483  }
1484 
1485  /*!
1486  * @brief Setter of optional limits for incoming HTTP messages.
1487  *
1488  * Usage example:
1489  * @code
1490  * struct my_traits : public restinio::default_traits_t { ... };
1491  * ...
1492  * auto server = restinio::run_async(
1493  * restinio::own_io_context(),
1494  * restinio::server_settings_t<my_traits>{}
1495  * ...
1496  * .incoming_http_msg_limits(
1497  * restinio::incoming_http_msg_limits_t{}
1498  * .max_url_size(8000u)
1499  * .max_field_name_size(2048u)
1500  * .max_field_value_size(4096u)
1501  * ),
1502  * std::thread::hardware_concurrency());
1503  * @endcode
1504  *
1505  * @since v.0.6.12
1506  */
1507  Derived &&
1509  const incoming_http_msg_limits_t & limits ) && noexcept
1510  {
1511  return std::move(this->incoming_http_msg_limits(limits));
1512  }
1513 
1514  /*!
1515  * @brief Setter for connection count limit.
1516  *
1517  * @note
1518  * This setter can be called only if the usage of connection
1519  * count limit is turned on explicitly.
1520  *
1521  * Usage example:
1522  * @code
1523  * struct my_traits : public restinio::default_traits_t {
1524  * static constexpr bool use_connection_count_limiter = true;
1525  * };
1526  * ...
1527  * restinio::server_settings_t<my_traits> settings;
1528  * settings.max_parallel_connections( 1000u );
1529  * ...
1530  * auto server = restinio::run_async(
1531  * restinio::own_io_context(),
1532  * std::move(settings),
1533  * std::thread::hardware_concurrency());
1534  * @endcode
1535  *
1536  * @since v.0.6.12
1537  */
1538  Derived &
1539  max_parallel_connections( std::size_t value ) & noexcept
1540  {
1541  static_assert(
1543  "max_parallel_connections(value) can't be used "
1544  "for the noop_connection_count_limiter_t" );
1545 
1547  return reference_to_derived();
1548  }
1549 
1550  /*!
1551  * @brief Setter for connection count limit.
1552  *
1553  * @note
1554  * This setter can be called only if the usage of connection
1555  * count limit is turned on explicitly.
1556  *
1557  * Usage example:
1558  * @code
1559  * struct my_traits : public restinio::default_traits_t {
1560  * static constexpr bool use_connection_count_limiter = true;
1561  * };
1562  * ...
1563  * auto server = restinio::run_async(
1564  * restinio::own_io_context(),
1565  * restinio::server_settings_t<my_traits>{}
1566  * ...
1567  * .max_parallel_connections(1000u),
1568  * std::thread::hardware_concurrency());
1569  * @endcode
1570  *
1571  * @since v.0.6.12
1572  */
1573  Derived &&
1574  max_parallel_connections( std::size_t value ) && noexcept
1575  {
1576  return std::move(this->max_parallel_connections( value ));
1577  }
1578 
1580 
1581  /*!
1582  * @name User-data factory.
1583  * @{
1584  */
1585  /*!
1586  * @brief The actual type of extra-data-factory.
1587  * @since v.0.6.13
1588  */
1589  using extra_data_factory_t = typename Traits::extra_data_factory_t;
1590  /*!
1591  * @brief Type of shared-pointer to extra-data-factory.
1592  * @since v.0.6.13
1593  */
1595 
1596  /*!
1597  * @brief Setter for extra-data-factory.
1598  *
1599  * Usage example:
1600  * @code
1601  * class my_extra_data_factory {
1602  * ... // Some factory's data.
1603  * public:
1604  * struct data_t {...};
1605  *
1606  * my_extra_data_factory(...) {...}
1607  *
1608  * void make_within(restinio::extra_data_buffer_t<data_t> buf) {
1609  * new(buf.get()) data_t{...};
1610  * }
1611  * };
1612  *
1613  * struct my_traits : public restinio::default_traits_t {
1614  * using extra_data_factory_t = my_extra_data_factory;
1615  * };
1616  *
1617  * restinio::server_settings_t<my_traits> settings;
1618  * ...
1619  * settings.extra_data_factory(std::make_shared<my_extra_data_factory>(...));
1620  * ...
1621  * auto server = restinio::run_async(
1622  * restinio::own_io_context(),
1623  * std::move(settings),
1624  * std::thread::hardware_concurrency());
1625  * @endcode
1626  *
1627  * @since v.0.6.13
1628  */
1629  Derived &
1631  extra_data_factory_handle_t factory ) &
1632  {
1634  return reference_to_derived();
1635  }
1636 
1637  /*!
1638  * @brief Setter for extra-data-factory.
1639  *
1640  * Usage example:
1641  * @code
1642  * class my_extra_data_factory {
1643  * ... // Some factory's data.
1644  * public:
1645  * struct data_t {...};
1646  *
1647  * my_extra_data_factory(...) {...}
1648  *
1649  * void make_within(restinio::extra_data_buffer_t<data_t> buf) {
1650  * new(buf.get()) data_t{...};
1651  * }
1652  * };
1653  *
1654  * struct my_traits : public restinio::default_traits_t {
1655  * using extra_data_factory_t = my_extra_data_factory;
1656  * };
1657  *
1658  * auto server = restinio::run_async(
1659  * restinio::own_io_context(),
1660  * restinio::server_settings_t<my_traits>{}
1661  * .extra_data_factory(std::make_shared<my_extra_data_factory>(...))
1662  * ...
1663  * ,
1664  * std::thread::hardware_concurrency());
1665  * @endcode
1666  *
1667  * @since v.0.6.13
1668  */
1669  Derived &&
1671  extra_data_factory_handle_t factory ) &&
1672  {
1673  return std::move(this->extra_data_factory( std::move(factory) ));
1674  }
1675 
1676  /*!
1677  * @brief Extractor for extra-data-factory.
1678  * @since v.0.6.13
1679  */
1680  [[nodiscard]]
1683  {
1684  return ensure_created(
1685  std::move(this->m_extra_data_factory),
1686  "extra_data_factory is not set" );
1687  }
1688  /*!
1689  * @}
1690  */
1691 
1692  private:
1693  Derived &
1695  {
1696  return static_cast<Derived &>(*this);
1697  }
1698 
1699  template< typename Target, typename... Params >
1700  Derived &
1701  set_unique_instance( std::unique_ptr< Target > & t, Params &&... params )
1702  {
1703  t =
1704  std::make_unique< Target >(
1705  std::forward< Params >( params )... );
1706 
1707  return reference_to_derived();
1708  }
1709 
1710  template< typename Target, typename... Params >
1711  Derived &
1712  set_shared_instance( std::shared_ptr< Target > & t, Params &&... params )
1713  {
1714  t =
1715  std::make_shared< Target >(
1716  std::forward< Params >( params )... );
1717 
1718  return reference_to_derived();
1719  }
1720 
1721  //! Server endpoint.
1722  //! \{
1725  /*!
1726  * @note
1727  * This member has type address_variant_t since v.0.6.11
1728  */
1730  //! \}
1731 
1732  //! Size of buffer for io operations.
1733  std::size_t m_buffer_size{ 4 * 1024 };
1734 
1735  //! Operations timeouts.
1736  //! \{
1739 
1742 
1745  //! \}
1746 
1747  //! Max pipelined requests to receive on single connection.
1749 
1750  //! Request handler.
1752 
1753  //! Timers factory.
1755 
1756  //! Logger.
1758 
1759  //! Acceptor options setter.
1761 
1762  //! A hook to be called just after a successful call to bind for acceptor.
1763  /*!
1764  * An empty lambda is used by default.
1765  *
1766  * @since v.0.6.11
1767  */
1769  [](asio_ns::ip::tcp::acceptor &) {}
1770  };
1771 
1772  //! Socket options setter.
1774 
1776 
1777  //! Do separate an accept operation and connection instantiation.
1779 
1780  //! Optional cleanup functor.
1782 
1783  /*!
1784  * @brief Limits for incoming HTTP messages.
1785  *
1786  * @since v.0.6.12
1787  */
1789 
1790  /*!
1791  * @brief User-data-factory for server.
1792  *
1793  * @since v.0.6.13
1794  */
1796 };
1797 
1798 //
1799 // server_settings_t
1800 //
1801 
1802 //! A fluent style interface for setting http server params.
1803 template<typename Traits = default_traits_t>
1805  : public basic_server_settings_t< server_settings_t<Traits>, Traits >
1806 {
1807  using base_type_t = basic_server_settings_t<
1808  server_settings_t<Traits>, Traits>;
1809 public:
1810  using base_type_t::base_type_t;
1811 };
1812 
1813 template < typename Traits, typename Configurator >
1814 auto
1815 exec_configurator( Configurator && configurator )
1816 {
1817  server_settings_t< Traits > result;
1818 
1819  configurator( result );
1820 
1821  return result;
1822 }
1823 
1824 } /* namespace restinio */
Derived && separate_accept_and_create_connect(bool do_separate) &&noexcept
Definition: settings.hpp:1084
Derived && extra_data_factory(extra_data_factory_handle_t factory) &&
Setter for extra-data-factory.
Definition: settings.hpp:1670
std::unique_ptr< logger_t > logger()
Definition: settings.hpp:969
Derived & address(asio_ns::ip::address addr) &
Definition: settings.hpp:687
Derived && timer_manager(Params &&... params) &&
Creates a factory object that will be used for creation of an actual timer_manager instance...
Definition: settings.hpp:934
Derived & buffer_size(std::size_t s) &
Size of buffer for io operations.
Definition: settings.hpp:729
static constexpr bool has_actual_ip_blocker
Definition: settings.hpp:390
Basic container for http_server settings.
Definition: settings.hpp:548
auto create_default_unique_object_instance(std::true_type)
Definition: settings.hpp:40
std::size_t m_max_parallel_connections
Actual value of the limit.
Definition: settings.hpp:489
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:778
std::size_t max_parallel_connections() const noexcept
Definition: settings.hpp:494
void set_max_parallel_connections(std::size_t v) noexcept
Definition: settings.hpp:500
std::size_t concurrent_accepts_count() const
Definition: settings.hpp:1060
Derived && write_http_response_timelimit(std::chrono::steady_clock::duration d) &&
Definition: settings.hpp:785
std::unique_ptr< logger_t > m_logger
Logger.
Definition: settings.hpp:1757
std::unique_ptr< request_handler_t > m_request_handler
Request handler.
Definition: settings.hpp:1751
void get_option(Option &option, asio_ns::error_code &ec)
Definition: settings.hpp:215
std::unique_ptr< acceptor_options_setter_t > m_acceptor_options_setter
Acceptor options setter.
Definition: settings.hpp:1760
Derived & ip_blocker(std::shared_ptr< typename Traits::ip_blocker_t > blocker) &
Setter for IP-blocker.
Definition: settings.hpp:1275
Derived && concurrent_accepts_count(std::size_t n) &&
Definition: settings.hpp:1054
bool separate_accept_and_create_connect() const noexcept
Definition: settings.hpp:1090
void set_option(const Option &option, asio_ns::error_code &ec)
Definition: settings.hpp:201
void check_valid_ip_blocker_pointer() const
Checks that pointer to IP-blocker is not null.
Definition: settings.hpp:397
details::address_variant_t m_address
Definition: settings.hpp:1729
void check_valid_connection_state_listener_pointer() const
Checks that pointer to state listener is not null.
Definition: settings.hpp:333
Derived & request_handler(std::unique_ptr< request_handler_t > handler) &
Definition: settings.hpp:847
A special type for holding the value of maximum allowed count of parallel connections.
Definition: settings.hpp:480
Derived & logger(Params &&... params) &
Definition: settings.hpp:954
Derived & concurrent_accepts_count(std::size_t n) &
Max number of running concurrent accepts.
Definition: settings.hpp:1040
acceptor_options_t(asio_ns::ip::tcp::acceptor &acceptor)
Definition: settings.hpp:186
static constexpr bool has_actual_connection_state_listener
Definition: settings.hpp:326
Derived && cleanup_func(Func &&func) &&
Definition: settings.hpp:1108
std::size_t max_pipelined_requests() const
Definition: settings.hpp:835
Derived && acceptor_post_bind_hook(acceptor_post_bind_hook_t hook) &&
A setter for post-bind callback.
Definition: settings.hpp:1413
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
Definition: value_or.hpp:64
std::unique_ptr< request_handler_t > request_handler()
Definition: settings.hpp:871
std::unique_ptr< timer_factory_t > timer_factory()
Definition: settings.hpp:940
auto create_default_unique_object_instance()
Default instantiation for a specific type.
Definition: settings.hpp:69
std::shared_ptr< Ip_Blocker > m_ip_blocker
Definition: settings.hpp:378
Derived && acceptor_options_setter(acceptor_options_setter_t aos) &&
Definition: settings.hpp:991
std::size_t buffer_size() const
Definition: settings.hpp:742
std::uint16_t m_port
Server endpoint.
Definition: settings.hpp:1723
acceptor_post_bind_hook_t m_acceptor_post_bind_hook
A hook to be called just after a successful call to bind for acceptor.
Definition: settings.hpp:1768
Derived && incoming_http_msg_limits(const incoming_http_msg_limits_t &limits) &&noexcept
Setter of optional limits for incoming HTTP messages.
Definition: settings.hpp:1508
Derived & cleanup_func(Func &&func) &
Definition: settings.hpp:1100
Derived & acceptor_options_setter(acceptor_options_setter_t aos) &
Definition: settings.hpp:980
std::size_t m_buffer_size
Size of buffer for io operations.
Definition: settings.hpp:1733
auto create_default_shared_object_instance(std::true_type)
Definition: settings.hpp:55
Derived && connection_state_listener(std::shared_ptr< typename Traits::connection_state_listener_t > listener) &&
Setter for connection state listener.
Definition: settings.hpp:1202
std::unique_ptr< socket_options_setter_t > m_socket_options_setter
Socket options setter.
Definition: settings.hpp:1773
Derived & set_shared_instance(std::shared_ptr< Target > &t, Params &&... params)
Definition: settings.hpp:1712
Derived && read_next_http_message_timelimit(std::chrono::steady_clock::duration d) &&
Definition: settings.hpp:763
A fluent style interface for setting http server params.
Definition: settings.hpp:1804
std::chrono::steady_clock::duration m_write_http_response_timelimit
Definition: settings.hpp:1741
Derived & protocol(asio_ns::ip::tcp p) &
Definition: settings.hpp:605
extra_data_factory_handle_t m_extra_data_factory
User-data-factory for server.
Definition: settings.hpp:1795
const std::shared_ptr< typename Traits::ip_blocker_t > & ip_blocker() const noexcept
Get reference to IP-blocker.
Definition: settings.hpp:1335
Derived & timer_manager(Params &&... params) &
Creates a factory object that will be used for creation of an actual timer_manager instance...
Definition: settings.hpp:918
Derived && max_pipelined_requests(std::size_t mpr) &&
Definition: settings.hpp:829
void ensure_valid_connection_state_listener()
Internal method for checking presence of state listener object.
Definition: settings.hpp:1238
Derived && protocol(asio_ns::ip::tcp p) &&
Definition: settings.hpp:612
Derived && address(asio_ns::ip::address addr) &&
Definition: settings.hpp:709
void ensure_valid_ip_blocker()
Internal method for checking presence of IP-blocker object.
Definition: settings.hpp:1354
Derived & set_unique_instance(std::unique_ptr< Target > &t, Params &&... params)
Definition: settings.hpp:1701
Derived & socket_options_setter(socket_options_setter_t sos) &
Definition: settings.hpp:1008
std::chrono::steady_clock::duration write_http_response_timelimit() const
Definition: settings.hpp:791
basic_server_settings_t(std::uint16_t port=8080, asio_ns::ip::tcp protocol=asio_ns::ip::tcp::v4())
Definition: settings.hpp:574
Derived && logger(Params &&... params) &&
Definition: settings.hpp:963
cleanup_functor_t giveaway_cleanup_func()
Definition: settings.hpp:1121
void set_option(const Option &option)
API for setting/getting options.
Definition: settings.hpp:194
A special class for holding actual connection state listener.
Definition: settings.hpp:322
std::uint16_t port() const
Definition: settings.hpp:599
Derived & read_next_http_message_timelimit(std::chrono::steady_clock::duration d) &
}
Definition: settings.hpp:756
std::chrono::steady_clock::duration m_read_next_http_message_timelimit
Operations timeouts.
Definition: settings.hpp:1738
auto exec_configurator(Configurator &&configurator)
Definition: settings.hpp:1815
A special class for holding actual IP-blocker object.
Definition: settings.hpp:373
std::size_t m_max_pipelined_requests
Max pipelined requests to receive on single connection.
Definition: settings.hpp:1748
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:800
Derived & incoming_http_msg_limits(const incoming_http_msg_limits_t &limits) &noexcept
Setter of optional limits for incoming HTTP messages.
Definition: settings.hpp:1478
An adapter for setting acceptor options before running server.
Definition: settings.hpp:183
std::unique_ptr< socket_options_setter_t > socket_options_setter()
Definition: settings.hpp:1025
Derived & extra_data_factory(extra_data_factory_handle_t factory) &
Setter for extra-data-factory.
Definition: settings.hpp:1630
incoming_http_msg_limits_t m_incoming_http_msg_limits
Limits for incoming HTTP messages.
Definition: settings.hpp:1788
Derived && socket_options_setter(socket_options_setter_t sos) &&
Definition: settings.hpp:1019
const std::shared_ptr< typename Traits::connection_state_listener_t > & connection_state_listener() const noexcept
Get reference to connection state listener.
Definition: settings.hpp:1218
Derived && buffer_size(std::size_t s) &&
Definition: settings.hpp:736
std::chrono::steady_clock::duration m_handle_request_timeout
Definition: settings.hpp:1744
Derived & port(std::uint16_t p) &
Server endpoint.
Definition: settings.hpp:585
cleanup_functor_t m_cleanup_functor
Optional cleanup functor.
Definition: settings.hpp:1781
Derived & request_handler(Params &&... params) &
Definition: settings.hpp:855
const incoming_http_msg_limits_t & incoming_http_msg_limits() const noexcept
Getter of optional limits for incoming HTTP messages.
Definition: settings.hpp:1450
Derived && request_handler(Params &&... params) &&
Definition: settings.hpp:865
Derived && max_parallel_connections(std::size_t value) &&noexcept
Setter for connection count limit.
Definition: settings.hpp:1574
extra_data_factory_handle_t giveaway_extra_data_factory() const noexcept
Extractor for extra-data-factory.
Definition: settings.hpp:1682
Derived && port(std::uint16_t p) &&
Definition: settings.hpp:592
bool m_separate_accept_and_create_connect
Do separate an accept operation and connection instantiation.
Definition: settings.hpp:1778
Derived && ip_blocker(std::shared_ptr< typename Traits::ip_blocker_t > blocker) &&
Setter for IP-blocker.
Definition: settings.hpp:1320
acceptor_post_bind_hook_t giveaway_acceptor_post_bind_hook()
A getter for post-bind callback.
Definition: settings.hpp:1430
Derived & max_pipelined_requests(std::size_t mpr) &
Max pipelined requests able to receive on single connection.
Definition: settings.hpp:822
Derived & separate_accept_and_create_connect(bool do_separate) &noexcept
Do separate an accept operation and connection instantiation.
Definition: settings.hpp:1077
std::unique_ptr< acceptor_options_setter_t > acceptor_options_setter()
Definition: settings.hpp:997
Derived && handle_request_timeout(std::chrono::steady_clock::duration d) &&
Definition: settings.hpp:807
asio_ns::ip::tcp protocol() const
Definition: settings.hpp:619
Derived & max_parallel_connections(std::size_t value) &noexcept
Setter for connection count limit.
Definition: settings.hpp:1539
Derived & acceptor_post_bind_hook(acceptor_post_bind_hook_t hook) &
A setter for post-bind callback.
Definition: settings.hpp:1384
asio_ns::ip::tcp::acceptor & m_acceptor
Definition: settings.hpp:222
A special indicator for the case when IP address for a server is not set explicitly.
Definition: settings.hpp:448
Derived & connection_state_listener(std::shared_ptr< typename Traits::connection_state_listener_t > listener) &
Setter for connection state listener.
Definition: settings.hpp:1158
std::shared_ptr< Listener > m_connection_state_listener
Definition: settings.hpp:324
std::chrono::steady_clock::duration read_next_http_message_timelimit() const
Definition: settings.hpp:769
std::unique_ptr< timer_factory_t > m_timer_factory
Timers factory.
Definition: settings.hpp:1754
void get_option(Option &option)
Definition: settings.hpp:208
std::chrono::steady_clock::duration handle_request_timeout() const
Definition: settings.hpp:813
const details::address_variant_t & address() const
Definition: settings.hpp:716