RESTinio
common_types.hpp
Go to the documentation of this file.
1 /*
2  restinio
3 */
4 
5 /*!
6  Restinio common types.
7 */
8 
9 #pragma once
10 
11 #include <cstdint>
12 
13 #include <restinio/asio_include.hpp>
14 
15 namespace restinio
16 {
17 
18 //! Request handling status.
19 /*!
20  If handler handles request it must return accepted.
21 
22  If handler refuses to handle request
23  it must return rejected.
24 */
26 {
27  //! Request accepted for handling.
28  accepted,
29 
30  //! Request wasn't accepted for handling.
31  rejected,
32 
33  //! The request wasn't handled. If there is another handler to
34  //! be tried it should be tried. Otherwise the request has to
35  //! be rejected.
36  //!
37  //! @since v.0.6.13.
39 };
40 
41 //! @name Helper funcs for working with request_handling_status_t
42 //! \see request_handling_status_t.
43 ///@{
44 [[nodiscard]]
46 request_accepted() noexcept
47 {
49 }
50 
51 [[nodiscard]]
53 request_rejected() noexcept
54 {
56 }
57 
58 /*!
59  * @since v.0.6.13
60  */
61 [[nodiscard]]
64 {
66 }
67 ///@}
68 
69 //! Request id in scope of single connection.
70 using request_id_t = unsigned int;
71 
72 //! Attribute for parts.
74 {
75  //! Intermediate parts (more parts of response to follow).
77  //! Final parts (response ands with these parts).
79 };
80 
81 inline std::ostream &
83 {
84  if( response_parts_attr_t::not_final_parts == attr )
85  o << "not_final_parts";
86  else
87  o << "final_parts";
88 
89  return o;
90 }
91 
92 //! Attribute for parts.
94 {
95  //! This response says to keep connection.
97  //! This response says to close connection.
99 };
100 
101 inline std::ostream &
103 {
104  if( response_connection_attr_t::connection_keepalive == attr )
105  o << "connection_keepalive";
106  else
107  o << "connection_close";
108 
109  return o;
110 }
111 
113 response_connection_attr( bool should_keep_alive )
114 {
115  if( should_keep_alive )
117 
119 }
120 
121 //! Response output flags for buffers commited to response-coordinator
123 {
125  response_parts_attr_t response_parts,
126  response_connection_attr_t response_connection ) noexcept
127  : m_response_parts{ response_parts }
128  , m_response_connection{ response_connection }
129  {}
130 
133 };
134 
135 inline std::ostream &
137 {
138  return o << "{ " << flags.m_response_parts << ", "
139  << flags.m_response_connection << " }";
140 }
141 
142 //
143 // nullable_pointer_t
144 //
145 /*!
146  * @brief Type for pointer that can be nullptr.
147  *
148  * This type is used in methods which return raw pointers. It indicates
149  * that returned value should be checked for nullptr.
150  *
151  * @since v.0.4.9
152  */
153 template< typename T >
154 using nullable_pointer_t = T*;
155 
156 //
157 // not_null_pointer_t
158 //
159 /*!
160  * @brief Type for pointer that is not null by design.
161  *
162  * @note
163  * There is no any compile-time or run-time checks for a value of the pointer.
164  * It is just a flag that we don't expect a nullptr here by design.
165  *
166  * @since v.0.4.9
167  */
168 template< typename T >
169 using not_null_pointer_t = T*;
170 
171 /*!
172  * @brief Type for ID of connection.
173  */
175 
176 //! An alias for endpoint type from Asio.
178 
179 } /* namespace restinio */
response_output_flags_t(response_parts_attr_t response_parts, response_connection_attr_t response_connection) noexcept
std::ostream & operator<<(std::ostream &o, const response_output_flags_t &flags)
This response says to close connection.
Final parts (response ands with these parts).
This response says to keep connection.
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
response_connection_attr_t m_response_connection
Request wasn&#39;t accepted for handling.
response_connection_attr_t response_connection_attr(bool should_keep_alive)
response_connection_attr_t
Attribute for parts.
constexpr request_handling_status_t request_not_handled() noexcept
request_handling_status_t
Request handling status.
std::ostream & operator<<(std::ostream &o, response_parts_attr_t attr)
std::ostream & operator<<(std::ostream &o, response_connection_attr_t attr)
response_parts_attr_t m_response_parts
Intermediate parts (more parts of response to follow).
constexpr request_handling_status_t request_rejected() noexcept
Request accepted for handling.
response_parts_attr_t
Attribute for parts.
Response output flags for buffers commited to response-coordinator.
The request wasn&#39;t handled. If there is another handler to be tried it should be tried. Otherwise the request has to be rejected.
constexpr request_handling_status_t request_accepted() noexcept