RESTinio
Loading...
Searching...
No Matches
http_headers.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
9#pragma once
10
12
14
17#include <restinio/optional.hpp>
19
20#include <http_parser.h>
21
22#include <iosfwd>
23#include <string>
24#include <vector>
25#include <algorithm>
26
27namespace restinio
28{
29
30
31// Adopted header fields
32// (https://www.iana.org/assignments/message-headers/message-headers.xml#perm-headers).
33// Fields `Connection` and `Content-Length` are specieal cases, thus they are excluded from the list.
34#define RESTINIO_HTTP_FIELDS_MAP( RESTINIO_GEN ) \
35 RESTINIO_GEN( a_im, A-IM ) \
36 RESTINIO_GEN( accept, Accept ) \
37 RESTINIO_GEN( accept_additions, Accept-Additions ) \
38 RESTINIO_GEN( accept_charset, Accept-Charset ) \
39 RESTINIO_GEN( accept_datetime, Accept-Datetime ) \
40 RESTINIO_GEN( accept_encoding, Accept-Encoding ) \
41 RESTINIO_GEN( accept_features, Accept-Features ) \
42 RESTINIO_GEN( accept_language, Accept-Language ) \
43 RESTINIO_GEN( accept_patch, Accept-Patch ) \
44 RESTINIO_GEN( accept_post, Accept-Post ) \
45 RESTINIO_GEN( accept_ranges, Accept-Ranges ) \
46 RESTINIO_GEN( age, Age ) \
47 RESTINIO_GEN( allow, Allow ) \
48 RESTINIO_GEN( alpn, ALPN ) \
49 RESTINIO_GEN( alt_svc, Alt-Svc ) \
50 RESTINIO_GEN( alt_used, Alt-Used ) \
51 RESTINIO_GEN( alternates, Alternates ) \
52 RESTINIO_GEN( apply_to_redirect_ref, Apply-To-Redirect-Ref ) \
53 RESTINIO_GEN( authentication_control, Authentication-Control ) \
54 RESTINIO_GEN( authentication_info, Authentication-Info ) \
55 RESTINIO_GEN( authorization, Authorization ) \
56 RESTINIO_GEN( c_ext, C-Ext ) \
57 RESTINIO_GEN( c_man, C-Man ) \
58 RESTINIO_GEN( c_opt, C-Opt ) \
59 RESTINIO_GEN( c_pep, C-PEP ) \
60 RESTINIO_GEN( c_pep_info, C-PEP-Info ) \
61 RESTINIO_GEN( cache_control, Cache-Control ) \
62 RESTINIO_GEN( caldav_timezones, CalDAV-Timezones ) \
63 RESTINIO_GEN( close, Close ) \
64 RESTINIO_GEN( content_base, Content-Base ) \
65 RESTINIO_GEN( content_disposition, Content-Disposition ) \
66 RESTINIO_GEN( content_encoding, Content-Encoding ) \
67 RESTINIO_GEN( content_id, Content-ID ) \
68 RESTINIO_GEN( content_language, Content-Language ) \
69 RESTINIO_GEN( content_location, Content-Location ) \
70 RESTINIO_GEN( content_md5, Content-MD5 ) \
71 RESTINIO_GEN( content_range, Content-Range ) \
72 RESTINIO_GEN( content_script_type, Content-Script-Type ) \
73 RESTINIO_GEN( content_style_type, Content-Style-Type ) \
74 RESTINIO_GEN( content_type, Content-Type ) \
75 RESTINIO_GEN( content_version, Content-Version ) \
76 RESTINIO_GEN( cookie, Cookie ) \
77 RESTINIO_GEN( cookie2, Cookie2 ) \
78 RESTINIO_GEN( dasl, DASL ) \
79 RESTINIO_GEN( dav, DAV ) \
80 RESTINIO_GEN( date, Date ) \
81 RESTINIO_GEN( default_style, Default-Style ) \
82 RESTINIO_GEN( delta_base, Delta-Base ) \
83 RESTINIO_GEN( depth, Depth ) \
84 RESTINIO_GEN( derived_from, Derived-From ) \
85 RESTINIO_GEN( destination, Destination ) \
86 RESTINIO_GEN( differential_id, Differential-ID ) \
87 RESTINIO_GEN( digest, Digest ) \
88 RESTINIO_GEN( etag, ETag ) \
89 RESTINIO_GEN( expect, Expect ) \
90 RESTINIO_GEN( expires, Expires ) \
91 RESTINIO_GEN( ext, Ext ) \
92 RESTINIO_GEN( forwarded, Forwarded ) \
93 RESTINIO_GEN( from, From ) \
94 RESTINIO_GEN( getprofile, GetProfile ) \
95 RESTINIO_GEN( hobareg, Hobareg ) \
96 RESTINIO_GEN( host, Host ) \
97 RESTINIO_GEN( http2_settings, HTTP2-Settings ) \
98 RESTINIO_GEN( im, IM ) \
99 RESTINIO_GEN( if_, If ) \
100 RESTINIO_GEN( if_match, If-Match ) \
101 RESTINIO_GEN( if_modified_since, If-Modified-Since ) \
102 RESTINIO_GEN( if_none_match, If-None-Match ) \
103 RESTINIO_GEN( if_range, If-Range ) \
104 RESTINIO_GEN( if_schedule_tag_match, If-Schedule-Tag-Match ) \
105 RESTINIO_GEN( if_unmodified_since, If-Unmodified-Since ) \
106 RESTINIO_GEN( keep_alive, Keep-Alive ) \
107 RESTINIO_GEN( label, Label ) \
108 RESTINIO_GEN( last_modified, Last-Modified ) \
109 RESTINIO_GEN( link, Link ) \
110 RESTINIO_GEN( location, Location ) \
111 RESTINIO_GEN( lock_token, Lock-Token ) \
112 RESTINIO_GEN( man, Man ) \
113 RESTINIO_GEN( max_forwards, Max-Forwards ) \
114 RESTINIO_GEN( memento_datetime, Memento-Datetime ) \
115 RESTINIO_GEN( meter, Meter ) \
116 RESTINIO_GEN( mime_version, MIME-Version ) \
117 RESTINIO_GEN( negotiate, Negotiate ) \
118 RESTINIO_GEN( opt, Opt ) \
119 RESTINIO_GEN( optional_www_authenticate, Optional-WWW-Authenticate ) \
120 RESTINIO_GEN( ordering_type, Ordering-Type ) \
121 RESTINIO_GEN( origin, Origin ) \
122 RESTINIO_GEN( overwrite, Overwrite ) \
123 RESTINIO_GEN( p3p, P3P ) \
124 RESTINIO_GEN( pep, PEP ) \
125 RESTINIO_GEN( pics_label, PICS-Label ) \
126 RESTINIO_GEN( pep_info, Pep-Info ) \
127 RESTINIO_GEN( position, Position ) \
128 RESTINIO_GEN( pragma, Pragma ) \
129 RESTINIO_GEN( prefer, Prefer ) \
130 RESTINIO_GEN( preference_applied, Preference-Applied ) \
131 RESTINIO_GEN( profileobject, ProfileObject ) \
132 RESTINIO_GEN( protocol, Protocol ) \
133 RESTINIO_GEN( protocol_info, Protocol-Info ) \
134 RESTINIO_GEN( protocol_query, Protocol-Query ) \
135 RESTINIO_GEN( protocol_request, Protocol-Request ) \
136 RESTINIO_GEN( proxy_authenticate, Proxy-Authenticate ) \
137 RESTINIO_GEN( proxy_authentication_info, Proxy-Authentication-Info ) \
138 RESTINIO_GEN( proxy_authorization, Proxy-Authorization ) \
139 RESTINIO_GEN( proxy_features, Proxy-Features ) \
140 RESTINIO_GEN( proxy_instruction, Proxy-Instruction ) \
141 RESTINIO_GEN( public_, Public ) \
142 RESTINIO_GEN( public_key_pins, Public-Key-Pins ) \
143 RESTINIO_GEN( public_key_pins_report_only, Public-Key-Pins-Report-Only ) \
144 RESTINIO_GEN( range, Range ) \
145 RESTINIO_GEN( redirect_ref, Redirect-Ref ) \
146 RESTINIO_GEN( referer, Referer ) \
147 RESTINIO_GEN( retry_after, Retry-After ) \
148 RESTINIO_GEN( safe, Safe ) \
149 RESTINIO_GEN( schedule_reply, Schedule-Reply ) \
150 RESTINIO_GEN( schedule_tag, Schedule-Tag ) \
151 RESTINIO_GEN( sec_websocket_accept, Sec-WebSocket-Accept ) \
152 RESTINIO_GEN( sec_websocket_extensions, Sec-WebSocket-Extensions ) \
153 RESTINIO_GEN( sec_websocket_key, Sec-WebSocket-Key ) \
154 RESTINIO_GEN( sec_websocket_protocol, Sec-WebSocket-Protocol ) \
155 RESTINIO_GEN( sec_websocket_version, Sec-WebSocket-Version ) \
156 RESTINIO_GEN( security_scheme, Security-Scheme ) \
157 RESTINIO_GEN( server, Server ) \
158 RESTINIO_GEN( set_cookie, Set-Cookie ) \
159 RESTINIO_GEN( set_cookie2, Set-Cookie2 ) \
160 RESTINIO_GEN( setprofile, SetProfile ) \
161 RESTINIO_GEN( slug, SLUG ) \
162 RESTINIO_GEN( soapaction, SoapAction ) \
163 RESTINIO_GEN( status_uri, Status-URI ) \
164 RESTINIO_GEN( strict_transport_security, Strict-Transport-Security ) \
165 RESTINIO_GEN( surrogate_capability, Surrogate-Capability ) \
166 RESTINIO_GEN( surrogate_control, Surrogate-Control ) \
167 RESTINIO_GEN( tcn, TCN ) \
168 RESTINIO_GEN( te, TE ) \
169 RESTINIO_GEN( timeout, Timeout ) \
170 RESTINIO_GEN( topic, Topic ) \
171 RESTINIO_GEN( trailer, Trailer ) \
172 RESTINIO_GEN( transfer_encoding, Transfer-Encoding ) \
173 RESTINIO_GEN( ttl, TTL ) \
174 RESTINIO_GEN( urgency, Urgency ) \
175 RESTINIO_GEN( uri, URI ) \
176 RESTINIO_GEN( upgrade, Upgrade ) \
177 RESTINIO_GEN( user_agent, User-Agent ) \
178 RESTINIO_GEN( variant_vary, Variant-Vary ) \
179 RESTINIO_GEN( vary, Vary ) \
180 RESTINIO_GEN( via, Via ) \
181 RESTINIO_GEN( www_authenticate, WWW-Authenticate ) \
182 RESTINIO_GEN( want_digest, Want-Digest ) \
183 RESTINIO_GEN( warning, Warning ) \
184 RESTINIO_GEN( x_frame_options, X-Frame-Options ) \
185\
186 RESTINIO_GEN( access_control, Access-Control ) \
187 RESTINIO_GEN( access_control_allow_credentials, Access-Control-Allow-Credentials ) \
188 RESTINIO_GEN( access_control_allow_headers, Access-Control-Allow-Headers )\
189 RESTINIO_GEN( access_control_allow_methods, Access-Control-Allow-Methods )\
190 RESTINIO_GEN( access_control_allow_origin, Access-Control-Allow-Origin ) \
191 RESTINIO_GEN( access_control_max_age, Access-Control-Max-Age ) \
192 RESTINIO_GEN( access_control_request_method, Access-Control-Request-Method ) \
193 RESTINIO_GEN( access_control_request_headers, Access-Control-Request-Headers ) \
194 RESTINIO_GEN( compliance, Compliance ) \
195 RESTINIO_GEN( content_transfer_encoding, Content-Transfer-Encoding ) \
196 RESTINIO_GEN( cost, Cost ) \
197 RESTINIO_GEN( ediint_features, EDIINT-Features ) \
198 RESTINIO_GEN( message_id, Message-ID ) \
199 RESTINIO_GEN( method_check, Method-Check ) \
200 RESTINIO_GEN( method_check_expires, Method-Check-Expires ) \
201 RESTINIO_GEN( non_compliance, Non-Compliance ) \
202 RESTINIO_GEN( optional, Optional ) \
203 RESTINIO_GEN( referer_root, Referer-Root ) \
204 RESTINIO_GEN( resolution_hint, Resolution-Hint ) \
205 RESTINIO_GEN( resolver_location, Resolver-Location ) \
206 RESTINIO_GEN( subok, SubOK ) \
207 RESTINIO_GEN( subst, Subst ) \
208 RESTINIO_GEN( title, Title ) \
209 RESTINIO_GEN( ua_color, UA-Color ) \
210 RESTINIO_GEN( ua_media, UA-Media ) \
211 RESTINIO_GEN( ua_pixels, UA-Pixels ) \
212 RESTINIO_GEN( ua_resolution, UA-Resolution ) \
213 RESTINIO_GEN( ua_windowpixels, UA-Windowpixels ) \
214 RESTINIO_GEN( version, Version ) \
215 RESTINIO_GEN( x_device_accept, X-Device-Accept ) \
216 RESTINIO_GEN( x_device_accept_charset, X-Device-Accept-Charset ) \
217 RESTINIO_GEN( x_device_accept_encoding, X-Device-Accept-Encoding ) \
218 RESTINIO_GEN( x_device_accept_language, X-Device-Accept-Language ) \
219 RESTINIO_GEN( x_device_user_agent, X-Device-User-Agent )
220 // SPECIAL CASE: RESTINIO_GEN( connection, Connection )
221 // SPECIAL CASE: RESTINIO_GEN( content_length, Content-Length )
222
223//
224// http_field_t
225//
226
228
232enum class http_field_t : std::uint8_t //By now 152 + 34 + 1 items fits to uint8_t
233{
234#define RESTINIO_HTTP_FIELD_GEN( name, ignored ) name,
236#undef RESTINIO_HTTP_FIELD_GEN
237 // Unspecified field.
239};
240
243
244//
245// string_to_field()
246//
247
250inline http_field_t
252{
253 const char * field_name = field.data();
254 const std::size_t field_name_size = field.size();
255
256#define RESTINIO_HTTP_CHECK_FOR_FIELD( field_id, candidate_field_name ) \
257 if( impl::is_equal_caseless(field_name, #candidate_field_name , field_name_size ) ) \
258 return http_field_t:: field_id;
259
260 // TODO: make most popular fields to be checked first.
261
262 switch( field_name_size )
263 {
264 case 2:
268 break;
269
270 case 3:
282 break;
283
284 case 4:
285 // Known to be more used first:
287
299 break;
300
301 case 5:
302 RESTINIO_HTTP_CHECK_FOR_FIELD( allow, Allow )
303 RESTINIO_HTTP_CHECK_FOR_FIELD( c_ext, C-Ext )
304 RESTINIO_HTTP_CHECK_FOR_FIELD( c_man, C-Man )
305 RESTINIO_HTTP_CHECK_FOR_FIELD( c_opt, C-Opt )
306 RESTINIO_HTTP_CHECK_FOR_FIELD( c_pep, C-PEP )
308 RESTINIO_HTTP_CHECK_FOR_FIELD( depth, Depth )
309 RESTINIO_HTTP_CHECK_FOR_FIELD( label, Label )
310 RESTINIO_HTTP_CHECK_FOR_FIELD( meter, Meter )
311 RESTINIO_HTTP_CHECK_FOR_FIELD( range, Range )
312 RESTINIO_HTTP_CHECK_FOR_FIELD( topic, Topic )
313 RESTINIO_HTTP_CHECK_FOR_FIELD( subok, SubOK )
314 RESTINIO_HTTP_CHECK_FOR_FIELD( subst, Subst )
315 RESTINIO_HTTP_CHECK_FOR_FIELD( title, Title )
316 break;
317
318 case 6:
319 // Known to be more used first:
320 RESTINIO_HTTP_CHECK_FOR_FIELD( accept, Accept )
321 RESTINIO_HTTP_CHECK_FOR_FIELD( cookie, Cookie )
322 RESTINIO_HTTP_CHECK_FOR_FIELD( server, Server )
323
324 RESTINIO_HTTP_CHECK_FOR_FIELD( digest, Digest )
325 RESTINIO_HTTP_CHECK_FOR_FIELD( expect, Expect )
326 RESTINIO_HTTP_CHECK_FOR_FIELD( origin, Origin )
327 RESTINIO_HTTP_CHECK_FOR_FIELD( pragma, Pragma )
328 RESTINIO_HTTP_CHECK_FOR_FIELD( prefer, Prefer )
329 RESTINIO_HTTP_CHECK_FOR_FIELD( public_, Public )
330 break;
331
332 case 7:
333 RESTINIO_HTTP_CHECK_FOR_FIELD( alt_svc, Alt-Svc )
334 RESTINIO_HTTP_CHECK_FOR_FIELD( cookie2, Cookie2 )
335 RESTINIO_HTTP_CHECK_FOR_FIELD( expires, Expires )
336 RESTINIO_HTTP_CHECK_FOR_FIELD( hobareg, Hobareg )
337 RESTINIO_HTTP_CHECK_FOR_FIELD( referer, Referer )
338 RESTINIO_HTTP_CHECK_FOR_FIELD( timeout, Timeout )
339 RESTINIO_HTTP_CHECK_FOR_FIELD( trailer, Trailer )
340 RESTINIO_HTTP_CHECK_FOR_FIELD( urgency, Urgency )
342 RESTINIO_HTTP_CHECK_FOR_FIELD( warning, Warning )
343 RESTINIO_HTTP_CHECK_FOR_FIELD( version, Version )
344 break;
345
346 case 8:
347 RESTINIO_HTTP_CHECK_FOR_FIELD( alt_used, Alt-Used )
348 RESTINIO_HTTP_CHECK_FOR_FIELD( if_match, If-Match )
349 RESTINIO_HTTP_CHECK_FOR_FIELD( if_range, If-Range )
350 RESTINIO_HTTP_CHECK_FOR_FIELD( location, Location )
351 RESTINIO_HTTP_CHECK_FOR_FIELD( pep_info, Pep-Info )
352 RESTINIO_HTTP_CHECK_FOR_FIELD( position, Position )
353 RESTINIO_HTTP_CHECK_FOR_FIELD( protocol, Protocol )
354 RESTINIO_HTTP_CHECK_FOR_FIELD( optional, Optional )
355 RESTINIO_HTTP_CHECK_FOR_FIELD( ua_color, UA-Color )
356 RESTINIO_HTTP_CHECK_FOR_FIELD( ua_media, UA-Media )
357 break;
358
359 case 9:
360 RESTINIO_HTTP_CHECK_FOR_FIELD( forwarded, Forwarded )
361 RESTINIO_HTTP_CHECK_FOR_FIELD( negotiate, Negotiate )
362 RESTINIO_HTTP_CHECK_FOR_FIELD( overwrite, Overwrite )
363 RESTINIO_HTTP_CHECK_FOR_FIELD( ua_pixels, UA-Pixels )
364 break;
365
366 case 10:
367 RESTINIO_HTTP_CHECK_FOR_FIELD( alternates, Alternates )
368 RESTINIO_HTTP_CHECK_FOR_FIELD( c_pep_info, C-PEP-Info )
369 RESTINIO_HTTP_CHECK_FOR_FIELD( content_id, Content-ID )
370 RESTINIO_HTTP_CHECK_FOR_FIELD( delta_base, Delta-Base )
371 RESTINIO_HTTP_CHECK_FOR_FIELD( getprofile, GetProfile )
373 RESTINIO_HTTP_CHECK_FOR_FIELD( lock_token, Lock-Token )
374 RESTINIO_HTTP_CHECK_FOR_FIELD( pics_label, PICS-Label )
375 RESTINIO_HTTP_CHECK_FOR_FIELD( set_cookie, Set-Cookie )
376 RESTINIO_HTTP_CHECK_FOR_FIELD( setprofile, SetProfile )
377 RESTINIO_HTTP_CHECK_FOR_FIELD( soapaction, SoapAction )
378 RESTINIO_HTTP_CHECK_FOR_FIELD( status_uri, Status-URI )
379 RESTINIO_HTTP_CHECK_FOR_FIELD( user_agent, User-Agent )
380 RESTINIO_HTTP_CHECK_FOR_FIELD( compliance, Compliance )
381 RESTINIO_HTTP_CHECK_FOR_FIELD( message_id, Message-ID )
382 break;
383
384 case 11:
385 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_post, Accept-Post )
386 RESTINIO_HTTP_CHECK_FOR_FIELD( content_md5, Content-MD5 )
387 RESTINIO_HTTP_CHECK_FOR_FIELD( destination, Destination )
388 RESTINIO_HTTP_CHECK_FOR_FIELD( retry_after, Retry-After )
389 RESTINIO_HTTP_CHECK_FOR_FIELD( set_cookie2, Set-Cookie2 )
390 RESTINIO_HTTP_CHECK_FOR_FIELD( want_digest, Want-Digest )
391 break;
392
393 case 12:
394 // Known to be more used first:
395 RESTINIO_HTTP_CHECK_FOR_FIELD( content_type, Content-Type )
396
397 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_patch, Accept-Patch )
398 RESTINIO_HTTP_CHECK_FOR_FIELD( content_base, Content-Base )
399 RESTINIO_HTTP_CHECK_FOR_FIELD( derived_from, Derived-From )
400 RESTINIO_HTTP_CHECK_FOR_FIELD( max_forwards, Max-Forwards )
401 RESTINIO_HTTP_CHECK_FOR_FIELD( mime_version, MIME-Version )
402 RESTINIO_HTTP_CHECK_FOR_FIELD( schedule_tag, Schedule-Tag )
403 RESTINIO_HTTP_CHECK_FOR_FIELD( redirect_ref, Redirect-Ref )
404 RESTINIO_HTTP_CHECK_FOR_FIELD( variant_vary, Variant-Vary )
405 RESTINIO_HTTP_CHECK_FOR_FIELD( method_check, Method-Check )
406 RESTINIO_HTTP_CHECK_FOR_FIELD( referer_root, Referer-Root )
407 break;
408
409 case 13:
410 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_ranges, Accept-Ranges )
411 RESTINIO_HTTP_CHECK_FOR_FIELD( authorization, Authorization )
412 RESTINIO_HTTP_CHECK_FOR_FIELD( cache_control, Cache-Control )
413 RESTINIO_HTTP_CHECK_FOR_FIELD( content_range, Content-Range )
414 RESTINIO_HTTP_CHECK_FOR_FIELD( default_style, Default-Style )
415 RESTINIO_HTTP_CHECK_FOR_FIELD( if_none_match, If-None-Match )
416 RESTINIO_HTTP_CHECK_FOR_FIELD( last_modified, Last-Modified )
417 RESTINIO_HTTP_CHECK_FOR_FIELD( ordering_type, Ordering-Type )
418 RESTINIO_HTTP_CHECK_FOR_FIELD( profileobject, ProfileObject )
419 RESTINIO_HTTP_CHECK_FOR_FIELD( protocol_info, Protocol-Info )
420 RESTINIO_HTTP_CHECK_FOR_FIELD( ua_resolution, UA-Resolution )
421 break;
422
423 case 14:
424 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_charset, Accept-Charset )
425 RESTINIO_HTTP_CHECK_FOR_FIELD( http2_settings, HTTP2-Settings )
426 RESTINIO_HTTP_CHECK_FOR_FIELD( protocol_query, Protocol-Query )
427 RESTINIO_HTTP_CHECK_FOR_FIELD( proxy_features, Proxy-Features )
428 RESTINIO_HTTP_CHECK_FOR_FIELD( schedule_reply, Schedule-Reply )
429 RESTINIO_HTTP_CHECK_FOR_FIELD( non_compliance, Non-Compliance )
430 RESTINIO_HTTP_CHECK_FOR_FIELD( access_control, Access-Control )
431 break;
432
433 case 15:
434 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_encoding, Accept-Encoding )
435 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_features, Accept-Features )
436 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_language, Accept-Language )
437 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_datetime, Accept-Datetime )
438 RESTINIO_HTTP_CHECK_FOR_FIELD( content_version, Content-Version )
439 RESTINIO_HTTP_CHECK_FOR_FIELD( differential_id, Differential-ID )
440 RESTINIO_HTTP_CHECK_FOR_FIELD( public_key_pins, Public-Key-Pins )
441 RESTINIO_HTTP_CHECK_FOR_FIELD( security_scheme, Security-Scheme )
442 RESTINIO_HTTP_CHECK_FOR_FIELD( x_frame_options, X-Frame-Options )
443 RESTINIO_HTTP_CHECK_FOR_FIELD( x_device_accept, X-Device-Accept )
444 RESTINIO_HTTP_CHECK_FOR_FIELD( resolution_hint, Resolution-Hint )
445 RESTINIO_HTTP_CHECK_FOR_FIELD( ediint_features, EDIINT-Features )
446 RESTINIO_HTTP_CHECK_FOR_FIELD( ua_windowpixels, UA-Windowpixels )
447 break;
448
449 case 16:
450 RESTINIO_HTTP_CHECK_FOR_FIELD( accept_additions, Accept-Additions )
451 RESTINIO_HTTP_CHECK_FOR_FIELD( caldav_timezones, CalDAV-Timezones )
452 RESTINIO_HTTP_CHECK_FOR_FIELD( content_encoding, Content-Encoding )
453 RESTINIO_HTTP_CHECK_FOR_FIELD( content_language, Content-Language )
454 RESTINIO_HTTP_CHECK_FOR_FIELD( content_location, Content-Location )
455 RESTINIO_HTTP_CHECK_FOR_FIELD( memento_datetime, Memento-Datetime )
456 RESTINIO_HTTP_CHECK_FOR_FIELD( protocol_request, Protocol-Request )
457 RESTINIO_HTTP_CHECK_FOR_FIELD( www_authenticate, WWW-Authenticate )
458 break;
459
460 case 17:
461 RESTINIO_HTTP_CHECK_FOR_FIELD( if_modified_since, If-Modified-Since )
462 RESTINIO_HTTP_CHECK_FOR_FIELD( proxy_instruction, Proxy-Instruction )
463 RESTINIO_HTTP_CHECK_FOR_FIELD( sec_websocket_key, Sec-WebSocket-Key )
464 RESTINIO_HTTP_CHECK_FOR_FIELD( surrogate_control, Surrogate-Control )
465 RESTINIO_HTTP_CHECK_FOR_FIELD( transfer_encoding, Transfer-Encoding )
466 RESTINIO_HTTP_CHECK_FOR_FIELD( resolver_location, Resolver-Location )
467 break;
468
469 case 18:
470 RESTINIO_HTTP_CHECK_FOR_FIELD( content_style_type, Content-Style-Type )
471 RESTINIO_HTTP_CHECK_FOR_FIELD( preference_applied, Preference-Applied )
472 RESTINIO_HTTP_CHECK_FOR_FIELD( proxy_authenticate, Proxy-Authenticate )
473 break;
474
475 case 19:
476 RESTINIO_HTTP_CHECK_FOR_FIELD( authentication_info, Authentication-Info )
477 RESTINIO_HTTP_CHECK_FOR_FIELD( content_disposition, Content-Disposition )
478 RESTINIO_HTTP_CHECK_FOR_FIELD( content_script_type, Content-Script-Type )
479 RESTINIO_HTTP_CHECK_FOR_FIELD( if_unmodified_since, If-Unmodified-Since )
480 RESTINIO_HTTP_CHECK_FOR_FIELD( proxy_authorization, Proxy-Authorization )
481 RESTINIO_HTTP_CHECK_FOR_FIELD( x_device_user_agent, X-Device-User-Agent )
482 break;
483
484 case 20:
485 RESTINIO_HTTP_CHECK_FOR_FIELD( sec_websocket_accept, Sec-WebSocket-Accept )
486 RESTINIO_HTTP_CHECK_FOR_FIELD( surrogate_capability, Surrogate-Capability )
487 RESTINIO_HTTP_CHECK_FOR_FIELD( method_check_expires, Method-Check-Expires )
488 break;
489
490 case 21:
491 RESTINIO_HTTP_CHECK_FOR_FIELD( apply_to_redirect_ref, Apply-To-Redirect-Ref )
492 RESTINIO_HTTP_CHECK_FOR_FIELD( if_schedule_tag_match, If-Schedule-Tag-Match )
493 RESTINIO_HTTP_CHECK_FOR_FIELD( sec_websocket_version, Sec-WebSocket-Version )
494 break;
495
496 case 22:
497 RESTINIO_HTTP_CHECK_FOR_FIELD( authentication_control, Authentication-Control )
498 RESTINIO_HTTP_CHECK_FOR_FIELD( sec_websocket_protocol, Sec-WebSocket-Protocol )
499 RESTINIO_HTTP_CHECK_FOR_FIELD( access_control_max_age, Access-Control-Max-Age )
500 break;
501
502 case 23:
503 RESTINIO_HTTP_CHECK_FOR_FIELD( x_device_accept_charset, X-Device-Accept-Charset )
504 break;
505
506 case 24:
507 RESTINIO_HTTP_CHECK_FOR_FIELD( sec_websocket_extensions, Sec-WebSocket-Extensions )
508 RESTINIO_HTTP_CHECK_FOR_FIELD( x_device_accept_encoding, X-Device-Accept-Encoding )
509 RESTINIO_HTTP_CHECK_FOR_FIELD( x_device_accept_language, X-Device-Accept-Language )
510 break;
511
512 case 25:
513 RESTINIO_HTTP_CHECK_FOR_FIELD( optional_www_authenticate, Optional-WWW-Authenticate )
514 RESTINIO_HTTP_CHECK_FOR_FIELD( proxy_authentication_info, Proxy-Authentication-Info )
515 RESTINIO_HTTP_CHECK_FOR_FIELD( strict_transport_security, Strict-Transport-Security )
516 RESTINIO_HTTP_CHECK_FOR_FIELD( content_transfer_encoding, Content-Transfer-Encoding )
517 break;
518
519 case 27:
520 RESTINIO_HTTP_CHECK_FOR_FIELD( public_key_pins_report_only, Public-Key-Pins-Report-Only )
521 RESTINIO_HTTP_CHECK_FOR_FIELD( access_control_allow_origin, Access-Control-Allow-Origin )
522 break;
523
524 case 28:
525 RESTINIO_HTTP_CHECK_FOR_FIELD( access_control_allow_headers, Access-Control-Allow-Headers )
526 RESTINIO_HTTP_CHECK_FOR_FIELD( access_control_allow_methods, Access-Control-Allow-Methods )
527 break;
528
529 case 29:
530 RESTINIO_HTTP_CHECK_FOR_FIELD( access_control_request_method, Access-Control-Request-Method )
531 break;
532
533 case 30:
534 RESTINIO_HTTP_CHECK_FOR_FIELD( access_control_request_headers, Access-Control-Request-Headers )
535 break;
536
537 case 32:
538 RESTINIO_HTTP_CHECK_FOR_FIELD( access_control_allow_credentials, Access-Control-Allow-Credentials )
539 break;
540 }
541
542#undef RESTINIO_HTTP_CHECK_FOR_FIELD
543
545}
546
547//
548// field_to_string()
549//
550
552inline const char *
554{
555 const char * result = "";
556 switch( f )
557 {
558 #define RESTINIO_HTTP_FIELD_STR_GEN( name, string_name ) \
559 case http_field_t::name: result = #string_name; break;
560
562 #undef RESTINIO_HTTP_FIELD_STR_GEN
563
564 case http_field_t::field_unspecified: break; // Ignore.
565 }
566
567 return result;
568}
569
570//
571// http_header_field_t
572//
573
575
583{
584 public:
587 {}
588
590 std::string name,
591 std::string value )
592 : m_name{ std::move( name ) }
593 , m_value{ std::move( value ) }
595 {}
596
600 : m_name{ name.data(), name.size() }
601 , m_value{ value.data(), value.size() }
603 {}
604
607 std::string value )
609 , m_value{ std::move( value ) }
611 {}
612
617 , m_value{ std::move( value ) }
619 {}
620
621 const std::string & name() const noexcept { return m_name; }
622 const std::string & value() const noexcept { return m_value; }
623 http_field_t field_id() const noexcept { return m_field_id; }
624
625 void
626 name( std::string n )
627 {
628 m_name = std::move( n );
630 }
631
632 void
633 value( std::string v )
634 {
635 m_value = std::move( v );
636 }
637
638 void
640 {
641 m_value.append( v.data(), v.size() );
642 }
643
644 void
646 {
649 }
650
651 private:
652 std::string m_name;
653 std::string m_value;
655};
656
657// Make neccessary forward declarations.
659namespace impl
660{
661
662void
664
665} /* namespace impl */
666
667#if !defined( RESTINIO_HEADER_FIELDS_DEFAULT_RESERVE_COUNT )
668 #define RESTINIO_HEADER_FIELDS_DEFAULT_RESERVE_COUNT 4
669#endif
670
671//
672// http_header_fields_t
673//
674
676
703{
704 friend void
706
707 public:
708 using fields_container_t = std::vector< http_header_field_t >;
709
711 using const_iterator = fields_container_t::const_iterator;
712
714
721 {
727 };
728
729 constexpr static handling_result_t continue_enumeration() noexcept
731
732 constexpr static handling_result_t stop_enumeration() noexcept
734
736 {
738 }
742
745
746 void
747 swap_fields( http_header_fields_t & http_header_fields )
748 {
749 std::swap( m_fields, http_header_fields.m_fields );
750 }
751
753 bool
754 has_field( string_view_t field_name ) const noexcept
755 {
756 return m_fields.cend() != cfind( field_name );
757 }
758
760
765 bool
766 has_field( http_field_t field_id ) const noexcept
767 {
768 return m_fields.cend() != cfind( field_id );
769 }
770
772 void
773 set_field( http_header_field_t http_header_field )
774 {
775 fields_container_t::iterator it;
776 if( http_field_t::field_unspecified != http_header_field.field_id() )
777 {
778 // Field has a standard name.
779 // Search it by id.
780 it = find( http_header_field.field_id() );
781 }
782 else
783 {
784 // Field has a non standard name.
785 // Search it by name.
786 it = find( http_header_field.name() );
787 }
788
789 if( m_fields.end() != it )
790 {
791 *it = std::move( http_header_field );
792 }
793 else
794 {
795 m_fields.emplace_back( std::move( http_header_field ) );
796 }
797 }
798
800 void
802 std::string field_name,
803 std::string field_value )
804 {
805 const auto it = find( field_name );
806
807 if( m_fields.end() != it )
808 {
809 it->name( std::move( field_name ) );
810 it->value( std::move( field_value ) );
811 }
812 else
813 {
814 m_fields.emplace_back(
815 std::move( field_name ),
816 std::move( field_value ) );
817 }
818 }
819
821
825 void
827 http_field_t field_id,
828 std::string field_value )
829 {
830 if( http_field_t::field_unspecified != field_id )
831 {
832 const auto it = find( field_id );
833
834 if( m_fields.end() != it )
835 {
836 it->value( std::move( field_value ) );
837 }
838 else
839 {
840 m_fields.emplace_back(
841 field_id,
842 std::move( field_value ) );
843 }
844 }
845 }
846
859 void
861 http_field_t field_id,
862 std::string field_value )
863 {
864 if( http_field_t::field_unspecified != field_id )
865 {
866 m_fields.emplace_back(
867 field_id,
868 std::move( field_value ) );
869 }
870 }
871
881 void
883 std::string field_name,
884 std::string field_value )
885 {
886 m_fields.emplace_back(
887 std::move( field_name ),
888 std::move( field_value ) );
889 }
890
900 void
901 add_field( http_header_field_t http_header_field )
902 {
903 m_fields.push_back( std::move(http_header_field) );
904 }
905
907 void
909 string_view_t field_name,
910 string_view_t field_value )
911 {
912 const auto it = find( field_name );
913
914 if( m_fields.end() != it )
915 {
916 it->append_value( field_value );
917 }
918 else
919 {
920 m_fields.emplace_back( field_name, field_value );
921 }
922 }
923
925
929 void
931 http_field_t field_id,
932 string_view_t field_value )
933 {
934 if( http_field_t::field_unspecified != field_id )
935 {
936 const auto it = find( field_id );
937
938 if( m_fields.end() != it )
939 {
940 it->append_value( field_value );
941 }
942 else
943 {
944 m_fields.emplace_back( field_id, field_value );
945 }
946 }
947 }
948
950 const std::string &
951 get_field( string_view_t field_name ) const
952 {
953 const auto it = cfind( field_name );
954
955 if( m_fields.end() == it )
956 throw exception_t{
957 fmt::format(
958 RESTINIO_FMT_FORMAT_STRING( "field '{}' doesn't exist" ),
959 fmtlib_tools::streamed( field_name ) ) };
960
961 return it->value();
962 }
963
965
977 try_get_field( string_view_t field_name ) const noexcept
978 {
979 const auto it = cfind( field_name );
980 if( m_fields.end() == it )
981 return nullptr;
982 else
983 return std::addressof(it->value());
984 }
985
987 const std::string &
988 get_field( http_field_t field_id ) const
989 {
990 if( http_field_t::field_unspecified == field_id )
991 {
992 throw exception_t{
993 "unspecified fields cannot be searched by id" };
994 }
995
996 const auto it = cfind( field_id );
997
998 if( m_fields.end() == it )
999 {
1000 throw exception_t{
1001 fmt::format(
1002 RESTINIO_FMT_FORMAT_STRING( "field '{}' doesn't exist" ),
1003 field_to_string( field_id ) ) };
1004 }
1005
1006 return it->value();
1007 }
1008
1010
1022 try_get_field( http_field_t field_id ) const noexcept
1023 {
1024 if( http_field_t::field_unspecified != field_id )
1025 {
1026 const auto it = cfind( field_id );
1027 if( m_fields.end() != it )
1028 return std::addressof(it->value());
1029 }
1030
1031 return nullptr;
1032 }
1033
1035
1040 std::string
1042 string_view_t field_name,
1043 string_view_t default_value ) const
1044 {
1045 const auto it = cfind( field_name );
1046
1047 if( m_fields.end() == it )
1048 return std::string( default_value.data(), default_value.size() );
1049
1050 return it->value();
1051 }
1052
1054
1059 std::string
1061 string_view_t field_name,
1062 std::string && default_value ) const
1063 {
1064 const auto it = cfind( field_name );
1065
1066 if( m_fields.end() == it )
1067 return std::move(default_value);
1068
1069 return it->value();
1070 }
1071
1073
1076 auto
1078 string_view_t field_name,
1079 const char * default_value ) const
1080 {
1081 return this->get_field_or( field_name, string_view_t{ default_value } );
1082 }
1083
1085
1088 auto
1090 string_view_t field_name,
1091 const std::string & default_value ) const
1092 {
1093 return this->get_field_or( field_name, string_view_t{ default_value } );
1094 }
1095
1097
1102 std::string
1104 http_field_t field_id,
1105 string_view_t default_value ) const
1106 {
1107 if( http_field_t::field_unspecified != field_id )
1108 {
1109 const auto it = cfind( field_id );
1110
1111 if( m_fields.end() != it )
1112 return it->value();
1113 }
1114
1115 return std::string( default_value.data(), default_value.size() );
1116 }
1117
1119
1122 auto
1124 http_field_t field_id,
1125 const char * default_value ) const
1126 {
1127 return this->get_field_or( field_id, string_view_t{ default_value } );
1128 }
1129
1131
1134 auto
1136 http_field_t field_id,
1137 const std::string & default_value ) const
1138 {
1139 return this->get_field_or( field_id, string_view_t{ default_value } );
1140 }
1141
1143
1148 std::string
1150 http_field_t field_id,
1151 std::string && default_value ) const
1152 {
1153 if( http_field_t::field_unspecified != field_id )
1154 {
1155 const auto it = cfind( field_id );
1156
1157 if( m_fields.end() != it )
1158 return it->value();
1159 }
1160
1161 return std::move( default_value );
1162 }
1163
1165
1174 bool
1175 remove_field( string_view_t field_name ) noexcept
1176 {
1177 const auto it = find( field_name );
1178
1179 if( m_fields.end() != it )
1180 {
1181 m_fields.erase( it );
1182 return true;
1183 }
1184
1185 return false;
1186 }
1187
1189
1198 bool
1199 remove_field( http_field_t field_id ) noexcept
1200 {
1201 if( http_field_t::field_unspecified != field_id )
1202 {
1203 const auto it = find( field_id );
1204
1205 if( m_fields.end() != it )
1206 {
1207 m_fields.erase( it );
1208 return true;
1209 }
1210 }
1211
1212 return false;
1213 }
1214
1216
1221 std::size_t
1222 remove_all_of( string_view_t field_name ) noexcept
1223 {
1224 std::size_t count{};
1225 for( auto it = m_fields.begin(); it != m_fields.end(); )
1226 {
1227 if( impl::is_equal_caseless( it->name(), field_name ) )
1228 {
1229 it = m_fields.erase( it );
1230 ++count;
1231 }
1232 else
1233 ++it;
1234 }
1235
1236 return count;
1237 }
1238
1240
1245 std::size_t
1246 remove_all_of( http_field_t field_id ) noexcept
1247 {
1248 std::size_t count{};
1249 if( http_field_t::field_unspecified != field_id )
1250 {
1251 for( auto it = m_fields.begin(); it != m_fields.end(); )
1252 {
1253 if( it->field_id() == field_id )
1254 {
1255 it = m_fields.erase( it );
1256 ++count;
1257 }
1258 else
1259 ++it;
1260 }
1261 }
1262
1263 return count;
1264 }
1265
1274 string_view_t name ) const
1275 {
1276 return { this->get_field(name) };
1277 }
1278
1283 http_field_t field_id ) const
1284 {
1285 return { this->get_field(field_id) };
1286 }
1287
1289
1303 string_view_t name ) const noexcept
1304 {
1306
1307 if( auto * ptr = this->try_get_field(name) )
1308 result = string_view_t{ *ptr };
1309
1310 return result;
1311 }
1312
1314
1328 http_field_t field_id ) const noexcept
1329 {
1331
1332 if( auto * ptr = this->try_get_field(field_id) )
1333 result = string_view_t{ *ptr };
1334
1335 return result;
1336 }
1342
1360 template< typename Lambda >
1361 void
1362 for_each_field( Lambda && lambda ) const
1363 noexcept(noexcept(lambda(
1364 std::declval<const http_header_field_t &>())))
1365 {
1366 for( const auto & f : m_fields )
1367 lambda( f );
1368 }
1369
1371
1400 template< typename Lambda >
1401 void
1403 http_field_t field_id,
1404 Lambda && lambda ) const
1405 noexcept(noexcept(lambda(
1406 std::declval<const string_view_t &>())))
1407 {
1408 static_assert(
1409 std::is_same<
1411 decltype(lambda(std::declval<const string_view_t &>()))
1412 >::value,
1413 "lambda should return restinio::http_header_fields_t::handling_result_t" );
1414
1415 for( const auto & f : m_fields )
1416 {
1417 if( field_id == f.field_id() )
1418 {
1419 const handling_result_t r = lambda( f.value() );
1420 if( stop_enumeration() == r )
1421 break;
1422 }
1423 }
1424 }
1425
1427
1456 template< typename Lambda >
1457 void
1459 string_view_t field_name,
1460 Lambda && lambda ) const
1461 noexcept(noexcept(lambda(
1462 std::declval<const string_view_t &>())))
1463 {
1464 static_assert(
1465 std::is_same<
1467 decltype(lambda(std::declval<const string_view_t &>()))
1468 >::value,
1469 "lambda should return restinio::http_header_fields_t::handling_result_t" );
1470
1471 for( const auto & f : m_fields )
1472 {
1473 if( impl::is_equal_caseless( f.name(), field_name ) )
1474 {
1475 const handling_result_t r = lambda( f.value() );
1476 if( stop_enumeration() == r )
1477 break;
1478 }
1479 }
1480 }
1481
1483 begin() const noexcept
1484 {
1485 return m_fields.cbegin();
1486 }
1487
1489 end() const noexcept
1490 {
1491 return m_fields.cend();
1492 }
1493
1494 auto fields_count() const noexcept
1495 {
1496 return m_fields.size();
1497 }
1498
1499 private:
1501
1509 void
1511 {
1512 m_fields.back().append_value( field_value );
1513 }
1514
1515 fields_container_t::iterator
1516 find( string_view_t field_name ) noexcept
1517 {
1518 return std::find_if(
1519 m_fields.begin(),
1520 m_fields.end(),
1521 [&]( const auto & f ){
1522 return impl::is_equal_caseless( f.name(), field_name );
1523 } );
1524 }
1525
1526 fields_container_t::const_iterator
1527 cfind( string_view_t field_name ) const noexcept
1528 {
1529 return std::find_if(
1530 m_fields.cbegin(),
1531 m_fields.cend(),
1532 [&]( const auto & f ){
1533 return impl::is_equal_caseless( f.name(), field_name );
1534 } );
1535 }
1536
1537 fields_container_t::iterator
1538 find( http_field_t field_id ) noexcept
1539 {
1540 return std::find_if(
1541 m_fields.begin(),
1542 m_fields.end(),
1543 [&]( const auto & f ){
1544 return f.field_id() == field_id;
1545 } );
1546 }
1547
1548 fields_container_t::const_iterator
1549 cfind( http_field_t field_id ) const noexcept
1550 {
1551 return std::find_if(
1552 m_fields.cbegin(),
1553 m_fields.cend(),
1554 [&]( const auto & f ){
1555 return f.field_id() == field_id;
1556 } );
1557 }
1558
1560};
1561
1562//
1563// http_connection_header_t
1564//
1565
1567enum class http_connection_header_t : std::uint8_t
1568{
1569 keep_alive,
1570 close,
1571 upgrade
1572};
1573
1574//
1575// http_header_common_t
1576//
1577
1580 : public http_header_fields_t
1581{
1582 public:
1585 std::uint16_t
1587 { return m_http_major; }
1588
1589 void
1590 http_major( std::uint16_t v ) noexcept
1591 { m_http_major = v; }
1592
1593 std::uint16_t
1595 { return m_http_minor; }
1596
1597 void
1598 http_minor( std::uint16_t v ) noexcept
1599 { m_http_minor = v; }
1601
1603 std::uint64_t
1605 { return m_content_length; }
1606
1607 void
1608 content_length( std::uint64_t l ) noexcept
1609 { m_content_length = l; }
1610
1611 bool
1613 {
1615 }
1616
1617 void
1619 {
1623 }
1624
1628 {
1630 }
1631
1633 void
1635 {
1637 }
1638
1639 private:
1642 std::uint16_t m_http_major{1};
1643 std::uint16_t m_http_minor{1};
1645
1647 std::uint64_t m_content_length{ 0 };
1648
1650};
1651
1653#define RESTINIO_HTTP_METHOD_MAP(RESTINIO_GEN) \
1654 RESTINIO_GEN( http_method_delete, HTTP_DELETE, DELETE ) \
1655 RESTINIO_GEN( http_method_get, HTTP_GET, GET ) \
1656 RESTINIO_GEN( http_method_head, HTTP_HEAD, HEAD ) \
1657 RESTINIO_GEN( http_method_post, HTTP_POST, POST ) \
1658 RESTINIO_GEN( http_method_put, HTTP_PUT, PUT ) \
1659 /* pathological */ \
1660 RESTINIO_GEN( http_method_connect, HTTP_CONNECT, CONNECT ) \
1661 RESTINIO_GEN( http_method_options, HTTP_OPTIONS, OPTIONS ) \
1662 RESTINIO_GEN( http_method_trace, HTTP_TRACE, TRACE ) \
1663 /* WebDAV */ \
1664 RESTINIO_GEN( http_method_copy, HTTP_COPY, COPY ) \
1665 RESTINIO_GEN( http_method_lock, HTTP_LOCK, LOCK ) \
1666 RESTINIO_GEN( http_method_mkcol, HTTP_MKCOL, MKCOL ) \
1667 RESTINIO_GEN( http_method_move, HTTP_MOVE, MOVE ) \
1668 RESTINIO_GEN( http_method_propfind, HTTP_PROPFIND, PROPFIND ) \
1669 RESTINIO_GEN( http_method_proppatch, HTTP_PROPPATCH, PROPPATCH ) \
1670 RESTINIO_GEN( http_method_search, HTTP_SEARCH, SEARCH ) \
1671 RESTINIO_GEN( http_method_unlock, HTTP_UNLOCK, UNLOCK ) \
1672 RESTINIO_GEN( http_method_bind, HTTP_BIND, BIND ) \
1673 RESTINIO_GEN( http_method_rebind, HTTP_REBIND, REBIND ) \
1674 RESTINIO_GEN( http_method_unbind, HTTP_UNBIND, UNBIND ) \
1675 RESTINIO_GEN( http_method_acl, HTTP_ACL, ACL ) \
1676 /* subversion */ \
1677 RESTINIO_GEN( http_method_report, HTTP_REPORT, REPORT ) \
1678 RESTINIO_GEN( http_method_mkactivity, HTTP_MKACTIVITY, MKACTIVITY ) \
1679 RESTINIO_GEN( http_method_checkout, HTTP_CHECKOUT, CHECKOUT ) \
1680 RESTINIO_GEN( http_method_merge, HTTP_MERGE, MERGE ) \
1681 /* upnp */ \
1682 RESTINIO_GEN( http_method_msearch, HTTP_MSEARCH, M-SEARCH) \
1683 RESTINIO_GEN( http_method_notify, HTTP_NOTIFY, NOTIFY ) \
1684 RESTINIO_GEN( http_method_subscribe, HTTP_SUBSCRIBE, SUBSCRIBE ) \
1685 RESTINIO_GEN( http_method_unsubscribe, HTTP_UNSUBSCRIBE, UNSUBSCRIBE ) \
1686 /* RFC-5789 */ \
1687 RESTINIO_GEN( http_method_patch, HTTP_PATCH, PATCH ) \
1688 RESTINIO_GEN( http_method_purge, HTTP_PURGE, PURGE ) \
1689 /* CalDAV */ \
1690 RESTINIO_GEN( http_method_mkcalendar, HTTP_MKCALENDAR, MKCALENDAR ) \
1691 /* RFC-2068, section 19.6.1.2 */ \
1692 RESTINIO_GEN( http_method_link, HTTP_LINK, LINK ) \
1693 RESTINIO_GEN( http_method_unlink, HTTP_UNLINK, UNLINK )
1694
1695//
1696// http_method_id_t
1697//
1745{
1747 const char * m_name;
1748
1749public:
1750 static constexpr const int unknown_method = -1;
1751
1752 constexpr http_method_id_t() noexcept
1754 , m_name{ "<undefined>" }
1755 {}
1757 int value,
1758 const char * name ) noexcept
1759 : m_value{ value }
1760 , m_name{ name }
1761 {}
1762
1763 constexpr http_method_id_t( const http_method_id_t & ) noexcept = default;
1764 constexpr http_method_id_t &
1765 operator=( const http_method_id_t & ) noexcept = default;
1766
1767 constexpr http_method_id_t( http_method_id_t && ) noexcept = default;
1768 constexpr http_method_id_t &
1769 operator=( http_method_id_t && ) noexcept = default;
1770
1771 constexpr auto
1772 raw_id() const noexcept { return m_value; }
1773
1774 constexpr const char *
1775 c_str() const noexcept { return m_name; }
1776
1777 friend constexpr bool
1778 operator==( const http_method_id_t & a, const http_method_id_t & b ) noexcept {
1779 return a.raw_id() == b.raw_id();
1780 }
1781
1782 friend constexpr bool
1783 operator!=( const http_method_id_t & a, const http_method_id_t & b ) noexcept {
1784 return a.raw_id() != b.raw_id();
1785 }
1786
1787 friend constexpr bool
1788 operator<( const http_method_id_t & a, const http_method_id_t & b ) noexcept {
1789 return a.raw_id() < b.raw_id();
1790 }
1791};
1792
1793inline std::ostream &
1794operator<<( std::ostream & to, const http_method_id_t & m )
1795{
1796 return to << m.c_str();
1797}
1798
1799// Generate helper funcs.
1800#define RESTINIO_HTTP_METHOD_FUNC_GEN( func_name, nodejs_code, method_name ) \
1801 inline constexpr http_method_id_t func_name() { \
1802 return { nodejs_code, #method_name }; \
1803 }
1804
1806#undef RESTINIO_HTTP_METHOD_FUNC_GEN
1807
1808inline constexpr http_method_id_t
1810{
1811 return http_method_id_t{};
1812}
1813
1814//
1815// default_http_methods_t
1816//
1833{
1834public :
1835 inline static constexpr http_method_id_t
1836 from_nodejs( int value ) noexcept
1837 {
1838 http_method_id_t result;
1839 switch( value )
1840 {
1841#define RESTINIO_HTTP_METHOD_FUNC_GEN( func_name, nodejs_code, method_name ) \
1842 case nodejs_code : result = func_name(); break;
1843
1845#undef RESTINIO_HTTP_METHOD_FUNC_GEN
1846 default : ; // Nothing to do.
1847 }
1848
1849 return result;
1850 }
1851};
1852
1853//
1854// http_request_header
1855//
1856
1859 : public http_header_common_t
1860{
1861 static std::size_t
1862 memchr_helper( int chr , const char * from, std::size_t size )
1863 {
1864 const char * result = static_cast< const char * >(
1865 std::memchr( from, chr, size ) );
1866
1867 return result ? static_cast< std::size_t >( result - from ) : size;
1868 }
1869
1870 public:
1872
1875 std::string request_target_ )
1876 : m_method{ method }
1877 {
1878 request_target( std::move( request_target_ ) );
1879 }
1880
1882 method() const noexcept
1883 { return m_method; }
1884
1885 void
1887 { m_method = m; }
1888
1889 const std::string &
1891 { return m_request_target; }
1892
1893 void
1894 request_target( std::string t )
1895 {
1896 m_request_target.assign( std::move( t ) );
1897
1899 memchr_helper( '#', m_request_target.data(), m_request_target.size() );
1900
1903 }
1904
1907
1909
1914 path() const noexcept
1915 {
1917 }
1918
1920
1925 query() const noexcept
1926 {
1927 return
1929 string_view_t{ nullptr, 0 } :
1933 }
1934
1935
1937
1942 fragment() const
1943 {
1944 return
1946 string_view_t{ nullptr, 0 } :
1950 }
1952
1954 void
1955 append_request_target( const char * at, size_t length )
1956 {
1958 {
1959 // If fragment separator hadn't already appeared,
1960 // search for it in a new block.
1961
1962 const auto fragment_separator_pos_inc =
1963 memchr_helper( '#', at, length );
1964
1965 m_fragment_separator_pos += fragment_separator_pos_inc;
1966
1968 {
1969 // If request separator hadn't already appeared,
1970 // search for it in a new block.
1972 memchr_helper( '?', at, fragment_separator_pos_inc );
1973 }
1974 }
1975 // Else fragment separator appeared
1976 // (req separator is either already defined or does not exist)
1977
1978 m_request_target.append( at, length );
1979 }
1980
1981 private:
1982 http_method_id_t m_method{ http_method_get() };
1983 std::string m_request_target;
1984 std::size_t m_query_separator_pos{ 0 };
1986};
1987
1988//
1989// http_status_code_t
1990//
1991
1994{
1995 public:
1996 constexpr http_status_code_t() noexcept
1997 {}
1998
1999 constexpr explicit http_status_code_t( std::uint16_t status_code ) noexcept
2000 : m_status_code{ status_code }
2001 {}
2002
2003 constexpr auto
2004 raw_code() const noexcept
2005 {
2006 return m_status_code;
2007 }
2008
2009 constexpr bool
2010 operator == ( const http_status_code_t & sc ) const noexcept
2011 {
2012 return raw_code() == sc.raw_code();
2013 }
2014
2015 constexpr bool
2016 operator != ( const http_status_code_t & sc ) const noexcept
2017 {
2018 return sc.raw_code() != sc.raw_code();
2019 }
2020
2021 constexpr bool
2022 operator < ( const http_status_code_t & sc ) const noexcept
2023 {
2024 return sc.raw_code() < sc.raw_code();
2025 }
2026
2027 private:
2029 std::uint16_t m_status_code{ 0 };
2030};
2031
2032namespace status_code
2033{
2034
2039
2040// Add '_', because 'continue is reserved word.'
2042
2044constexpr http_status_code_t ok{ 200 };
2053constexpr http_status_code_t found{ 302 };
2068constexpr http_status_code_t gone{ 410 };
2071
2072//413 Payload Too Large (RFC 7231)
2073// The request is larger than the server is willing or able to process.
2074// Previously called "Request Entity Too Large".[44]
2076
2077// 414 URI Too Long (RFC 7231)
2078// The URI provided was too long for the server to process.
2079// Often the result of too much data being encoded as a query-string of a GET request,
2080// in which case it should be converted to a POST request.
2081// Called "Request-URI Too Long" previously.[46]
2083
2094
2099 // RFC 7538
2101
2102 // RFC 2518
2109
2110 // RFC 6585
2116
2117} /* namespace status_code */
2118
2119//
2120// http_status_line_t
2121//
2122
2125{
2126 public:
2128 {}
2129
2132 std::string reason_phrase )
2133 : m_status_code{ sc }
2134 , m_reason_phrase{ std::move( reason_phrase ) }
2135 {}
2136
2139 { return m_status_code; }
2140
2141 void
2143 { m_status_code = c; }
2144
2145 const std::string &
2147 { return m_reason_phrase; }
2148
2149 void
2150 reason_phrase( std::string r )
2151 { m_reason_phrase.assign( std::move( r ) ); }
2152
2153 private:
2155 std::string m_reason_phrase;
2156};
2157
2158inline std::ostream &
2159operator << ( std::ostream & o, const http_status_line_t & status_line )
2160{
2161 return o << "{" << status_line.status_code().raw_code() << ", "
2162 << status_line.reason_phrase() << "}";
2163}
2164
2169
2171{ return http_status_line_t{ status_code::continue_, "Continue" }; }
2172
2174{ return http_status_line_t{ status_code::switching_protocols, "Switching Protocols" }; }
2175
2177{ return http_status_line_t{ status_code::ok, "OK" }; }
2178
2180{ return http_status_line_t{ status_code::created, "Created" }; }
2181
2183{ return http_status_line_t{ status_code::accepted, "Accepted" }; }
2184
2186{ return http_status_line_t{ status_code::non_authoritative_information, "Non-Authoritative Information" }; }
2187
2189{ return http_status_line_t{ status_code::no_content, "No Content" }; }
2190
2192{ return http_status_line_t{ status_code::reset_content, "Reset Content" }; }
2193
2195{ return http_status_line_t{ status_code::partial_content, "Partial Content" }; }
2196
2198{ return http_status_line_t{ status_code::multiple_choices, "Multiple Choices" }; }
2199
2201{ return http_status_line_t{ status_code::moved_permanently, "Moved Permanently" }; }
2202
2204{ return http_status_line_t{ status_code::found, "Found" }; }
2205
2207{ return http_status_line_t{ status_code::see_other, "See Other" }; }
2208
2210{ return http_status_line_t{ status_code::not_modified, "Not Modified" }; }
2211
2213{ return http_status_line_t{ status_code::use_proxy, "Use Proxy" }; }
2214
2216{ return http_status_line_t{ status_code::temporary_redirect, "Temporary Redirect" }; }
2217
2219{ return http_status_line_t{ status_code::bad_request, "Bad Request" }; }
2220
2222{ return http_status_line_t{ status_code::unauthorized, "Unauthorized" }; }
2223
2225{ return http_status_line_t{ status_code::payment_required, "Payment Required" }; }
2226
2228{ return http_status_line_t{ status_code::forbidden, "Forbidden" }; }
2229
2231{ return http_status_line_t{ status_code::not_found, "Not Found" }; }
2232
2234{ return http_status_line_t{ status_code::method_not_allowed, "Method Not Allowed" }; }
2235
2237{ return http_status_line_t{ status_code::not_acceptable, "Not Acceptable" }; }
2238
2240{ return http_status_line_t{status_code::proxy_authentication_required, "Proxy Authentication Required" }; }
2241
2243{ return http_status_line_t{ status_code::request_time_out, "Request Timeout" }; }
2244
2246{ return http_status_line_t{ status_code::conflict, "Conflict" }; }
2247
2249{ return http_status_line_t{ status_code::gone, "Gone" }; }
2250
2252{ return http_status_line_t{ status_code::length_required, "Length Required" }; }
2253
2255{ return http_status_line_t{ status_code::precondition_failed, "Precondition Failed" }; }
2256
2258{ return http_status_line_t{ status_code::payload_too_large, "Payload Too Large" }; }
2259
2261{ return http_status_line_t{ status_code::uri_too_long, "URI Too Long" }; }
2262
2264{ return http_status_line_t{ status_code::unsupported_media_type, "Unsupported Media Type" }; }
2265
2267{ return http_status_line_t{ status_code::requested_range_not_satisfiable, "Requested Range Not Satisfiable" }; }
2268
2270{ return http_status_line_t{ status_code::expectation_failed, "Expectation Failed" }; }
2271
2273{ return http_status_line_t{ status_code::internal_server_error, "Internal Server Error" }; }
2274
2276{ return http_status_line_t{ status_code::not_implemented, "Not Implemented" }; }
2277
2279{ return http_status_line_t{ status_code::bad_gateway, "Bad Gateway" }; }
2280
2282{ return http_status_line_t{ status_code::service_unavailable, "Service Unavailable" }; }
2283
2285{ return http_status_line_t{ status_code::gateway_time_out, "Gateway Timeout" }; }
2286
2288{ return http_status_line_t{ status_code::http_version_not_supported, "HTTP Version not supported" }; }
2290
2295 // RFC 7538
2297{ return http_status_line_t{ status_code::permanent_redirect, "Permanent Redirect" }; }
2298
2299 // RFC 2518
2301{ return http_status_line_t{ status_code::processing, "Processing" }; }
2302
2304{ return http_status_line_t{ status_code::multi_status, "Multi-Status" }; }
2305
2307{ return http_status_line_t{ status_code::unprocessable_entity, "Unprocessable Entity" }; }
2308
2310{ return http_status_line_t{ status_code::locked, "Locked" }; }
2311
2313{ return http_status_line_t{ status_code::failed_dependency, "Failed Dependency" }; }
2314
2316{ return http_status_line_t{ status_code::insufficient_storage, "Insufficient Storage" }; }
2317
2318 // RFC 6585
2320{ return http_status_line_t{ status_code::precondition_required, "Precondition Required" }; }
2321
2323{ return http_status_line_t{ status_code::too_many_requests, "Too Many Requests" }; }
2324
2326{ return http_status_line_t{ status_code::request_header_fields_too_large, "Request Header Fields Too Large" }; }
2327
2329{ return http_status_line_t{ status_code::network_authentication_required, "Network Authentication Required" }; }
2331
2332//
2333// http_response_header_t
2334//
2335
2338 : public http_header_common_t
2339{
2340 public:
2342 {}
2343
2345 : m_status_line{ std::move( status_line ) }
2346 {}
2347
2350 { return m_status_line.status_code(); }
2351
2352 void
2354 { m_status_line.status_code( c ); }
2355
2356 const std::string &
2358 { return m_status_line.reason_phrase(); }
2359
2360 void
2361 reason_phrase( std::string r )
2362 { m_status_line.reason_phrase( std::move( r ) ); }
2363
2364 const http_status_line_t &
2366 {
2367 return m_status_line;
2368 }
2369
2370 void
2372 {
2373 m_status_line = std::move( sl );
2374 }
2375
2376 private:
2378};
2379
2380} /* namespace restinio */
The default implementation for http_method_mapper.
static constexpr http_method_id_t from_nodejs(int value) noexcept
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
A single header field.
http_header_field_t(http_field_t field_id, string_view_t value)
void field_id(http_field_t field_id)
http_header_field_t(std::string name, std::string value)
const std::string & value() const noexcept
http_header_field_t(string_view_t name, string_view_t value)
const std::string & name() const noexcept
http_field_t field_id() const noexcept
http_header_field_t(http_field_t field_id, std::string value)
void append_value(string_view_t v)
bool has_field(string_view_t field_name) const noexcept
Check field by name.
string_view_t value_of(string_view_t name) const
Get the value of a field or throw if the field not found.
void add_field(http_header_field_t http_header_field)
Add a field in the form of http_header_field object.
http_header_fields_t(const http_header_fields_t &)=default
void add_field(http_field_t field_id, std::string field_value)
Add a field in the form of id-value pair.
string_view_t value_of(http_field_t field_id) const
Get the value of a field or throw if the field not found.
fields_container_t::iterator find(string_view_t field_name) noexcept
nullable_pointer_t< const std::string > try_get_field(http_field_t field_id) const noexcept
Try to get the value of a field by field ID.
std::size_t remove_all_of(string_view_t field_name) noexcept
Remove all occurences of a field with specified name.
http_header_fields_t(http_header_fields_t &&)=default
fields_container_t::const_iterator const_iterator
Type of const_iterator for enumeration of fields.
static constexpr handling_result_t stop_enumeration() noexcept
void swap_fields(http_header_fields_t &http_header_fields)
auto get_field_or(string_view_t field_name, const char *default_value) const
Get field by name or default value if the field not found.
std::vector< http_header_field_t > fields_container_t
optional_t< string_view_t > opt_value_of(string_view_t name) const noexcept
Get optional value of a field.
static constexpr handling_result_t continue_enumeration() noexcept
fields_container_t::const_iterator cfind(string_view_t field_name) const noexcept
void for_each_value_of(http_field_t field_id, Lambda &&lambda) const noexcept(noexcept(lambda(std::declval< const string_view_t & >())))
Enumeration of each value of a field.
void add_field(std::string field_name, std::string field_value)
Add a field in the form of name-value pair.
void for_each_value_of(string_view_t field_name, Lambda &&lambda) const noexcept(noexcept(lambda(std::declval< const string_view_t & >())))
Enumeration of each value of a field.
bool remove_field(http_field_t field_id) noexcept
Remove field by id.
http_header_fields_t & operator=(const http_header_fields_t &)=default
const std::string & get_field(http_field_t field_id) const
Get field by id.
void set_field(std::string field_name, std::string field_value)
Set field with string pair.
std::string get_field_or(string_view_t field_name, std::string &&default_value) const
Get field value by field name or default value if the field not found.
void set_field(http_field_t field_id, std::string field_value)
Set field with id-value pair.
http_header_fields_t & operator=(http_header_fields_t &&)=default
std::string get_field_or(http_field_t field_id, std::string &&default_value) const
Get field by id or default value if the field not found.
handling_result_t
The result of handling yet another field value.
@ stop_enumeration
The loop on field values should be stopped.
@ continue_enumeration
Next value of field should be found and passed to the next invocation of handler.
nullable_pointer_t< const std::string > try_get_field(string_view_t field_name) const noexcept
Try to get the value of a field by field name.
void append_last_field(string_view_t field_value)
Appends last added field.
optional_t< string_view_t > opt_value_of(http_field_t field_id) const noexcept
Get optional value of a field.
std::string get_field_or(http_field_t field_id, string_view_t default_value) const
Get field by id or default value if the field not found.
void set_field(http_header_field_t http_header_field)
Set header field via http_header_field_t.
void for_each_field(Lambda &&lambda) const noexcept(noexcept(lambda(std::declval< const http_header_field_t & >())))
Enumeration of fields.
void append_field(string_view_t field_name, string_view_t field_value)
Append field with name.
auto get_field_or(http_field_t field_id, const char *default_value) const
Get field by id or default value if the field not found.
const_iterator end() const noexcept
const std::string & get_field(string_view_t field_name) const
Get field by name.
auto fields_count() const noexcept
auto get_field_or(string_view_t field_name, const std::string &default_value) const
Get field by name or default value if the field not found.
const_iterator begin() const noexcept
bool remove_field(string_view_t field_name) noexcept
Remove field by name.
std::string get_field_or(string_view_t field_name, string_view_t default_value) const
Get field value by field name or default value if the field not found.
bool has_field(http_field_t field_id) const noexcept
Check field by field-id.
fields_container_t::const_iterator cfind(http_field_t field_id) const noexcept
auto get_field_or(http_field_t field_id, const std::string &default_value) const
Get field by id or default value if the field not found.
std::size_t remove_all_of(http_field_t field_id) noexcept
Remove all occurences of a field with specified id.
fields_container_t::iterator find(http_field_t field_id) noexcept
void append_field(http_field_t field_id, string_view_t field_value)
Append field with id.
A type for representation of HTTP method ID.
friend constexpr bool operator<(const http_method_id_t &a, const http_method_id_t &b) noexcept
static constexpr const int unknown_method
constexpr http_method_id_t(const http_method_id_t &) noexcept=default
friend constexpr bool operator!=(const http_method_id_t &a, const http_method_id_t &b) noexcept
constexpr http_method_id_t() noexcept
constexpr http_method_id_t(http_method_id_t &&) noexcept=default
constexpr auto raw_id() const noexcept
constexpr http_method_id_t & operator=(const http_method_id_t &) noexcept=default
constexpr http_method_id_t(int value, const char *name) noexcept
friend constexpr bool operator==(const http_method_id_t &a, const http_method_id_t &b) noexcept
constexpr const char * c_str() const noexcept
A handy wrapper for HTTP response status code.
constexpr auto raw_code() const noexcept
constexpr http_status_code_t() noexcept
constexpr http_status_code_t(std::uint16_t status_code) noexcept
std::uint16_t m_status_code
Status code value.
HTTP response header status line.
void reason_phrase(std::string r)
void status_code(http_status_code_t c) noexcept
http_status_line_t(http_status_code_t sc, std::string reason_phrase)
http_status_code_t status_code() const noexcept
http_status_code_t m_status_code
const std::string & reason_phrase() const noexcept
#define RESTINIO_HTTP_METHOD_MAP(RESTINIO_GEN)
HTTP methods mapping with nodejs http methods.
#define RESTINIO_HEADER_FIELDS_DEFAULT_RESERVE_COUNT
#define RESTINIO_HTTP_METHOD_FUNC_GEN(func_name, nodejs_code, method_name)
#define RESTINIO_HTTP_FIELD_STR_GEN(name, string_name)
#define RESTINIO_HTTP_FIELDS_MAP(RESTINIO_GEN)
#define RESTINIO_HTTP_CHECK_FOR_FIELD(field_id, candidate_field_name)
A special wrapper around fmtlib include files.
#define RESTINIO_FMT_FORMAT_STRING(s)
decltype(auto) streamed(T &&v) noexcept
bool is_equal_caseless(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
void append_last_field_accessor(http_header_fields_t &, string_view_t)
constexpr http_status_code_t switching_protocols
constexpr http_status_code_t gone
constexpr http_status_code_t precondition_failed
constexpr http_status_code_t ok
constexpr http_status_code_t unauthorized
constexpr http_status_code_t bad_request
constexpr http_status_code_t see_other
constexpr http_status_code_t multiple_choices
constexpr http_status_code_t not_acceptable
constexpr http_status_code_t not_found
constexpr http_status_code_t forbidden
constexpr http_status_code_t gateway_time_out
constexpr http_status_code_t uri_too_long
constexpr http_status_code_t partial_content
constexpr http_status_code_t requested_range_not_satisfiable
constexpr http_status_code_t unsupported_media_type
constexpr http_status_code_t locked
constexpr http_status_code_t not_implemented
constexpr http_status_code_t request_header_fields_too_large
constexpr http_status_code_t payload_too_large
constexpr http_status_code_t failed_dependency
constexpr http_status_code_t unprocessable_entity
constexpr http_status_code_t conflict
constexpr http_status_code_t network_authentication_required
constexpr http_status_code_t not_modified
constexpr http_status_code_t no_content
constexpr http_status_code_t accepted
constexpr http_status_code_t created
constexpr http_status_code_t http_version_not_supported
constexpr http_status_code_t multi_status
constexpr http_status_code_t processing
constexpr http_status_code_t bad_gateway
constexpr http_status_code_t use_proxy
constexpr http_status_code_t found
constexpr http_status_code_t continue_
constexpr http_status_code_t temporary_redirect
constexpr http_status_code_t method_not_allowed
constexpr http_status_code_t permanent_redirect
constexpr http_status_code_t length_required
constexpr http_status_code_t insufficient_storage
constexpr http_status_code_t service_unavailable
constexpr http_status_code_t precondition_required
constexpr http_status_code_t request_time_out
constexpr http_status_code_t internal_server_error
constexpr http_status_code_t too_many_requests
constexpr http_status_code_t proxy_authentication_required
constexpr http_status_code_t payment_required
constexpr http_status_code_t moved_permanently
constexpr http_status_code_t reset_content
constexpr http_status_code_t expectation_failed
constexpr http_status_code_t non_authoritative_information
http_status_line_t status_gone()
http_status_line_t status_not_acceptable()
http_status_line_t status_non_authoritative_information()
http_status_line_t status_locked()
http_status_line_t status_not_implemented()
http_status_line_t status_unprocessable_entity()
T * nullable_pointer_t
Type for pointer that can be nullptr.
http_status_line_t status_http_version_not_supported()
http_status_line_t status_payment_required()
http_status_line_t status_conflict()
http_status_line_t status_permanent_redirect()
http_status_line_t status_partial_content()
nonstd::string_view string_view_t
Definition: string_view.hpp:19
http_status_line_t status_no_content()
http_status_line_t status_network_authentication_required()
http_status_line_t status_not_modified()
http_status_line_t status_failed_dependency()
http_status_line_t status_moved_permanently()
http_status_line_t status_forbidden()
http_connection_header_t
Values for conection header field.
std::ostream & operator<<(std::ostream &o, response_parts_attr_t attr)
http_status_line_t status_continue()
http_status_line_t status_requested_range_not_satisfiable()
http_status_line_t status_internal_server_error()
http_status_line_t status_use_proxy()
http_status_line_t status_request_time_out()
http_status_line_t status_created()
http_status_line_t status_unauthorized()
http_status_line_t status_temporary_redirect()
http_status_line_t status_gateway_time_out()
http_status_line_t status_found()
http_status_line_t status_multiple_choices()
constexpr http_method_id_t http_method_unknown()
http_status_line_t status_insufficient_storage()
http_status_line_t status_unsupported_media_type()
http_status_line_t status_too_many_requests()
http_status_line_t status_bad_gateway()
http_status_line_t status_expectation_failed()
http_status_line_t status_see_other()
http_field_t string_to_field(string_view_t field) noexcept
Helper function to get method string name.
const char * field_to_string(http_field_t f) noexcept
Helper sunction to get method string name.
http_status_line_t status_reset_content()
http_status_line_t status_ok()
http_field_t
C++ enum that repeats nodejs c-style enum.
RESTINIO_HTTP_FIELD_GEN(name, ignored)
http_status_line_t status_switching_protocols()
http_status_line_t status_payload_too_large()
http_status_line_t status_uri_too_long()
http_status_line_t status_request_header_fields_too_large()
http_status_line_t status_processing()
http_status_line_t status_precondition_failed()
http_status_line_t status_method_not_allowed()
http_status_line_t status_accepted()
http_status_line_t status_proxy_authentication_required()
http_status_line_t status_precondition_required()
http_status_line_t status_bad_request()
http_status_line_t status_not_found()
http_status_line_t status_multi_status()
http_status_line_t status_service_unavailable()
http_status_line_t status_length_required()
STL namespace.
Helpers for caseless comparison of strings.
Req/Resp headers common data.
void should_keep_alive(bool keep_alive) noexcept
void content_length(std::uint64_t l) noexcept
void http_major(std::uint16_t v) noexcept
bool should_keep_alive() const noexcept
http_connection_header_t m_http_connection_header_field_value
std::uint16_t http_major() const noexcept
Http version.
http_connection_header_t connection() const
Get the value of 'connection' header field.
std::uint16_t m_http_major
Http version.
std::uint64_t m_content_length
Length of body of an http-message.
std::uint64_t content_length() const noexcept
Length of body of an http-message.
void http_minor(std::uint16_t v) noexcept
std::uint16_t http_minor() const noexcept
void connection(http_connection_header_t ch) noexcept
Set the value of 'connection' header field.
void method(http_method_id_t m) noexcept
void request_target(std::string t)
string_view_t fragment() const
Get the fragment part of the request URL.
string_view_t path() const noexcept
Request URL-structure.
const std::string & request_target() const noexcept
void append_request_target(const char *at, size_t length)
Helpfull function for using in parser callback.
static std::size_t memchr_helper(int chr, const char *from, std::size_t size)
http_method_id_t method() const noexcept
string_view_t query() const noexcept
Get the query part of the request URL.
http_request_header_t(http_method_id_t method, std::string request_target_)
void status_code(http_status_code_t c) noexcept
const http_status_line_t & status_line() const noexcept
void status_line(http_status_line_t sl)
http_status_code_t status_code() const noexcept
http_response_header_t(http_status_line_t status_line)
const std::string & reason_phrase() const noexcept
#define const
Definition: zconf.h:230