16 #include <fmt/format.h> 17 #include <fmt/ostream.h> 19 #include <http_parser.h> 21 #include <restinio/exception.hpp> 22 #include <restinio/string_view.hpp> 23 #include <restinio/optional.hpp> 24 #include <restinio/common_types.hpp> 32 #include "impl/to_lower_lut.ipp" 35 uchar_at(
const char *
const from,
const std::size_t at )
noexcept 37 return static_cast<
unsigned char >( from[ at ] );
51 std::size_t size )
noexcept 53 const unsigned char *
const table = impl::to_lower_lut<
unsigned char >();
55 for( std::size_t i = 0; i < size; ++i )
56 if( table[ impl::uchar_at( a, i ) ] != table[ impl::uchar_at( b, i ) ] )
72 std::size_t b_size )
noexcept 74 if( a_size == b_size )
76 return caseless_cmp( a, b, a_size );
90 return caseless_cmp( a.data(), a.size(), b.data(), b.size() );
96 #define RESTINIO_HTTP_FIELDS_MAP( RESTINIO_GEN ) 97 RESTINIO_GEN( a_im, A-IM ) 98 RESTINIO_GEN( accept, Accept ) 99 RESTINIO_GEN( accept_additions, Accept-Additions ) 100 RESTINIO_GEN( accept_charset, Accept-Charset ) 101 RESTINIO_GEN( accept_datetime, Accept-Datetime ) 102 RESTINIO_GEN( accept_encoding, Accept-Encoding ) 103 RESTINIO_GEN( accept_features, Accept-Features ) 104 RESTINIO_GEN( accept_language, Accept-Language ) 105 RESTINIO_GEN( accept_patch, Accept-Patch ) 106 RESTINIO_GEN( accept_post, Accept-Post ) 107 RESTINIO_GEN( accept_ranges, Accept-Ranges ) 108 RESTINIO_GEN( age, Age ) 109 RESTINIO_GEN( allow, Allow ) 110 RESTINIO_GEN( alpn, ALPN ) 111 RESTINIO_GEN( alt_svc, Alt-Svc ) 112 RESTINIO_GEN( alt_used, Alt-Used ) 113 RESTINIO_GEN( alternates, Alternates ) 114 RESTINIO_GEN( apply_to_redirect_ref, Apply-To-Redirect-Ref ) 115 RESTINIO_GEN( authentication_control, Authentication-Control ) 116 RESTINIO_GEN( authentication_info, Authentication-Info ) 117 RESTINIO_GEN( authorization, Authorization ) 118 RESTINIO_GEN( c_ext, C-Ext ) 119 RESTINIO_GEN( c_man, C-Man ) 120 RESTINIO_GEN( c_opt, C-Opt ) 121 RESTINIO_GEN( c_pep, C-PEP ) 122 RESTINIO_GEN( c_pep_info, C-PEP-Info ) 123 RESTINIO_GEN( cache_control, Cache-Control ) 124 RESTINIO_GEN( caldav_timezones, CalDAV-Timezones ) 125 RESTINIO_GEN( close, Close ) 126 RESTINIO_GEN( content_base, Content-Base ) 127 RESTINIO_GEN( content_disposition, Content-Disposition ) 128 RESTINIO_GEN( content_encoding, Content-Encoding ) 129 RESTINIO_GEN( content_id, Content-ID ) 130 RESTINIO_GEN( content_language, Content-Language ) 131 RESTINIO_GEN( content_location, Content-Location ) 132 RESTINIO_GEN( content_md5, Content-MD5 ) 133 RESTINIO_GEN( content_range, Content-Range ) 134 RESTINIO_GEN( content_script_type, Content-Script-Type ) 135 RESTINIO_GEN( content_style_type, Content-Style-Type ) 136 RESTINIO_GEN( content_type, Content-Type ) 137 RESTINIO_GEN( content_version, Content-Version ) 138 RESTINIO_GEN( cookie, Cookie ) 139 RESTINIO_GEN( cookie2, Cookie2 ) 140 RESTINIO_GEN( dasl, DASL ) 141 RESTINIO_GEN( dav, DAV ) 142 RESTINIO_GEN( date, Date ) 143 RESTINIO_GEN( default_style, Default-Style ) 144 RESTINIO_GEN( delta_base, Delta-Base ) 145 RESTINIO_GEN( depth, Depth ) 146 RESTINIO_GEN( derived_from, Derived-From ) 147 RESTINIO_GEN( destination, Destination ) 148 RESTINIO_GEN( differential_id, Differential-ID ) 149 RESTINIO_GEN( digest, Digest ) 150 RESTINIO_GEN( etag, ETag ) 151 RESTINIO_GEN( expect, Expect ) 152 RESTINIO_GEN( expires, Expires ) 153 RESTINIO_GEN( ext, Ext ) 154 RESTINIO_GEN( forwarded, Forwarded ) 155 RESTINIO_GEN( from, From ) 156 RESTINIO_GEN( getprofile, GetProfile ) 157 RESTINIO_GEN( hobareg, Hobareg ) 158 RESTINIO_GEN( host, Host ) 159 RESTINIO_GEN( http2_settings, HTTP2-Settings ) 160 RESTINIO_GEN( im, IM ) 161 RESTINIO_GEN( if_, If ) 162 RESTINIO_GEN( if_match, If-Match ) 163 RESTINIO_GEN( if_modified_since, If-Modified-Since ) 164 RESTINIO_GEN( if_none_match, If-None-Match ) 165 RESTINIO_GEN( if_range, If-Range ) 166 RESTINIO_GEN( if_schedule_tag_match, If-Schedule-Tag-Match ) 167 RESTINIO_GEN( if_unmodified_since, If-Unmodified-Since ) 168 RESTINIO_GEN( keep_alive, Keep-Alive ) 169 RESTINIO_GEN( label, Label ) 170 RESTINIO_GEN( last_modified, Last-Modified ) 171 RESTINIO_GEN( link, Link ) 172 RESTINIO_GEN( location, Location ) 173 RESTINIO_GEN( lock_token, Lock-Token ) 174 RESTINIO_GEN( man, Man ) 175 RESTINIO_GEN( max_forwards, Max-Forwards ) 176 RESTINIO_GEN( memento_datetime, Memento-Datetime ) 177 RESTINIO_GEN( meter, Meter ) 178 RESTINIO_GEN( mime_version, MIME-Version ) 179 RESTINIO_GEN( negotiate, Negotiate ) 180 RESTINIO_GEN( opt, Opt ) 181 RESTINIO_GEN( optional_www_authenticate, Optional-WWW-Authenticate ) 182 RESTINIO_GEN( ordering_type, Ordering-Type ) 183 RESTINIO_GEN( origin, Origin ) 184 RESTINIO_GEN( overwrite, Overwrite ) 185 RESTINIO_GEN( p3p, P3P ) 186 RESTINIO_GEN( pep, PEP ) 187 RESTINIO_GEN( pics_label, PICS-Label ) 188 RESTINIO_GEN( pep_info, Pep-Info ) 189 RESTINIO_GEN( position, Position ) 190 RESTINIO_GEN( pragma, Pragma ) 191 RESTINIO_GEN( prefer, Prefer ) 192 RESTINIO_GEN( preference_applied, Preference-Applied ) 193 RESTINIO_GEN( profileobject, ProfileObject ) 194 RESTINIO_GEN( protocol, Protocol ) 195 RESTINIO_GEN( protocol_info, Protocol-Info ) 196 RESTINIO_GEN( protocol_query, Protocol-Query ) 197 RESTINIO_GEN( protocol_request, Protocol-Request ) 198 RESTINIO_GEN( proxy_authenticate, Proxy-Authenticate ) 199 RESTINIO_GEN( proxy_authentication_info, Proxy-Authentication-Info ) 200 RESTINIO_GEN( proxy_authorization, Proxy-Authorization ) 201 RESTINIO_GEN( proxy_features, Proxy-Features ) 202 RESTINIO_GEN( proxy_instruction, Proxy-Instruction ) 203 RESTINIO_GEN( public_, Public ) 204 RESTINIO_GEN( public_key_pins, Public-Key-Pins ) 205 RESTINIO_GEN( public_key_pins_report_only, Public-Key-Pins-Report-Only ) 206 RESTINIO_GEN( range, Range ) 207 RESTINIO_GEN( redirect_ref, Redirect-Ref ) 208 RESTINIO_GEN( referer, Referer ) 209 RESTINIO_GEN( retry_after, Retry-After ) 210 RESTINIO_GEN( safe, Safe ) 211 RESTINIO_GEN( schedule_reply, Schedule-Reply ) 212 RESTINIO_GEN( schedule_tag, Schedule-Tag ) 213 RESTINIO_GEN( sec_websocket_accept, Sec-WebSocket-Accept ) 214 RESTINIO_GEN( sec_websocket_extensions, Sec-WebSocket-Extensions ) 215 RESTINIO_GEN( sec_websocket_key, Sec-WebSocket-Key ) 216 RESTINIO_GEN( sec_websocket_protocol, Sec-WebSocket-Protocol ) 217 RESTINIO_GEN( sec_websocket_version, Sec-WebSocket-Version ) 218 RESTINIO_GEN( security_scheme, Security-Scheme ) 219 RESTINIO_GEN( server, Server ) 220 RESTINIO_GEN( set_cookie, Set-Cookie ) 221 RESTINIO_GEN( set_cookie2, Set-Cookie2 ) 222 RESTINIO_GEN( setprofile, SetProfile ) 223 RESTINIO_GEN( slug, SLUG ) 224 RESTINIO_GEN( soapaction, SoapAction ) 225 RESTINIO_GEN( status_uri, Status-URI ) 226 RESTINIO_GEN( strict_transport_security, Strict-Transport-Security ) 227 RESTINIO_GEN( surrogate_capability, Surrogate-Capability ) 228 RESTINIO_GEN( surrogate_control, Surrogate-Control ) 229 RESTINIO_GEN( tcn, TCN ) 230 RESTINIO_GEN( te, TE ) 231 RESTINIO_GEN( timeout, Timeout ) 232 RESTINIO_GEN( topic, Topic ) 233 RESTINIO_GEN( trailer, Trailer ) 234 RESTINIO_GEN( transfer_encoding, Transfer-Encoding ) 235 RESTINIO_GEN( ttl, TTL ) 236 RESTINIO_GEN( urgency, Urgency ) 237 RESTINIO_GEN( uri, URI ) 238 RESTINIO_GEN( upgrade, Upgrade ) 239 RESTINIO_GEN( user_agent, User-Agent ) 240 RESTINIO_GEN( variant_vary, Variant-Vary ) 241 RESTINIO_GEN( vary, Vary ) 242 RESTINIO_GEN( via, Via ) 243 RESTINIO_GEN( www_authenticate, WWW-Authenticate ) 244 RESTINIO_GEN( want_digest, Want-Digest ) 245 RESTINIO_GEN( warning, Warning ) 246 RESTINIO_GEN( x_frame_options, X-Frame-Options ) 248 RESTINIO_GEN( access_control, Access-Control ) 249 RESTINIO_GEN( access_control_allow_credentials, Access-Control-Allow-Credentials ) 250 RESTINIO_GEN( access_control_allow_headers, Access-Control-Allow-Headers ) 251 RESTINIO_GEN( access_control_allow_methods, Access-Control-Allow-Methods ) 252 RESTINIO_GEN( access_control_allow_origin, Access-Control-Allow-Origin ) 253 RESTINIO_GEN( access_control_max_age, Access-Control-Max-Age ) 254 RESTINIO_GEN( access_control_request_method, Access-Control-Request-Method ) 255 RESTINIO_GEN( access_control_request_headers, Access-Control-Request-Headers ) 256 RESTINIO_GEN( compliance, Compliance ) 257 RESTINIO_GEN( content_transfer_encoding, Content-Transfer-Encoding ) 258 RESTINIO_GEN( cost, Cost ) 259 RESTINIO_GEN( ediint_features, EDIINT-Features ) 260 RESTINIO_GEN( message_id, Message-ID ) 261 RESTINIO_GEN( method_check, Method-Check ) 262 RESTINIO_GEN( method_check_expires, Method-Check-Expires ) 263 RESTINIO_GEN( non_compliance, Non-Compliance ) 264 RESTINIO_GEN( optional, Optional ) 265 RESTINIO_GEN( referer_root, Referer-Root ) 266 RESTINIO_GEN( resolution_hint, Resolution-Hint ) 267 RESTINIO_GEN( resolver_location, Resolver-Location ) 268 RESTINIO_GEN( subok, SubOK ) 269 RESTINIO_GEN( subst, Subst ) 270 RESTINIO_GEN( title, Title ) 271 RESTINIO_GEN( ua_color, UA-Color ) 272 RESTINIO_GEN( ua_media, UA-Media ) 273 RESTINIO_GEN( ua_pixels, UA-Pixels ) 274 RESTINIO_GEN( ua_resolution, UA-Resolution ) 275 RESTINIO_GEN( ua_windowpixels, UA-Windowpixels ) 276 RESTINIO_GEN( version, Version ) 277 RESTINIO_GEN( x_device_accept, X-Device-Accept ) 278 RESTINIO_GEN( x_device_accept_charset, X-Device-Accept-Charset ) 279 RESTINIO_GEN( x_device_accept_encoding, X-Device-Accept-Encoding ) 280 RESTINIO_GEN( x_device_accept_language, X-Device-Accept-Language ) 281 RESTINIO_GEN( x_device_user_agent, X-Device-User-Agent ) 296 #define RESTINIO_HTTP_FIELD_GEN( name, ignored ) name, 298 #undef RESTINIO_HTTP_FIELD_GEN 315 const char * field_name = field.data();
316 const std::size_t field_name_size = field.size();
318 #define RESTINIO_HTTP_CHECK_FOR_FIELD( field_id, candidate_field_name ) 319 if( caseless_cmp(field_name, #candidate_field_name , field_name_size ) ) 320 return http_field_t:: field_id; 324 switch( field_name_size )
604 #undef RESTINIO_HTTP_CHECK_FOR_FIELD 617 const char * result =
"";
620 #define RESTINIO_HTTP_FIELD_STR_GEN( name, string_name ) 621 case http_field_t::name: result = #string_name; break; 624 #undef RESTINIO_HTTP_FIELD_STR_GEN 661 string_view_t value )
677 string_view_t value )
690 m_name = std::move( n );
691 m_field_id = string_to_field( m_name );
697 m_value = std::move( v );
703 m_value.append( v.data(), v.size() );
710 m_name = field_to_string( m_field_id );
729 #if !defined( RESTINIO_HEADER_FIELDS_DEFAULT_RESERVE_COUNT ) 730 #define RESTINIO_HEADER_FIELDS_DEFAULT_RESERVE_COUNT 4
789 std::swap( m_fields, http_header_fields.m_fields );
796 return m_fields.cend() != cfind( field_name );
808 return m_fields.cend() != cfind( field_id );
815 fields_container_t::iterator it;
820 it = find( http_header_field.field_id() );
826 it = find( http_header_field.name() );
829 if( m_fields.end() != it )
831 *it = std::move( http_header_field );
835 m_fields.emplace_back( std::move( http_header_field ) );
842 std::string field_name,
843 std::string field_value )
845 const auto it = find( field_name );
847 if( m_fields.end() != it )
849 it->name( std::move( field_name ) );
850 it->value( std::move( field_value ) );
854 m_fields.emplace_back(
855 std::move( field_name ),
856 std::move( field_value ) );
868 std::string field_value )
872 const auto it = find( field_id );
874 if( m_fields.end() != it )
876 it->value( std::move( field_value ) );
880 m_fields.emplace_back(
882 std::move( field_value ) );
890 string_view_t field_name,
891 string_view_t field_value )
893 const auto it = find( field_name );
895 if( m_fields.end() != it )
897 it->append_value( field_value );
901 m_fields.emplace_back( field_name, field_value );
913 string_view_t field_value )
917 const auto it = find( field_id );
919 if( m_fields.end() != it )
921 it->append_value( field_value );
925 m_fields.emplace_back( field_id, field_value );
934 const auto it = cfind( field_name );
936 if( m_fields.end() == it )
938 fmt::format(
"field '{}' doesn't exist", field_name ) };
958 const auto it = cfind( field_name );
959 if( m_fields.end() == it )
962 return std::addressof(it->value());
973 "unspecified fields cannot be searched by id" ) };
976 const auto it = cfind( field_id );
978 if( m_fields.end() == it )
982 "field '{}' doesn't exist",
983 field_to_string( field_id ) ) };
1006 const auto it = cfind( field_id );
1007 if( m_fields.end() != it )
1008 return std::addressof(it->value());
1025 const auto it = cfind( field_name );
1027 if( m_fields.end() == it )
1028 return std::string( default_value.data(), default_value.size() );
1044 const auto it = cfind( field_name );
1046 if( m_fields.end() == it )
1047 return std::move(default_value);
1058 string_view_t field_name,
1059 const char * default_value )
const 1061 return this->get_field_or( field_name, string_view_t{ default_value } );
1070 string_view_t field_name,
1071 const std::string & default_value )
const 1073 return this->get_field_or( field_name, string_view_t{ default_value } );
1089 const auto it = cfind( field_id );
1091 if( m_fields.end() != it )
1095 return std::string( default_value.data(), default_value.size() );
1105 const char * default_value )
const 1107 return this->get_field_or( field_id, string_view_t{ default_value } );
1117 const std::string & default_value )
const 1119 return this->get_field_or( field_id, string_view_t{ default_value } );
1135 const auto it = cfind( field_id );
1137 if( m_fields.end() != it )
1141 return std::move( default_value );
1148 const auto it = find( field_name );
1150 if( m_fields.end() != it )
1152 m_fields.erase( it );
1162 const auto it = find( field_id );
1164 if( m_fields.end() != it )
1166 m_fields.erase( it );
1181 return {
this->get_field(name) };
1190 return {
this->get_field(field_id) };
1210 optional_t< string_view_t > result;
1212 if(
auto * ptr =
this->try_get_field(name) )
1213 result = string_view_t{ *ptr };
1235 optional_t< string_view_t > result;
1237 if(
auto * ptr =
this->try_get_field(field_id) )
1238 result = string_view_t{ *ptr };
1265 template<
typename Lambda >
1268 noexcept(
noexcept(
lambda(
1278 return m_fields.cbegin();
1284 return m_fields.cend();
1289 return m_fields.size();
1305 m_fields.back().append_value( field_value );
1311 return std::find_if(
1314 [&](
const auto & f ){
1315 return caseless_cmp( f.name(), field_name );
1322 return std::find_if(
1325 [&](
const auto & f ){
1326 return caseless_cmp( f.name(), field_name );
1333 return std::find_if(
1336 [&](
const auto & f ){
1337 return f.field_id() == field_id;
1344 return std::find_if(
1347 [&](
const auto & f ){
1348 return f.field_id() == field_id;
1380 {
return m_http_major; }
1384 { m_http_major = v; }
1388 {
return m_http_minor; }
1392 { m_http_minor = v; }
1398 {
return m_content_length; }
1402 { m_content_length = l; }
1446 #define RESTINIO_HTTP_METHOD_MAP(RESTINIO_GEN) 1447 RESTINIO_GEN( http_method_delete, HTTP_DELETE, DELETE ) 1448 RESTINIO_GEN( http_method_get, HTTP_GET, GET ) 1449 RESTINIO_GEN( http_method_head, HTTP_HEAD, HEAD ) 1450 RESTINIO_GEN( http_method_post, HTTP_POST, POST ) 1451 RESTINIO_GEN( http_method_put, HTTP_PUT, PUT ) 1453 RESTINIO_GEN( http_method_connect, HTTP_CONNECT, CONNECT ) 1454 RESTINIO_GEN( http_method_options, HTTP_OPTIONS, OPTIONS ) 1455 RESTINIO_GEN( http_method_trace, HTTP_TRACE, TRACE ) 1457 RESTINIO_GEN( http_method_copy, HTTP_COPY, COPY ) 1458 RESTINIO_GEN( http_method_lock, HTTP_LOCK, LOCK ) 1459 RESTINIO_GEN( http_method_mkcol, HTTP_MKCOL, MKCOL ) 1460 RESTINIO_GEN( http_method_move, HTTP_MOVE, MOVE ) 1461 RESTINIO_GEN( http_method_propfind, HTTP_PROPFIND, PROPFIND ) 1462 RESTINIO_GEN( http_method_proppatch, HTTP_PROPPATCH, PROPPATCH ) 1463 RESTINIO_GEN( http_method_search, HTTP_SEARCH, SEARCH ) 1464 RESTINIO_GEN( http_method_unlock, HTTP_UNLOCK, UNLOCK ) 1465 RESTINIO_GEN( http_method_bind, HTTP_BIND, BIND ) 1466 RESTINIO_GEN( http_method_rebind, HTTP_REBIND, REBIND ) 1467 RESTINIO_GEN( http_method_unbind, HTTP_UNBIND, UNBIND ) 1468 RESTINIO_GEN( http_method_acl, HTTP_ACL, ACL ) 1470 RESTINIO_GEN( http_method_report, HTTP_REPORT, REPORT ) 1471 RESTINIO_GEN( http_method_mkactivity, HTTP_MKACTIVITY, MKACTIVITY ) 1472 RESTINIO_GEN( http_method_checkout, HTTP_CHECKOUT, CHECKOUT ) 1473 RESTINIO_GEN( http_method_merge, HTTP_MERGE, MERGE ) 1475 RESTINIO_GEN( http_method_msearch, HTTP_MSEARCH, M-SEARCH) 1476 RESTINIO_GEN( http_method_notify, HTTP_NOTIFY, NOTIFY ) 1477 RESTINIO_GEN( http_method_subscribe, HTTP_SUBSCRIBE, SUBSCRIBE ) 1478 RESTINIO_GEN( http_method_unsubscribe, HTTP_UNSUBSCRIBE, UNSUBSCRIBE ) 1480 RESTINIO_GEN( http_method_patch, HTTP_PATCH, PATCH ) 1481 RESTINIO_GEN( http_method_purge, HTTP_PURGE, PURGE ) 1483 RESTINIO_GEN( http_method_mkcalendar, HTTP_MKCALENDAR, MKCALENDAR ) 1485 RESTINIO_GEN( http_method_link, HTTP_LINK, LINK ) 1486 RESTINIO_GEN( http_method_unlink, HTTP_UNLINK, UNLINK ) 1547 ,
m_name{
"<undefined>" }
1551 const char * name )
noexcept 1567 constexpr const char *
1570 friend constexpr bool 1575 friend constexpr bool 1580 friend constexpr bool 1589 return to << m.c_str();
1593 #define RESTINIO_HTTP_METHOD_FUNC_GEN( func_name, nodejs_code, method_name ) 1594 inline constexpr http_method_id_t func_name() { 1595 return { nodejs_code, #method_name }; 1599 #undef RESTINIO_HTTP_METHOD_FUNC_GEN 1634 #define RESTINIO_HTTP_METHOD_FUNC_GEN( func_name, nodejs_code, method_name ) 1635 case nodejs_code : result = func_name(); break; 1638 #undef RESTINIO_HTTP_METHOD_FUNC_GEN 1651 struct http_request_header_t
final 1657 const char * result =
static_cast<
const char * >(
1658 std::memchr( from, chr, size ) );
1660 return result ?
static_cast< std::size_t >( result - from ) : size;
1668 std::string request_target_ )
1671 request_target( std::move( request_target_ ) );
1676 {
return m_method; }
1684 {
return m_request_target; }
1689 m_request_target.assign( std::move( t ) );
1691 m_fragment_separator_pos =
1692 memchr_helper(
'#', m_request_target.data(), m_request_target.size() );
1694 m_query_separator_pos =
1695 memchr_helper(
'?', m_request_target.data(), m_fragment_separator_pos );
1709 return string_view_t{ m_request_target.data(), m_query_separator_pos };
1721 m_fragment_separator_pos == m_query_separator_pos ?
1722 string_view_t{
nullptr, 0 } :
1724 m_request_target.data() + m_query_separator_pos + 1,
1725 m_fragment_separator_pos - m_query_separator_pos - 1 };
1738 m_request_target.size() == m_fragment_separator_pos ?
1739 string_view_t{
nullptr, 0 } :
1741 m_request_target.data() + m_fragment_separator_pos + 1,
1742 m_request_target.size() - m_fragment_separator_pos - 1 };
1750 if( m_request_target.size() == m_fragment_separator_pos )
1755 const auto fragment_separator_pos_inc =
1756 memchr_helper(
'#', at, length );
1758 m_fragment_separator_pos += fragment_separator_pos_inc;
1760 if( m_request_target.size() == m_query_separator_pos )
1764 m_query_separator_pos +=
1765 memchr_helper(
'?', at, fragment_separator_pos_inc );
1771 m_request_target.append( at, length );
1799 return m_status_code;
1805 return raw_code() == sc.raw_code();
1811 return sc.raw_code() != sc.raw_code();
1817 return sc.raw_code() < sc.raw_code();
1925 std::string reason_phrase )
1932 {
return m_status_code; }
1936 { m_status_code = c; }
1940 {
return m_reason_phrase; }
1944 { m_reason_phrase.assign( std::move( r ) ); }
1954 return o <<
"{" << status_line.status_code().raw_code() <<
", " 1955 << status_line.reason_phrase() <<
"}";
1964 {
return http_status_line_t{ status_code::continue_,
"Continue" }; }
1967 {
return http_status_line_t{ status_code::switching_protocols,
"Switching Protocols" }; }
1970 {
return http_status_line_t{ status_code::ok,
"OK" }; }
1973 {
return http_status_line_t{ status_code::created,
"Created" }; }
1976 {
return http_status_line_t{ status_code::accepted,
"Accepted" }; }
1979 {
return http_status_line_t{ status_code::non_authoritative_information,
"Non-Authoritative Information" }; }
1982 {
return http_status_line_t{ status_code::no_content,
"No Content" }; }
1985 {
return http_status_line_t{ status_code::reset_content,
"Reset Content" }; }
1988 {
return http_status_line_t{ status_code::partial_content,
"Partial Content" }; }
1991 {
return http_status_line_t{ status_code::multiple_choices,
"Multiple Choices" }; }
1994 {
return http_status_line_t{ status_code::moved_permanently,
"Moved Permanently" }; }
1997 {
return http_status_line_t{ status_code::found,
"Found" }; }
2000 {
return http_status_line_t{ status_code::see_other,
"See Other" }; }
2003 {
return http_status_line_t{ status_code::not_modified,
"Not Modified" }; }
2006 {
return http_status_line_t{ status_code::use_proxy,
"Use Proxy" }; }
2009 {
return http_status_line_t{ status_code::temporary_redirect,
"Temporary Redirect" }; }
2012 {
return http_status_line_t{ status_code::bad_request,
"Bad Request" }; }
2015 {
return http_status_line_t{ status_code::unauthorized,
"Unauthorized" }; }
2018 {
return http_status_line_t{ status_code::payment_required,
"Payment Required" }; }
2021 {
return http_status_line_t{ status_code::forbidden,
"Forbidden" }; }
2024 {
return http_status_line_t{ status_code::not_found,
"Not Found" }; }
2027 {
return http_status_line_t{ status_code::method_not_allowed,
"Method Not Allowed" }; }
2030 {
return http_status_line_t{ status_code::not_acceptable,
"Not Acceptable" }; }
2033 {
return http_status_line_t{status_code::proxy_authentication_required,
"Proxy Authentication Required" }; }
2036 {
return http_status_line_t{ status_code::request_time_out,
"Request Timeout" }; }
2039 {
return http_status_line_t{ status_code::conflict,
"Conflict" }; }
2042 {
return http_status_line_t{ status_code::gone,
"Gone" }; }
2045 {
return http_status_line_t{ status_code::length_required,
"Length Required" }; }
2048 {
return http_status_line_t{ status_code::precondition_failed,
"Precondition Failed" }; }
2051 {
return http_status_line_t{ status_code::payload_too_large,
"Payload Too Large" }; }
2054 {
return http_status_line_t{ status_code::uri_too_long,
"URI Too Long" }; }
2057 {
return http_status_line_t{ status_code::unsupported_media_type,
"Unsupported Media Type" }; }
2060 {
return http_status_line_t{ status_code::requested_range_not_satisfiable,
"Requested Range Not Satisfiable" }; }
2063 {
return http_status_line_t{ status_code::expectation_failed,
"Expectation Failed" }; }
2066 {
return http_status_line_t{ status_code::internal_server_error,
"Internal Server Error" }; }
2069 {
return http_status_line_t{ status_code::not_implemented,
"Not Implemented" }; }
2072 {
return http_status_line_t{ status_code::bad_gateway,
"Bad Gateway" }; }
2075 {
return http_status_line_t{ status_code::service_unavailable,
"Service Unavailable" }; }
2078 {
return http_status_line_t{ status_code::gateway_time_out,
"Gateway Timeout" }; }
2081 {
return http_status_line_t{ status_code::http_version_not_supported,
"HTTP Version not supported" }; }
2090 {
return http_status_line_t{ status_code::permanent_redirect,
"Permanent Redirect" }; }
2094 {
return http_status_line_t{ status_code::processing,
"Processing" }; }
2097 {
return http_status_line_t{ status_code::multi_status,
"Multi-Status" }; }
2100 {
return http_status_line_t{ status_code::unprocessable_entity,
"Unprocessable Entity" }; }
2103 {
return http_status_line_t{ status_code::locked,
"Locked" }; }
2106 {
return http_status_line_t{ status_code::failed_dependency,
"Failed Dependency" }; }
2109 {
return http_status_line_t{ status_code::insufficient_storage,
"Insufficient Storage" }; }
2113 {
return http_status_line_t{ status_code::precondition_required,
"Precondition Required" }; }
2116 {
return http_status_line_t{ status_code::too_many_requests,
"Too Many Requests" }; }
2119 {
return http_status_line_t{ status_code::request_header_fields_too_large,
"Request Header Fields Too Large" }; }
2122 {
return http_status_line_t{ status_code::network_authentication_required,
"Network Authentication Required" }; }
2130 struct http_response_header_t
final 2143 {
return m_status_line.status_code(); }
2147 { m_status_line.status_code( c ); }
2151 {
return m_status_line.reason_phrase(); }
2155 { m_status_line.reason_phrase( std::move( r ) ); }
2160 return m_status_line;
2166 m_status_line = std::move( sl );
void reason_phrase(std::string r)
http_status_line_t status_method_not_allowed()
constexpr http_status_code_t see_other
http_status_line_t status_unprocessable_entity()
http_status_line_t status_temporary_redirect()
constexpr http_status_code_t no_content
http_status_line_t status_use_proxy()
friend constexpr bool operator!=(const http_method_id_t &a, const http_method_id_t &b) noexcept
std::ostream & operator<<(std::ostream &o, const http_status_line_t &status_line)
constexpr http_method_id_t(int value, const char *name) noexcept
constexpr http_status_code_t too_many_requests
constexpr http_status_code_t non_authoritative_information
http_status_line_t status_multi_status()
constexpr http_status_code_t ok
constexpr http_status_code_t conflict
http_status_line_t status_gone()
std::string m_reason_phrase
constexpr http_status_code_t(std::uint16_t status_code) noexcept
constexpr http_method_id_t() noexcept
constexpr http_status_code_t payment_required
A type for representation of HTTP method ID.
constexpr http_status_code_t bad_request
constexpr http_status_code_t multi_status
http_status_line_t status_created()
constexpr const char * c_str() const noexcept
http_status_line_t status_bad_request()
http_status_line_t status_internal_server_error()
http_status_line_t status_payment_required()
http_status_line_t status_length_required()
constexpr http_status_code_t expectation_failed
http_status_line_t status_not_acceptable()
friend constexpr bool operator==(const http_method_id_t &a, const http_method_id_t &b) noexcept
constexpr http_status_code_t requested_range_not_satisfiable
constexpr http_status_code_t() noexcept
constexpr bool operator==(const http_status_code_t &sc) const noexcept
constexpr http_method_id_t & operator=(const http_method_id_t &) noexcept=default
http_status_line_t status_payload_too_large()
constexpr http_status_code_t length_required
http_status_line_t(http_status_code_t sc, std::string reason_phrase)
constexpr http_status_code_t moved_permanently
constexpr http_method_id_t(const http_method_id_t &) noexcept=default
constexpr auto raw_code() const noexcept
http_status_line_t status_not_modified()
bool caseless_cmp(string_view_t a, string_view_t b) noexcept
Comparator for fields names.
const char * field_to_string(http_field_t f) noexcept
Helper sunction to get method string name.
constexpr http_status_code_t partial_content
http_status_line_t status_non_authoritative_information()
std::uint16_t m_status_code
Status code value.
http_status_line_t status_precondition_failed()
constexpr http_method_id_t http_method_unknown()
http_status_line_t status_http_version_not_supported()
constexpr http_status_code_t request_time_out
const std::string & reason_phrase() const noexcept
constexpr http_status_code_t temporary_redirect
http_status_line_t status_proxy_authentication_required()
constexpr http_status_code_t processing
http_status_line_t status_conflict()
http_status_line_t status_expectation_failed()
constexpr http_status_code_t precondition_required
constexpr http_status_code_t unauthorized
HTTP response header status line.
constexpr http_status_code_t internal_server_error
http_connection_header_t
Values for conection header field.
constexpr http_status_code_t gateway_time_out
http_status_line_t status_request_header_fields_too_large()
http_status_line_t status_partial_content()
constexpr http_status_code_t switching_protocols
constexpr http_status_code_t not_acceptable
http_status_line_t status_failed_dependency()
constexpr http_status_code_t http_version_not_supported
constexpr http_status_code_t method_not_allowed
constexpr http_status_code_t continue_
http_status_line_t status_gateway_time_out()
std::ostream & operator<<(std::ostream &to, const http_method_id_t &m)
constexpr http_status_code_t network_authentication_required
http_status_line_t status_accepted()
friend constexpr bool operator<(const http_method_id_t &a, const http_method_id_t &b) noexcept
void status_code(http_status_code_t c) noexcept
http_status_line_t status_unauthorized()
constexpr http_status_code_t insufficient_storage
constexpr bool operator<(const http_status_code_t &sc) const noexcept
http_status_line_t status_service_unavailable()
constexpr http_status_code_t reset_content
http_status_line_t status_multiple_choices()
http_status_line_t status_found()
http_status_line_t status_reset_content()
http_status_line_t status_too_many_requests()
bool caseless_cmp(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
constexpr http_status_code_t created
http_status_code_t m_status_code
http_status_line_t status_moved_permanently()
http_status_line_t status_not_found()
constexpr http_status_code_t found
constexpr http_method_id_t(http_method_id_t &&) noexcept=default
constexpr http_status_code_t unprocessable_entity
constexpr bool operator!=(const http_status_code_t &sc) const noexcept
http_status_line_t status_bad_gateway()
http_status_line_t status_requested_range_not_satisfiable()
A handy wrapper for HTTP response status code.
constexpr http_status_code_t not_implemented
http_status_code_t status_code() const noexcept
http_status_line_t status_locked()
http_status_line_t status_forbidden()
The default implementation for http_method_mapper.
static constexpr const int unknown_method
http_status_line_t status_request_time_out()
http_status_line_t status_uri_too_long()
constexpr http_status_code_t locked
constexpr http_status_code_t not_found
constexpr http_status_code_t request_header_fields_too_large
constexpr http_status_code_t bad_gateway
constexpr http_status_code_t service_unavailable
constexpr http_status_code_t precondition_failed
http_field_t string_to_field(string_view_t field) noexcept
Helper function to get method string name.
bool caseless_cmp(const char *a, std::size_t a_size, const char *b, std::size_t b_size) noexcept
Comparator for fields names.
http_status_line_t status_precondition_required()
constexpr http_status_code_t proxy_authentication_required
constexpr http_status_code_t accepted
constexpr http_status_code_t not_modified
constexpr http_status_code_t unsupported_media_type
constexpr auto uchar_at(const char *const from, const std::size_t at) noexcept
http_status_line_t status_no_content()
constexpr http_status_code_t multiple_choices
constexpr http_status_code_t use_proxy
http_status_line_t status_ok()
constexpr http_status_code_t permanent_redirect
http_status_line_t status_processing()
constexpr http_status_code_t failed_dependency
static constexpr http_method_id_t from_nodejs(int value) noexcept
http_status_line_t status_insufficient_storage()
http_status_line_t status_permanent_redirect()
http_status_line_t status_unsupported_media_type()
constexpr auto raw_id() const noexcept
http_status_line_t status_switching_protocols()
constexpr http_status_code_t payload_too_large
http_field_t
C++ enum that repeats nodejs c-style enum.
http_status_line_t status_network_authentication_required()
constexpr http_status_code_t forbidden
http_status_line_t status_continue()
http_status_line_t status_not_implemented()
http_status_line_t status_see_other()
constexpr http_status_code_t uri_too_long
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
constexpr http_method_id_t & operator=(http_method_id_t &&) noexcept=default
constexpr http_status_code_t gone