RESTinio

http_headers.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
9#pragma once
10
11#include <restinio/impl/include_fmtlib.hpp>
12
13#include <restinio/impl/string_caseless_compare.hpp>
14
15#include <restinio/exception.hpp>
16#include <restinio/string_view.hpp>
17#include <restinio/optional.hpp>
18#include <restinio/common_types.hpp>
19
20#include <http_parser.h>
21
22#include <iosfwd>
23#include <string>
24#include <vector>
25#include <algorithm>
26
27 namespace 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
232 enum 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,
235 RESTINIO_HTTP_FIELDS_MAP( RESTINIO_HTTP_FIELD_GEN )
236#undef RESTINIO_HTTP_FIELD_GEN
237 // Unspecified field.
238 field_unspecified
239};
240
242 using http_field = http_field_t;
243
244//
245// string_to_field()
246//
247
250 inline http_field_t
251 string_to_field( string_view_t field ) noexcept
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:
265 RESTINIO_HTTP_CHECK_FOR_FIELD( if_, If )
266 RESTINIO_HTTP_CHECK_FOR_FIELD( im, IM )
267 RESTINIO_HTTP_CHECK_FOR_FIELD( te, TE )
268 break;
269
270 case 3:
271 RESTINIO_HTTP_CHECK_FOR_FIELD( age, Age )
272 RESTINIO_HTTP_CHECK_FOR_FIELD( dav, DAV )
273 RESTINIO_HTTP_CHECK_FOR_FIELD( ext, Ext )
274 RESTINIO_HTTP_CHECK_FOR_FIELD( man, Man )
275 RESTINIO_HTTP_CHECK_FOR_FIELD( opt, Opt )
276 RESTINIO_HTTP_CHECK_FOR_FIELD( p3p, P3P )
277 RESTINIO_HTTP_CHECK_FOR_FIELD( pep, PEP )
278 RESTINIO_HTTP_CHECK_FOR_FIELD( tcn, TCN )
279 RESTINIO_HTTP_CHECK_FOR_FIELD( ttl, TTL )
280 RESTINIO_HTTP_CHECK_FOR_FIELD( uri, URI )
281 RESTINIO_HTTP_CHECK_FOR_FIELD( via, Via )
282 break;
283
284 case 4:
285 // Known to be more used first:
286 RESTINIO_HTTP_CHECK_FOR_FIELD( host, Host )
287
288 RESTINIO_HTTP_CHECK_FOR_FIELD( a_im, A-IM )
289 RESTINIO_HTTP_CHECK_FOR_FIELD( alpn, ALPN )
290 RESTINIO_HTTP_CHECK_FOR_FIELD( dasl, DASL )
291 RESTINIO_HTTP_CHECK_FOR_FIELD( date, Date )
292 RESTINIO_HTTP_CHECK_FOR_FIELD( etag, ETag )
293 RESTINIO_HTTP_CHECK_FOR_FIELD( from, From )
294 RESTINIO_HTTP_CHECK_FOR_FIELD( link, Link )
295 RESTINIO_HTTP_CHECK_FOR_FIELD( safe, Safe )
296 RESTINIO_HTTP_CHECK_FOR_FIELD( slug, SLUG )
297 RESTINIO_HTTP_CHECK_FOR_FIELD( vary, Vary )
298 RESTINIO_HTTP_CHECK_FOR_FIELD( cost, Cost )
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 )
307 RESTINIO_HTTP_CHECK_FOR_FIELD( close, Close )
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 )
341 RESTINIO_HTTP_CHECK_FOR_FIELD( upgrade, Upgrade )
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 )
372 RESTINIO_HTTP_CHECK_FOR_FIELD( keep_alive, Keep-Alive )
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
544 return http_field_t::field_unspecified;
545}
546
547//
548// field_to_string()
549//
550
552 inline const char *
553 field_to_string( http_field_t f ) noexcept
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
561 RESTINIO_HTTP_FIELDS_MAP( RESTINIO_HTTP_FIELD_STR_GEN )
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
582 class http_header_field_t
583{
584 public:
585 http_header_field_t()
586 : m_field_id{ http_field_t::field_unspecified }
587 {}
588
589 http_header_field_t(
590 std::string name,
591 std::string value )
592 : m_name{ std::move( name ) }
593 , m_value{ std::move( value ) }
594 , m_field_id{ string_to_field( m_name ) }
595 {}
596
597 http_header_field_t(
598 string_view_t name,
599 string_view_t value )
600 : m_name{ name.data(), name.size() }
601 , m_value{ value.data(), value.size() }
602 , m_field_id{ string_to_field( m_name ) }
603 {}
604
605 http_header_field_t(
606 http_field_t field_id,
607 std::string value )
608 : m_name{ field_to_string( field_id ) }
609 , m_value{ std::move( value ) }
610 , m_field_id{ field_id }
611 {}
612
613 http_header_field_t(
614 http_field_t field_id,
615 string_view_t value )
616 : m_name{ field_to_string( field_id ) }
617 , m_value{ std::move( value ) }
618 , m_field_id{ field_id }
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 );
629 m_field_id = string_to_field( m_name );
630 }
631
632 void
633 value( std::string v )
634 {
635 m_value = std::move( v );
636 }
637
638 void
639 append_value( string_view_t v )
640 {
641 m_value.append( v.data(), v.size() );
642 }
643
644 void
645 field_id( http_field_t field_id )
646 {
647 m_field_id = field_id;
648 m_name = field_to_string( m_field_id );
649 }
650
651 private:
652 std::string m_name;
653 std::string m_value;
654 http_field_t m_field_id;
655};
656
657// Make neccessary forward declarations.
658 class http_header_fields_t;
659 namespace impl
660{
661
662 void
663 append_last_field_accessor( http_header_fields_t &, string_view_t );
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
702 class http_header_fields_t
703{
704 friend void
705 impl::append_last_field_accessor( http_header_fields_t &, string_view_t );
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
720 enum class handling_result_t
721 {
724 continue_enumeration,
726 stop_enumeration
727 };
728
729 constexpr static handling_result_t continue_enumeration() noexcept
730 { return handling_result_t::continue_enumeration; }
731
732 constexpr static handling_result_t stop_enumeration() noexcept
733 { return handling_result_t::stop_enumeration; }
734
735 http_header_fields_t()
736 {
737 m_fields.reserve( RESTINIO_HEADER_FIELDS_DEFAULT_RESERVE_COUNT );
738 }
739 http_header_fields_t(const http_header_fields_t &) = default;
740 http_header_fields_t(http_header_fields_t &&) = default;
741 virtual ~http_header_fields_t() {}
742
743 http_header_fields_t & operator=(const http_header_fields_t &) = default;
744 http_header_fields_t & operator=(http_header_fields_t &&) = default;
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
801 set_field(
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
826 set_field(
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
860 add_field(
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
882 add_field(
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
908 append_field(
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
930 append_field(
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( "field '{}' doesn't exist", field_name ) };
958
959 return it->value();
960 }
961
963
974 nullable_pointer_t<const std::string>
975 try_get_field( string_view_t field_name ) const noexcept
976 {
977 const auto it = cfind( field_name );
978 if( m_fields.end() == it )
979 return nullptr;
980 else
981 return std::addressof(it->value());
982 }
983
985 const std::string &
986 get_field( http_field_t field_id ) const
987 {
988 if( http_field_t::field_unspecified == field_id )
989 {
990 throw exception_t{
991 fmt::format(
992 "unspecified fields cannot be searched by id" ) };
993 }
994
995 const auto it = cfind( field_id );
996
997 if( m_fields.end() == it )
998 {
999 throw exception_t{
1000 fmt::format(
1001 "field '{}' doesn't exist",
1002 field_to_string( field_id ) ) };
1003 }
1004
1005 return it->value();
1006 }
1007
1009
1020 nullable_pointer_t<const std::string>
1021 try_get_field( http_field_t field_id ) const noexcept
1022 {
1023 if( http_field_t::field_unspecified != field_id )
1024 {
1025 const auto it = cfind( field_id );
1026 if( m_fields.end() != it )
1027 return std::addressof(it->value());
1028 }
1029
1030 return nullptr;
1031 }
1032
1034
1039 std::string
1040 get_field_or(
1041 string_view_t field_name,
1042 string_view_t default_value ) const
1043 {
1044 const auto it = cfind( field_name );
1045
1046 if( m_fields.end() == it )
1047 return std::string( default_value.data(), default_value.size() );
1048
1049 return it->value();
1050 }
1051
1053
1058 std::string
1059 get_field_or(
1060 string_view_t field_name,
1061 std::string && default_value ) const
1062 {
1063 const auto it = cfind( field_name );
1064
1065 if( m_fields.end() == it )
1066 return std::move(default_value);
1067
1068 return it->value();
1069 }
1070
1072
1075 auto
1076 get_field_or(
1077 string_view_t field_name,
1078 const char * default_value ) const
1079 {
1080 return this->get_field_or( field_name, string_view_t{ default_value } );
1081 }
1082
1084
1087 auto
1088 get_field_or(
1089 string_view_t field_name,
1090 const std::string & default_value ) const
1091 {
1092 return this->get_field_or( field_name, string_view_t{ default_value } );
1093 }
1094
1096
1101 std::string
1102 get_field_or(
1103 http_field_t field_id,
1104 string_view_t default_value ) const
1105 {
1106 if( http_field_t::field_unspecified != field_id )
1107 {
1108 const auto it = cfind( field_id );
1109
1110 if( m_fields.end() != it )
1111 return it->value();
1112 }
1113
1114 return std::string( default_value.data(), default_value.size() );
1115 }
1116
1118
1121 auto
1122 get_field_or(
1123 http_field_t field_id,
1124 const char * default_value ) const
1125 {
1126 return this->get_field_or( field_id, string_view_t{ default_value } );
1127 }
1128
1130
1133 auto
1134 get_field_or(
1135 http_field_t field_id,
1136 const std::string & default_value ) const
1137 {
1138 return this->get_field_or( field_id, string_view_t{ default_value } );
1139 }
1140
1142
1147 std::string
1148 get_field_or(
1149 http_field_t field_id,
1150 std::string && default_value ) const
1151 {
1152 if( http_field_t::field_unspecified != field_id )
1153 {
1154 const auto it = cfind( field_id );
1155
1156 if( m_fields.end() != it )
1157 return it->value();
1158 }
1159
1160 return std::move( default_value );
1161 }
1162
1164
1173 bool
1174 remove_field( string_view_t field_name ) noexcept
1175 {
1176 const auto it = find( field_name );
1177
1178 if( m_fields.end() != it )
1179 {
1180 m_fields.erase( it );
1181 return true;
1182 }
1183
1184 return false;
1185 }
1186
1188
1197 bool
1198 remove_field( http_field_t field_id ) noexcept
1199 {
1200 if( http_field_t::field_unspecified != field_id )
1201 {
1202 const auto it = find( field_id );
1203
1204 if( m_fields.end() != it )
1205 {
1206 m_fields.erase( it );
1207 return true;
1208 }
1209 }
1210
1211 return false;
1212 }
1213
1215
1220 std::size_t
1221 remove_all_of( string_view_t field_name ) noexcept
1222 {
1223 std::size_t count{};
1224 for( auto it = m_fields.begin(); it != m_fields.end(); )
1225 {
1226 if( impl::is_equal_caseless( it->name(), field_name ) )
1227 {
1228 it = m_fields.erase( it );
1229 ++count;
1230 }
1231 else
1232 ++it;
1233 }
1234
1235 return count;
1236 }
1237
1239
1244 std::size_t
1245 remove_all_of( http_field_t field_id ) noexcept
1246 {
1247 std::size_t count{};
1248 if( http_field_t::field_unspecified != field_id )
1249 {
1250 for( auto it = m_fields.begin(); it != m_fields.end(); )
1251 {
1252 if( it->field_id() == field_id )
1253 {
1254 it = m_fields.erase( it );
1255 ++count;
1256 }
1257 else
1258 ++it;
1259 }
1260 }
1261
1262 return count;
1263 }
1264
1270 string_view_t
1271 value_of(
1273 string_view_t name ) const
1274 {
1275 return { this->get_field(name) };
1276 }
1277
1279 string_view_t
1280 value_of(
1282 http_field_t field_id ) const
1283 {
1284 return { this->get_field(field_id) };
1285 }
1286
1288
1299 optional_t< string_view_t >
1300 opt_value_of(
1302 string_view_t name ) const noexcept
1303 {
1304 optional_t< string_view_t > result;
1305
1306 if( auto * ptr = this->try_get_field(name) )
1307 result = string_view_t{ *ptr };
1308
1309 return result;
1310 }
1311
1313
1324 optional_t< string_view_t >
1325 opt_value_of(
1327 http_field_t field_id ) const noexcept
1328 {
1329 optional_t< string_view_t > result;
1330
1331 if( auto * ptr = this->try_get_field(field_id) )
1332 result = string_view_t{ *ptr };
1333
1334 return result;
1335 }
1341
1359 template< typename Lambda >
1360 void
1361 for_each_field( Lambda && lambda ) const
1362 noexcept(noexcept(lambda(
1363 std::declval<const http_header_field_t &>())))
1364 {
1365 for( const auto & f : m_fields )
1366 lambda( f );
1367 }
1368
1370
1399 template< typename Lambda >
1400 void
1401 for_each_value_of(
1402 http_field_t field_id,
1403 Lambda && lambda ) const
1404 noexcept(noexcept(lambda(
1405 std::declval<const string_view_t &>())))
1406 {
1407 static_assert(
1408 std::is_same<
1409 handling_result_t,
1410 decltype(lambda(std::declval<const string_view_t &>()))
1411 >::value,
1412 "lambda should return restinio::http_header_fields_t::handling_result_t" );
1413
1414 for( const auto & f : m_fields )
1415 {
1416 if( field_id == f.field_id() )
1417 {
1418 const handling_result_t r = lambda( f.value() );
1419 if( stop_enumeration() == r )
1420 break;
1421 }
1422 }
1423 }
1424
1426
1455 template< typename Lambda >
1456 void
1457 for_each_value_of(
1458 string_view_t field_name,
1459 Lambda && lambda ) const
1460 noexcept(noexcept(lambda(
1461 std::declval<const string_view_t &>())))
1462 {
1463 static_assert(
1464 std::is_same<
1465 handling_result_t,
1466 decltype(lambda(std::declval<const string_view_t &>()))
1467 >::value,
1468 "lambda should return restinio::http_header_fields_t::handling_result_t" );
1469
1470 for( const auto & f : m_fields )
1471 {
1472 if( impl::is_equal_caseless( f.name(), field_name ) )
1473 {
1474 const handling_result_t r = lambda( f.value() );
1475 if( stop_enumeration() == r )
1476 break;
1477 }
1478 }
1479 }
1480
1481 const_iterator
1482 begin() const noexcept
1483 {
1484 return m_fields.cbegin();
1485 }
1486
1487 const_iterator
1488 end() const noexcept
1489 {
1490 return m_fields.cend();
1491 }
1492
1493 auto fields_count() const noexcept
1494 {
1495 return m_fields.size();
1496 }
1497
1498 private:
1500
1508 void
1509 append_last_field( string_view_t field_value )
1510 {
1511 m_fields.back().append_value( field_value );
1512 }
1513
1514 fields_container_t::iterator
1515 find( string_view_t field_name ) noexcept
1516 {
1517 return std::find_if(
1518 m_fields.begin(),
1519 m_fields.end(),
1520 [&]( const auto & f ){
1521 return impl::is_equal_caseless( f.name(), field_name );
1522 } );
1523 }
1524
1525 fields_container_t::const_iterator
1526 cfind( string_view_t field_name ) const noexcept
1527 {
1528 return std::find_if(
1529 m_fields.cbegin(),
1530 m_fields.cend(),
1531 [&]( const auto & f ){
1532 return impl::is_equal_caseless( f.name(), field_name );
1533 } );
1534 }
1535
1536 fields_container_t::iterator
1537 find( http_field_t field_id ) noexcept
1538 {
1539 return std::find_if(
1540 m_fields.begin(),
1541 m_fields.end(),
1542 [&]( const auto & f ){
1543 return f.field_id() == field_id;
1544 } );
1545 }
1546
1547 fields_container_t::const_iterator
1548 cfind( http_field_t field_id ) const noexcept
1549 {
1550 return std::find_if(
1551 m_fields.cbegin(),
1552 m_fields.cend(),
1553 [&]( const auto & f ){
1554 return f.field_id() == field_id;
1555 } );
1556 }
1557
1558 fields_container_t m_fields;
1559};
1560
1561//
1562// http_connection_header_t
1563//
1564
1566 enum class http_connection_header_t : std::uint8_t
1567{
1568 keep_alive,
1569 close,
1570 upgrade
1571};
1572
1573//
1574// http_header_common_t
1575//
1576
1578 struct http_header_common_t
1579 : public http_header_fields_t
1580{
1581 public:
1584 std::uint16_t
1585 http_major() const noexcept
1586 { return m_http_major; }
1587
1588 void
1589 http_major( std::uint16_t v ) noexcept
1590 { m_http_major = v; }
1591
1592 std::uint16_t
1593 http_minor() const noexcept
1594 { return m_http_minor; }
1595
1596 void
1597 http_minor( std::uint16_t v ) noexcept
1598 { m_http_minor = v; }
1600
1602 std::uint64_t
1603 content_length() const noexcept
1604 { return m_content_length; }
1605
1606 void
1607 content_length( std::uint64_t l ) noexcept
1608 { m_content_length = l; }
1609
1610 bool
1611 should_keep_alive() const noexcept
1612 {
1613 return http_connection_header_t::keep_alive == m_http_connection_header_field_value;
1614 }
1615
1616 void
1617 should_keep_alive( bool keep_alive ) noexcept
1618 {
1619 connection( keep_alive?
1620 http_connection_header_t::keep_alive :
1621 http_connection_header_t::close );
1622 }
1623
1625 http_connection_header_t
1626 connection() const
1627 {
1628 return m_http_connection_header_field_value;
1629 }
1630
1632 void
1633 connection( http_connection_header_t ch ) noexcept
1634 {
1635 m_http_connection_header_field_value = ch;
1636 }
1637
1638 private:
1641 std::uint16_t m_http_major{1};
1642 std::uint16_t m_http_minor{1};
1644
1646 std::uint64_t m_content_length{ 0 };
1647
1648 http_connection_header_t m_http_connection_header_field_value{ http_connection_header_t::close };
1649};
1650
1652#define RESTINIO_HTTP_METHOD_MAP(RESTINIO_GEN) \
1653 RESTINIO_GEN( http_method_delete, HTTP_DELETE, DELETE ) \
1654 RESTINIO_GEN( http_method_get, HTTP_GET, GET ) \
1655 RESTINIO_GEN( http_method_head, HTTP_HEAD, HEAD ) \
1656 RESTINIO_GEN( http_method_post, HTTP_POST, POST ) \
1657 RESTINIO_GEN( http_method_put, HTTP_PUT, PUT ) \
1658 /* pathological */ \
1659 RESTINIO_GEN( http_method_connect, HTTP_CONNECT, CONNECT ) \
1660 RESTINIO_GEN( http_method_options, HTTP_OPTIONS, OPTIONS ) \
1661 RESTINIO_GEN( http_method_trace, HTTP_TRACE, TRACE ) \
1662 /* WebDAV */ \
1663 RESTINIO_GEN( http_method_copy, HTTP_COPY, COPY ) \
1664 RESTINIO_GEN( http_method_lock, HTTP_LOCK, LOCK ) \
1665 RESTINIO_GEN( http_method_mkcol, HTTP_MKCOL, MKCOL ) \
1666 RESTINIO_GEN( http_method_move, HTTP_MOVE, MOVE ) \
1667 RESTINIO_GEN( http_method_propfind, HTTP_PROPFIND, PROPFIND ) \
1668 RESTINIO_GEN( http_method_proppatch, HTTP_PROPPATCH, PROPPATCH ) \
1669 RESTINIO_GEN( http_method_search, HTTP_SEARCH, SEARCH ) \
1670 RESTINIO_GEN( http_method_unlock, HTTP_UNLOCK, UNLOCK ) \
1671 RESTINIO_GEN( http_method_bind, HTTP_BIND, BIND ) \
1672 RESTINIO_GEN( http_method_rebind, HTTP_REBIND, REBIND ) \
1673 RESTINIO_GEN( http_method_unbind, HTTP_UNBIND, UNBIND ) \
1674 RESTINIO_GEN( http_method_acl, HTTP_ACL, ACL ) \
1675 /* subversion */ \
1676 RESTINIO_GEN( http_method_report, HTTP_REPORT, REPORT ) \
1677 RESTINIO_GEN( http_method_mkactivity, HTTP_MKACTIVITY, MKACTIVITY ) \
1678 RESTINIO_GEN( http_method_checkout, HTTP_CHECKOUT, CHECKOUT ) \
1679 RESTINIO_GEN( http_method_merge, HTTP_MERGE, MERGE ) \
1680 /* upnp */ \
1681 RESTINIO_GEN( http_method_msearch, HTTP_MSEARCH, M-SEARCH) \
1682 RESTINIO_GEN( http_method_notify, HTTP_NOTIFY, NOTIFY ) \
1683 RESTINIO_GEN( http_method_subscribe, HTTP_SUBSCRIBE, SUBSCRIBE ) \
1684 RESTINIO_GEN( http_method_unsubscribe, HTTP_UNSUBSCRIBE, UNSUBSCRIBE ) \
1685 /* RFC-5789 */ \
1686 RESTINIO_GEN( http_method_patch, HTTP_PATCH, PATCH ) \
1687 RESTINIO_GEN( http_method_purge, HTTP_PURGE, PURGE ) \
1688 /* CalDAV */ \
1689 RESTINIO_GEN( http_method_mkcalendar, HTTP_MKCALENDAR, MKCALENDAR ) \
1690 /* RFC-2068, section 19.6.1.2 */ \
1691 RESTINIO_GEN( http_method_link, HTTP_LINK, LINK ) \
1692 RESTINIO_GEN( http_method_unlink, HTTP_UNLINK, UNLINK )
1693
1694//
1695// http_method_id_t
1696//
1743 class http_method_id_t
1744{
1745 int m_value;
1746 const char * m_name;
1747
1748 public:
1749 static constexpr const int unknown_method = -1;
1750
1751 constexpr http_method_id_t() noexcept
1752 : m_value{ unknown_method }
1753 , m_name{ "<undefined>" }
1754 {}
1755 constexpr http_method_id_t(
1756 int value,
1757 const char * name ) noexcept
1758 : m_value{ value }
1759 , m_name{ name }
1760 {}
1761
1762 constexpr http_method_id_t( const http_method_id_t & ) noexcept = default;
1763 constexpr http_method_id_t &
1764 operator=( const http_method_id_t & ) noexcept = default;
1765
1766 constexpr http_method_id_t( http_method_id_t && ) noexcept = default;
1767 constexpr http_method_id_t &
1768 operator=( http_method_id_t && ) noexcept = default;
1769
1770 constexpr auto
1771 raw_id() const noexcept { return m_value; }
1772
1773 constexpr const char *
1774 c_str() const noexcept { return m_name; }
1775
1776 friend constexpr bool
1777 operator==( const http_method_id_t & a, const http_method_id_t & b ) noexcept {
1778 return a.raw_id() == b.raw_id();
1779 }
1780
1781 friend constexpr bool
1782 operator!=( const http_method_id_t & a, const http_method_id_t & b ) noexcept {
1783 return a.raw_id() != b.raw_id();
1784 }
1785
1786 friend constexpr bool
1787 operator<( const http_method_id_t & a, const http_method_id_t & b ) noexcept {
1788 return a.raw_id() < b.raw_id();
1789 }
1790};
1791
1792 inline std::ostream &
1793 operator<<( std::ostream & to, const http_method_id_t & m )
1794{
1795 return to << m.c_str();
1796}
1797
1798// Generate helper funcs.
1799#define RESTINIO_HTTP_METHOD_FUNC_GEN( func_name, nodejs_code, method_name ) \
1800 inline constexpr http_method_id_t func_name() { \
1801 return { nodejs_code, #method_name }; \
1802 }
1803
1804 RESTINIO_HTTP_METHOD_MAP( RESTINIO_HTTP_METHOD_FUNC_GEN )
1805#undef RESTINIO_HTTP_METHOD_FUNC_GEN
1806
1807 inline constexpr http_method_id_t
1808 http_method_unknown()
1809{
1810 return http_method_id_t{};
1811}
1812
1813//
1814// default_http_methods_t
1815//
1831 class default_http_methods_t
1832{
1833public :
1834 inline static constexpr http_method_id_t
1835 from_nodejs( int value ) noexcept
1836 {
1837 http_method_id_t result;
1838 switch( value )
1839 {
1840#define RESTINIO_HTTP_METHOD_FUNC_GEN( func_name, nodejs_code, method_name ) \
1841 case nodejs_code : result = func_name(); break;
1842
1843 RESTINIO_HTTP_METHOD_MAP( RESTINIO_HTTP_METHOD_FUNC_GEN )
1844#undef RESTINIO_HTTP_METHOD_FUNC_GEN
1845 default : ; // Nothing to do.
1846 }
1847
1848 return result;
1849 }
1850};
1851
1852//
1853// http_request_header
1854//
1855
1857 struct http_request_header_t final
1858 : public http_header_common_t
1859{
1860 static std::size_t
1861 memchr_helper( int chr , const char * from, std::size_t size )
1862 {
1863 const char * result = static_cast< const char * >(
1864 std::memchr( from, chr, size ) );
1865
1866 return result ? static_cast< std::size_t >( result - from ) : size;
1867 }
1868
1869 public:
1870 http_request_header_t() = default;
1871
1872 http_request_header_t(
1873 http_method_id_t method,
1874 std::string request_target_ )
1875 : m_method{ method }
1876 {
1877 request_target( std::move( request_target_ ) );
1878 }
1879
1880 http_method_id_t
1881 method() const noexcept
1882 { return m_method; }
1883
1884 void
1885 method( http_method_id_t m ) noexcept
1886 { m_method = m; }
1887
1888 const std::string &
1889 request_target() const noexcept
1890 { return m_request_target; }
1891
1892 void
1893 request_target( std::string t )
1894 {
1895 m_request_target.assign( std::move( t ) );
1896
1897 m_fragment_separator_pos =
1898 memchr_helper( '#', m_request_target.data(), m_request_target.size() );
1899
1900 m_query_separator_pos =
1901 memchr_helper( '?', m_request_target.data(), m_fragment_separator_pos );
1902 }
1903
1906
1908
1912 string_view_t
1913 path() const noexcept
1914 {
1915 return string_view_t{ m_request_target.data(), m_query_separator_pos };
1916 }
1917
1919
1923 string_view_t
1924 query() const noexcept
1925 {
1926 return
1927 m_fragment_separator_pos == m_query_separator_pos ?
1928 string_view_t{ nullptr, 0 } :
1929 string_view_t{
1930 m_request_target.data() + m_query_separator_pos + 1,
1931 m_fragment_separator_pos - m_query_separator_pos - 1 };
1932 }
1933
1934
1936
1940 string_view_t
1941 fragment() const
1942 {
1943 return
1944 m_request_target.size() == m_fragment_separator_pos ?
1945 string_view_t{ nullptr, 0 } :
1946 string_view_t{
1947 m_request_target.data() + m_fragment_separator_pos + 1,
1948 m_request_target.size() - m_fragment_separator_pos - 1 };
1949 }
1951
1953 void
1954 append_request_target( const char * at, size_t length )
1955 {
1956 if( m_request_target.size() == m_fragment_separator_pos )
1957 {
1958 // If fragment separator hadn't already appeared,
1959 // search for it in a new block.
1960
1961 const auto fragment_separator_pos_inc =
1962 memchr_helper( '#', at, length );
1963
1964 m_fragment_separator_pos += fragment_separator_pos_inc;
1965
1966 if( m_request_target.size() == m_query_separator_pos )
1967 {
1968 // If request separator hadn't already appeared,
1969 // search for it in a new block.
1970 m_query_separator_pos +=
1971 memchr_helper( '?', at, fragment_separator_pos_inc );
1972 }
1973 }
1974 // Else fragment separator appeared
1975 // (req separator is either already defined or does not exist)
1976
1977 m_request_target.append( at, length );
1978 }
1979
1980 private:
1981 http_method_id_t m_method{ http_method_get() };
1982 std::string m_request_target;
1983 std::size_t m_query_separator_pos{ 0 };
1984 std::size_t m_fragment_separator_pos{ 0 };
1985};
1986
1987//
1988// http_status_code_t
1989//
1990
1992 class http_status_code_t
1993{
1994 public:
1995 constexpr http_status_code_t() noexcept
1996 {}
1997
1998 constexpr explicit http_status_code_t( std::uint16_t status_code ) noexcept
1999 : m_status_code{ status_code }
2000 {}
2001
2002 constexpr auto
2003 raw_code() const noexcept
2004 {
2005 return m_status_code;
2006 }
2007
2008 constexpr bool
2009 operator == ( const http_status_code_t & sc ) const noexcept
2010 {
2011 return raw_code() == sc.raw_code();
2012 }
2013
2014 constexpr bool
2015 operator != ( const http_status_code_t & sc ) const noexcept
2016 {
2017 return sc.raw_code() != sc.raw_code();
2018 }
2019
2020 constexpr bool
2021 operator < ( const http_status_code_t & sc ) const noexcept
2022 {
2023 return sc.raw_code() < sc.raw_code();
2024 }
2025
2026 private:
2028 std::uint16_t m_status_code{ 0 };
2029};
2030
2031 namespace status_code
2032{
2033
2038
2039// Add '_', because 'continue is reserved word.'
2040 constexpr http_status_code_t continue_{ 100 };
2041
2042 constexpr http_status_code_t switching_protocols{ 101 };
2043 constexpr http_status_code_t ok{ 200 };
2044 constexpr http_status_code_t created{ 201 };
2045 constexpr http_status_code_t accepted{ 202 };
2046 constexpr http_status_code_t non_authoritative_information{ 203 };
2047 constexpr http_status_code_t no_content{ 204 };
2048 constexpr http_status_code_t reset_content{ 205 };
2049 constexpr http_status_code_t partial_content{ 206 };
2050 constexpr http_status_code_t multiple_choices{ 300 };
2051 constexpr http_status_code_t moved_permanently{ 301 };
2052 constexpr http_status_code_t found{ 302 };
2053 constexpr http_status_code_t see_other{ 303 };
2054 constexpr http_status_code_t not_modified{ 304 };
2055 constexpr http_status_code_t use_proxy{ 305 };
2056 constexpr http_status_code_t temporary_redirect{ 307 };
2057 constexpr http_status_code_t bad_request{ 400 };
2058 constexpr http_status_code_t unauthorized{ 401 };
2059 constexpr http_status_code_t payment_required{ 402 };
2060 constexpr http_status_code_t forbidden{ 403 };
2061 constexpr http_status_code_t not_found{ 404 };
2062 constexpr http_status_code_t method_not_allowed{ 405 };
2063 constexpr http_status_code_t not_acceptable{ 406 };
2064 constexpr http_status_code_t proxy_authentication_required{ 407 };
2065 constexpr http_status_code_t request_time_out{ 408 };
2066 constexpr http_status_code_t conflict{ 409 };
2067 constexpr http_status_code_t gone{ 410 };
2068 constexpr http_status_code_t length_required{ 411 };
2069 constexpr http_status_code_t precondition_failed{ 412 };
2070
2071//413 Payload Too Large (RFC 7231)
2072// The request is larger than the server is willing or able to process.
2073// Previously called "Request Entity Too Large".[44]
2074 constexpr http_status_code_t payload_too_large{ 413 };
2075
2076// 414 URI Too Long (RFC 7231)
2077// The URI provided was too long for the server to process.
2078// Often the result of too much data being encoded as a query-string of a GET request,
2079// in which case it should be converted to a POST request.
2080// Called "Request-URI Too Long" previously.[46]
2081 constexpr http_status_code_t uri_too_long{ 414 };
2082
2083 constexpr http_status_code_t unsupported_media_type{ 415 };
2084 constexpr http_status_code_t requested_range_not_satisfiable{ 416 };
2085 constexpr http_status_code_t expectation_failed{ 417 };
2086 constexpr http_status_code_t internal_server_error{ 500 };
2087 constexpr http_status_code_t not_implemented{ 501 };
2088 constexpr http_status_code_t bad_gateway{ 502 };
2089 constexpr http_status_code_t service_unavailable{ 503 };
2090 constexpr http_status_code_t gateway_time_out{ 504 };
2091 constexpr http_status_code_t http_version_not_supported{ 505 };
2093
2098 // RFC 7538
2099 constexpr http_status_code_t permanent_redirect{ 308 };
2100
2101 // RFC 2518
2102 constexpr http_status_code_t processing{ 102 };
2103 constexpr http_status_code_t multi_status{ 207 };
2104 constexpr http_status_code_t unprocessable_entity{ 422 };
2105 constexpr http_status_code_t locked{ 423 };
2106 constexpr http_status_code_t failed_dependency{ 424 };
2107 constexpr http_status_code_t insufficient_storage{ 507 };
2108
2109 // RFC 6585
2110 constexpr http_status_code_t precondition_required{ 428 };
2111 constexpr http_status_code_t too_many_requests{ 429 };
2112 constexpr http_status_code_t request_header_fields_too_large{ 431 };
2113 constexpr http_status_code_t network_authentication_required{ 511 };
2115
2116} /* namespace status_code */
2117
2118//
2119// http_status_line_t
2120//
2121
2123 class http_status_line_t
2124{
2125 public:
2126 http_status_line_t()
2127 {}
2128
2129 http_status_line_t(
2130 http_status_code_t sc,
2131 std::string reason_phrase )
2132 : m_status_code{ sc }
2133 , m_reason_phrase{ std::move( reason_phrase ) }
2134 {}
2135
2136 http_status_code_t
2137 status_code() const noexcept
2138 { return m_status_code; }
2139
2140 void
2141 status_code( http_status_code_t c ) noexcept
2142 { m_status_code = c; }
2143
2144 const std::string &
2145 reason_phrase() const noexcept
2146 { return m_reason_phrase; }
2147
2148 void
2149 reason_phrase( std::string r )
2150 { m_reason_phrase.assign( std::move( r ) ); }
2151
2152 private:
2153 http_status_code_t m_status_code{ status_code::ok };
2154 std::string m_reason_phrase;
2155};
2156
2157 inline std::ostream &
2158 operator << ( std::ostream & o, const http_status_line_t & status_line )
2159{
2160 return o << "{" << status_line.status_code().raw_code() << ", "
2161 << status_line.reason_phrase() << "}";
2162}
2163
2168
2169 inline http_status_line_t status_continue()
2170{ return http_status_line_t{ status_code::continue_, "Continue" }; }
2171
2172 inline http_status_line_t status_switching_protocols()
2173{ return http_status_line_t{ status_code::switching_protocols, "Switching Protocols" }; }
2174
2175 inline http_status_line_t status_ok()
2176{ return http_status_line_t{ status_code::ok, "OK" }; }
2177
2178 inline http_status_line_t status_created()
2179{ return http_status_line_t{ status_code::created, "Created" }; }
2180
2181 inline http_status_line_t status_accepted()
2182{ return http_status_line_t{ status_code::accepted, "Accepted" }; }
2183
2184 inline http_status_line_t status_non_authoritative_information()
2185{ return http_status_line_t{ status_code::non_authoritative_information, "Non-Authoritative Information" }; }
2186
2187 inline http_status_line_t status_no_content()
2188{ return http_status_line_t{ status_code::no_content, "No Content" }; }
2189
2190 inline http_status_line_t status_reset_content()
2191{ return http_status_line_t{ status_code::reset_content, "Reset Content" }; }
2192
2193 inline http_status_line_t status_partial_content()
2194{ return http_status_line_t{ status_code::partial_content, "Partial Content" }; }
2195
2196 inline http_status_line_t status_multiple_choices()
2197{ return http_status_line_t{ status_code::multiple_choices, "Multiple Choices" }; }
2198
2199 inline http_status_line_t status_moved_permanently()
2200{ return http_status_line_t{ status_code::moved_permanently, "Moved Permanently" }; }
2201
2202 inline http_status_line_t status_found()
2203{ return http_status_line_t{ status_code::found, "Found" }; }
2204
2205 inline http_status_line_t status_see_other()
2206{ return http_status_line_t{ status_code::see_other, "See Other" }; }
2207
2208 inline http_status_line_t status_not_modified()
2209{ return http_status_line_t{ status_code::not_modified, "Not Modified" }; }
2210
2211 inline http_status_line_t status_use_proxy()
2212{ return http_status_line_t{ status_code::use_proxy, "Use Proxy" }; }
2213
2214 inline http_status_line_t status_temporary_redirect()
2215{ return http_status_line_t{ status_code::temporary_redirect, "Temporary Redirect" }; }
2216
2217 inline http_status_line_t status_bad_request()
2218{ return http_status_line_t{ status_code::bad_request, "Bad Request" }; }
2219
2220 inline http_status_line_t status_unauthorized()
2221{ return http_status_line_t{ status_code::unauthorized, "Unauthorized" }; }
2222
2223 inline http_status_line_t status_payment_required()
2224{ return http_status_line_t{ status_code::payment_required, "Payment Required" }; }
2225
2226 inline http_status_line_t status_forbidden()
2227{ return http_status_line_t{ status_code::forbidden, "Forbidden" }; }
2228
2229 inline http_status_line_t status_not_found()
2230{ return http_status_line_t{ status_code::not_found, "Not Found" }; }
2231
2232 inline http_status_line_t status_method_not_allowed()
2233{ return http_status_line_t{ status_code::method_not_allowed, "Method Not Allowed" }; }
2234
2235 inline http_status_line_t status_not_acceptable()
2236{ return http_status_line_t{ status_code::not_acceptable, "Not Acceptable" }; }
2237
2238 inline http_status_line_t status_proxy_authentication_required()
2239{ return http_status_line_t{status_code::proxy_authentication_required, "Proxy Authentication Required" }; }
2240
2241 inline http_status_line_t status_request_time_out()
2242{ return http_status_line_t{ status_code::request_time_out, "Request Timeout" }; }
2243
2244 inline http_status_line_t status_conflict()
2245{ return http_status_line_t{ status_code::conflict, "Conflict" }; }
2246
2247 inline http_status_line_t status_gone()
2248{ return http_status_line_t{ status_code::gone, "Gone" }; }
2249
2250 inline http_status_line_t status_length_required()
2251{ return http_status_line_t{ status_code::length_required, "Length Required" }; }
2252
2253 inline http_status_line_t status_precondition_failed()
2254{ return http_status_line_t{ status_code::precondition_failed, "Precondition Failed" }; }
2255
2256 inline http_status_line_t status_payload_too_large()
2257{ return http_status_line_t{ status_code::payload_too_large, "Payload Too Large" }; }
2258
2259 inline http_status_line_t status_uri_too_long()
2260{ return http_status_line_t{ status_code::uri_too_long, "URI Too Long" }; }
2261
2262 inline http_status_line_t status_unsupported_media_type()
2263{ return http_status_line_t{ status_code::unsupported_media_type, "Unsupported Media Type" }; }
2264
2265 inline http_status_line_t status_requested_range_not_satisfiable()
2266{ return http_status_line_t{ status_code::requested_range_not_satisfiable, "Requested Range Not Satisfiable" }; }
2267
2268 inline http_status_line_t status_expectation_failed()
2269{ return http_status_line_t{ status_code::expectation_failed, "Expectation Failed" }; }
2270
2271 inline http_status_line_t status_internal_server_error()
2272{ return http_status_line_t{ status_code::internal_server_error, "Internal Server Error" }; }
2273
2274 inline http_status_line_t status_not_implemented()
2275{ return http_status_line_t{ status_code::not_implemented, "Not Implemented" }; }
2276
2277 inline http_status_line_t status_bad_gateway()
2278{ return http_status_line_t{ status_code::bad_gateway, "Bad Gateway" }; }
2279
2280 inline http_status_line_t status_service_unavailable()
2281{ return http_status_line_t{ status_code::service_unavailable, "Service Unavailable" }; }
2282
2283 inline http_status_line_t status_gateway_time_out()
2284{ return http_status_line_t{ status_code::gateway_time_out, "Gateway Timeout" }; }
2285
2286 inline http_status_line_t status_http_version_not_supported()
2287{ return http_status_line_t{ status_code::http_version_not_supported, "HTTP Version not supported" }; }
2289
2294 // RFC 7538
2295 inline http_status_line_t status_permanent_redirect()
2296{ return http_status_line_t{ status_code::permanent_redirect, "Permanent Redirect" }; }
2297
2298 // RFC 2518
2299 inline http_status_line_t status_processing()
2300{ return http_status_line_t{ status_code::processing, "Processing" }; }
2301
2302 inline http_status_line_t status_multi_status()
2303{ return http_status_line_t{ status_code::multi_status, "Multi-Status" }; }
2304
2305 inline http_status_line_t status_unprocessable_entity()
2306{ return http_status_line_t{ status_code::unprocessable_entity, "Unprocessable Entity" }; }
2307
2308 inline http_status_line_t status_locked()
2309{ return http_status_line_t{ status_code::locked, "Locked" }; }
2310
2311 inline http_status_line_t status_failed_dependency()
2312{ return http_status_line_t{ status_code::failed_dependency, "Failed Dependency" }; }
2313
2314 inline http_status_line_t status_insufficient_storage()
2315{ return http_status_line_t{ status_code::insufficient_storage, "Insufficient Storage" }; }
2316
2317 // RFC 6585
2318 inline http_status_line_t status_precondition_required()
2319{ return http_status_line_t{ status_code::precondition_required, "Precondition Required" }; }
2320
2321 inline http_status_line_t status_too_many_requests()
2322{ return http_status_line_t{ status_code::too_many_requests, "Too Many Requests" }; }
2323
2324 inline http_status_line_t status_request_header_fields_too_large()
2325{ return http_status_line_t{ status_code::request_header_fields_too_large, "Request Header Fields Too Large" }; }
2326
2327 inline http_status_line_t status_network_authentication_required()
2328{ return http_status_line_t{ status_code::network_authentication_required, "Network Authentication Required" }; }
2330
2331//
2332// http_response_header_t
2333//
2334
2336 struct http_response_header_t final
2337 : public http_header_common_t
2338{
2339 public:
2340 http_response_header_t()
2341 {}
2342
2343 http_response_header_t( http_status_line_t status_line )
2344 : m_status_line{ std::move( status_line ) }
2345 {}
2346
2347 http_status_code_t
2348 status_code() const noexcept
2349 { return m_status_line.status_code(); }
2350
2351 void
2352 status_code( http_status_code_t c ) noexcept
2353 { m_status_line.status_code( c ); }
2354
2355 const std::string &
2356 reason_phrase() const noexcept
2357 { return m_status_line.reason_phrase(); }
2358
2359 void
2360 reason_phrase( std::string r )
2361 { m_status_line.reason_phrase( std::move( r ) ); }
2362
2363 const http_status_line_t &
2364 status_line() const noexcept
2365 {
2366 return m_status_line;
2367 }
2368
2369 void
2370 status_line( http_status_line_t sl )
2371 {
2372 m_status_line = std::move( sl );
2373 }
2374
2375 private:
2376 http_status_line_t m_status_line;
2377};
2378
2379} /* namespace restinio */
nonstd::optional_lite::optional
class optional
Definition: optional.hpp:919
restinio::default_http_methods_t
The default implementation for http_method_mapper.
Definition: http_headers.hpp:1832
restinio::default_http_methods_t::from_nodejs
static constexpr http_method_id_t from_nodejs(int value) noexcept
Definition: http_headers.hpp:1835
restinio::exception_t
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
restinio::http_header_field_t
A single header field.
Definition: http_headers.hpp:583
restinio::http_header_field_t::http_header_field_t
http_header_field_t(http_field_t field_id, string_view_t value)
Definition: http_headers.hpp:613
restinio::http_header_field_t::field_id
void field_id(http_field_t field_id)
Definition: http_headers.hpp:645
restinio::http_header_field_t::m_value
std::string m_value
Definition: http_headers.hpp:653
restinio::http_header_field_t::m_name
std::string m_name
Definition: http_headers.hpp:652
restinio::http_header_field_t::http_header_field_t
http_header_field_t(std::string name, std::string value)
Definition: http_headers.hpp:589
restinio::http_header_field_t::m_field_id
http_field_t m_field_id
Definition: http_headers.hpp:654
restinio::http_header_field_t::value
void value(std::string v)
Definition: http_headers.hpp:633
restinio::http_header_field_t::value
const std::string & value() const noexcept
Definition: http_headers.hpp:622
restinio::http_header_field_t::http_header_field_t
http_header_field_t(string_view_t name, string_view_t value)
Definition: http_headers.hpp:597
restinio::http_header_field_t::name
void name(std::string n)
Definition: http_headers.hpp:626
restinio::http_header_field_t::name
const std::string & name() const noexcept
Definition: http_headers.hpp:621
restinio::http_header_field_t::field_id
http_field_t field_id() const noexcept
Definition: http_headers.hpp:623
restinio::http_header_field_t::http_header_field_t
http_header_field_t(http_field_t field_id, std::string value)
Definition: http_headers.hpp:605
restinio::http_header_field_t::append_value
void append_value(string_view_t v)
Definition: http_headers.hpp:639
restinio::http_header_field_t::http_header_field_t
http_header_field_t()
Definition: http_headers.hpp:585
restinio::http_header_fields_t
Header fields map.
Definition: http_headers.hpp:703
restinio::http_header_fields_t::has_field
bool has_field(string_view_t field_name) const noexcept
Check field by name.
Definition: http_headers.hpp:754
restinio::http_header_fields_t::value_of
string_view_t value_of(string_view_t name) const
Get the value of a field or throw if the field not found.
Definition: http_headers.hpp:1271
restinio::http_header_fields_t::add_field
void add_field(http_header_field_t http_header_field)
Add a field in the form of http_header_field object.
Definition: http_headers.hpp:901
restinio::http_header_fields_t::http_header_fields_t
http_header_fields_t(const http_header_fields_t &)=default
restinio::http_header_fields_t::add_field
void add_field(http_field_t field_id, std::string field_value)
Add a field in the form of id-value pair.
Definition: http_headers.hpp:860
restinio::http_header_fields_t::value_of
string_view_t value_of(http_field_t field_id) const
Get the value of a field or throw if the field not found.
Definition: http_headers.hpp:1280
restinio::http_header_fields_t::find
fields_container_t::iterator find(string_view_t field_name) noexcept
Definition: http_headers.hpp:1515
restinio::http_header_fields_t::try_get_field
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.
Definition: http_headers.hpp:1021
restinio::http_header_fields_t::remove_all_of
std::size_t remove_all_of(string_view_t field_name) noexcept
Remove all occurences of a field with specified name.
Definition: http_headers.hpp:1221
restinio::http_header_fields_t::http_header_fields_t
http_header_fields_t(http_header_fields_t &&)=default
restinio::http_header_fields_t::const_iterator
fields_container_t::const_iterator const_iterator
Type of const_iterator for enumeration of fields.
Definition: http_headers.hpp:711
restinio::http_header_fields_t::stop_enumeration
static constexpr handling_result_t stop_enumeration() noexcept
Definition: http_headers.hpp:732
restinio::http_header_fields_t::~http_header_fields_t
virtual ~http_header_fields_t()
Definition: http_headers.hpp:741
restinio::http_header_fields_t::swap_fields
void swap_fields(http_header_fields_t &http_header_fields)
Definition: http_headers.hpp:747
restinio::http_header_fields_t::get_field_or
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.
Definition: http_headers.hpp:1076
restinio::http_header_fields_t::fields_container_t
std::vector< http_header_field_t > fields_container_t
Definition: http_headers.hpp:708
restinio::http_header_fields_t::m_fields
fields_container_t m_fields
Definition: http_headers.hpp:1558
restinio::http_header_fields_t::opt_value_of
optional_t< string_view_t > opt_value_of(string_view_t name) const noexcept
Get optional value of a field.
Definition: http_headers.hpp:1300
restinio::http_header_fields_t::continue_enumeration
static constexpr handling_result_t continue_enumeration() noexcept
Definition: http_headers.hpp:729
restinio::http_header_fields_t::cfind
fields_container_t::const_iterator cfind(string_view_t field_name) const noexcept
Definition: http_headers.hpp:1526
restinio::http_header_fields_t::for_each_value_of
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.
Definition: http_headers.hpp:1401
restinio::http_header_fields_t::add_field
void add_field(std::string field_name, std::string field_value)
Add a field in the form of name-value pair.
Definition: http_headers.hpp:882
restinio::http_header_fields_t::for_each_value_of
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.
Definition: http_headers.hpp:1457
restinio::http_header_fields_t::remove_field
bool remove_field(http_field_t field_id) noexcept
Remove field by id.
Definition: http_headers.hpp:1198
restinio::http_header_fields_t::operator=
http_header_fields_t & operator=(const http_header_fields_t &)=default
restinio::http_header_fields_t::get_field
const std::string & get_field(http_field_t field_id) const
Get field by id.
Definition: http_headers.hpp:986
restinio::http_header_fields_t::set_field
void set_field(std::string field_name, std::string field_value)
Set field with string pair.
Definition: http_headers.hpp:801
restinio::http_header_fields_t::get_field_or
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.
Definition: http_headers.hpp:1059
restinio::http_header_fields_t::set_field
void set_field(http_field_t field_id, std::string field_value)
Set field with id-value pair.
Definition: http_headers.hpp:826
restinio::http_header_fields_t::operator=
http_header_fields_t & operator=(http_header_fields_t &&)=default
restinio::http_header_fields_t::get_field_or
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.
Definition: http_headers.hpp:1148
restinio::http_header_fields_t::handling_result_t
handling_result_t
The result of handling yet another field value.
Definition: http_headers.hpp:721
restinio::http_header_fields_t::handling_result_t::stop_enumeration
@ stop_enumeration
The loop on field values should be stopped.
restinio::http_header_fields_t::handling_result_t::continue_enumeration
@ continue_enumeration
Next value of field should be found and passed to the next invocation of handler.
restinio::http_header_fields_t::http_header_fields_t
http_header_fields_t()
Definition: http_headers.hpp:735
restinio::http_header_fields_t::try_get_field
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.
Definition: http_headers.hpp:975
restinio::http_header_fields_t::append_last_field
void append_last_field(string_view_t field_value)
Appends last added field.
Definition: http_headers.hpp:1509
restinio::http_header_fields_t::opt_value_of
optional_t< string_view_t > opt_value_of(http_field_t field_id) const noexcept
Get optional value of a field.
Definition: http_headers.hpp:1325
restinio::http_header_fields_t::get_field_or
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.
Definition: http_headers.hpp:1102
restinio::http_header_fields_t::set_field
void set_field(http_header_field_t http_header_field)
Set header field via http_header_field_t.
Definition: http_headers.hpp:773
restinio::http_header_fields_t::for_each_field
void for_each_field(Lambda &&lambda) const noexcept(noexcept(lambda(std::declval< const http_header_field_t & >())))
Enumeration of fields.
Definition: http_headers.hpp:1361
restinio::http_header_fields_t::append_field
void append_field(string_view_t field_name, string_view_t field_value)
Append field with name.
Definition: http_headers.hpp:908
restinio::http_header_fields_t::get_field_or
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.
Definition: http_headers.hpp:1122
restinio::http_header_fields_t::end
const_iterator end() const noexcept
Definition: http_headers.hpp:1488
restinio::http_header_fields_t::get_field
const std::string & get_field(string_view_t field_name) const
Get field by name.
Definition: http_headers.hpp:951
restinio::http_header_fields_t::fields_count
auto fields_count() const noexcept
Definition: http_headers.hpp:1493
restinio::http_header_fields_t::get_field_or
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.
Definition: http_headers.hpp:1088
restinio::http_header_fields_t::begin
const_iterator begin() const noexcept
Definition: http_headers.hpp:1482
restinio::http_header_fields_t::remove_field
bool remove_field(string_view_t field_name) noexcept
Remove field by name.
Definition: http_headers.hpp:1174
restinio::http_header_fields_t::get_field_or
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.
Definition: http_headers.hpp:1040
restinio::http_header_fields_t::has_field
bool has_field(http_field_t field_id) const noexcept
Check field by field-id.
Definition: http_headers.hpp:766
restinio::http_header_fields_t::cfind
fields_container_t::const_iterator cfind(http_field_t field_id) const noexcept
Definition: http_headers.hpp:1548
restinio::http_header_fields_t::get_field_or
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.
Definition: http_headers.hpp:1134
restinio::http_header_fields_t::remove_all_of
std::size_t remove_all_of(http_field_t field_id) noexcept
Remove all occurences of a field with specified id.
Definition: http_headers.hpp:1245
restinio::http_header_fields_t::find
fields_container_t::iterator find(http_field_t field_id) noexcept
Definition: http_headers.hpp:1537
restinio::http_header_fields_t::append_field
void append_field(http_field_t field_id, string_view_t field_value)
Append field with id.
Definition: http_headers.hpp:930
restinio::http_method_id_t
A type for representation of HTTP method ID.
Definition: http_headers.hpp:1744
restinio::http_method_id_t::m_value
int m_value
Definition: http_headers.hpp:1745
restinio::http_method_id_t::operator<
friend constexpr bool operator<(const http_method_id_t &a, const http_method_id_t &b) noexcept
Definition: http_headers.hpp:1787
restinio::http_method_id_t::unknown_method
static constexpr const int unknown_method
Definition: http_headers.hpp:1749
restinio::http_method_id_t::http_method_id_t
constexpr http_method_id_t(const http_method_id_t &) noexcept=default
restinio::http_method_id_t::operator!=
friend constexpr bool operator!=(const http_method_id_t &a, const http_method_id_t &b) noexcept
Definition: http_headers.hpp:1782
restinio::http_method_id_t::http_method_id_t
constexpr http_method_id_t() noexcept
Definition: http_headers.hpp:1751
restinio::http_method_id_t::http_method_id_t
constexpr http_method_id_t(http_method_id_t &&) noexcept=default
restinio::http_method_id_t::m_name
const char * m_name
Definition: http_headers.hpp:1746
restinio::http_method_id_t::raw_id
constexpr auto raw_id() const noexcept
Definition: http_headers.hpp:1771
restinio::http_method_id_t::operator=
constexpr http_method_id_t & operator=(const http_method_id_t &) noexcept=default
restinio::http_method_id_t::http_method_id_t
constexpr http_method_id_t(int value, const char *name) noexcept
Definition: http_headers.hpp:1755
restinio::http_method_id_t::operator==
friend constexpr bool operator==(const http_method_id_t &a, const http_method_id_t &b) noexcept
Definition: http_headers.hpp:1777
restinio::http_method_id_t::c_str
constexpr const char * c_str() const noexcept
Definition: http_headers.hpp:1774
restinio::http_status_code_t
A handy wrapper for HTTP response status code.
Definition: http_headers.hpp:1993
restinio::http_status_code_t::raw_code
constexpr auto raw_code() const noexcept
Definition: http_headers.hpp:2003
restinio::http_status_code_t::operator==
constexpr bool operator==(const http_status_code_t &sc) const noexcept
Definition: http_headers.hpp:2009
restinio::http_status_code_t::operator!=
constexpr bool operator!=(const http_status_code_t &sc) const noexcept
Definition: http_headers.hpp:2015
restinio::http_status_code_t::http_status_code_t
constexpr http_status_code_t() noexcept
Definition: http_headers.hpp:1995
restinio::http_status_code_t::operator<
constexpr bool operator<(const http_status_code_t &sc) const noexcept
Definition: http_headers.hpp:2021
restinio::http_status_code_t::http_status_code_t
constexpr http_status_code_t(std::uint16_t status_code) noexcept
Definition: http_headers.hpp:1998
restinio::http_status_code_t::m_status_code
std::uint16_t m_status_code
Status code value.
Definition: http_headers.hpp:2028
restinio::http_status_line_t
HTTP response header status line.
Definition: http_headers.hpp:2124
restinio::http_status_line_t::reason_phrase
void reason_phrase(std::string r)
Definition: http_headers.hpp:2149
restinio::http_status_line_t::status_code
void status_code(http_status_code_t c) noexcept
Definition: http_headers.hpp:2141
restinio::http_status_line_t::http_status_line_t
http_status_line_t(http_status_code_t sc, std::string reason_phrase)
Definition: http_headers.hpp:2129
restinio::http_status_line_t::m_reason_phrase
std::string m_reason_phrase
Definition: http_headers.hpp:2154
restinio::http_status_line_t::status_code
http_status_code_t status_code() const noexcept
Definition: http_headers.hpp:2137
restinio::http_status_line_t::m_status_code
http_status_code_t m_status_code
Definition: http_headers.hpp:2153
restinio::http_status_line_t::reason_phrase
const std::string & reason_phrase() const noexcept
Definition: http_headers.hpp:2145
restinio::http_status_line_t::http_status_line_t
http_status_line_t()
Definition: http_headers.hpp:2126
common_types.hpp
exception.hpp
RESTINIO_HTTP_METHOD_MAP
#define RESTINIO_HTTP_METHOD_MAP(RESTINIO_GEN)
HTTP methods mapping with nodejs http methods.
Definition: http_headers.hpp:1652
RESTINIO_HEADER_FIELDS_DEFAULT_RESERVE_COUNT
#define RESTINIO_HEADER_FIELDS_DEFAULT_RESERVE_COUNT
Definition: http_headers.hpp:668
RESTINIO_HTTP_METHOD_FUNC_GEN
#define RESTINIO_HTTP_METHOD_FUNC_GEN(func_name, nodejs_code, method_name)
Definition: http_headers.hpp:1799
RESTINIO_HTTP_FIELD_STR_GEN
#define RESTINIO_HTTP_FIELD_STR_GEN(name, string_name)
RESTINIO_HTTP_FIELDS_MAP
#define RESTINIO_HTTP_FIELDS_MAP(RESTINIO_GEN)
Definition: http_headers.hpp:34
RESTINIO_HTTP_CHECK_FOR_FIELD
#define RESTINIO_HTTP_CHECK_FOR_FIELD(field_id, candidate_field_name)
include_fmtlib.hpp
A special wrapper around fmtlib include files.
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:465
nonstd::optional_lite::swap
void swap(optional< T > &x, optional< T > &y)
Definition: optional.hpp:1705
restinio::impl::is_equal_caseless
bool is_equal_caseless(const char *a, const char *b, std::size_t size) noexcept
Comparator for fields names.
Definition: string_caseless_compare.hpp:40
restinio::impl::append_last_field_accessor
void append_last_field_accessor(http_header_fields_t &, string_view_t)
restinio::status_code::switching_protocols
constexpr http_status_code_t switching_protocols
Definition: http_headers.hpp:2042
restinio::status_code::gone
constexpr http_status_code_t gone
Definition: http_headers.hpp:2067
restinio::status_code::precondition_failed
constexpr http_status_code_t precondition_failed
Definition: http_headers.hpp:2069
restinio::status_code::ok
constexpr http_status_code_t ok
Definition: http_headers.hpp:2043
restinio::status_code::unauthorized
constexpr http_status_code_t unauthorized
Definition: http_headers.hpp:2058
restinio::status_code::bad_request
constexpr http_status_code_t bad_request
Definition: http_headers.hpp:2057
restinio::status_code::see_other
constexpr http_status_code_t see_other
Definition: http_headers.hpp:2053
restinio::status_code::multiple_choices
constexpr http_status_code_t multiple_choices
Definition: http_headers.hpp:2050
restinio::status_code::not_acceptable
constexpr http_status_code_t not_acceptable
Definition: http_headers.hpp:2063
restinio::status_code::not_found
constexpr http_status_code_t not_found
Definition: http_headers.hpp:2061
restinio::status_code::forbidden
constexpr http_status_code_t forbidden
Definition: http_headers.hpp:2060
restinio::status_code::gateway_time_out
constexpr http_status_code_t gateway_time_out
Definition: http_headers.hpp:2090
restinio::status_code::uri_too_long
constexpr http_status_code_t uri_too_long
Definition: http_headers.hpp:2081
restinio::status_code::partial_content
constexpr http_status_code_t partial_content
Definition: http_headers.hpp:2049
restinio::status_code::requested_range_not_satisfiable
constexpr http_status_code_t requested_range_not_satisfiable
Definition: http_headers.hpp:2084
restinio::status_code::unsupported_media_type
constexpr http_status_code_t unsupported_media_type
Definition: http_headers.hpp:2083
restinio::status_code::locked
constexpr http_status_code_t locked
Definition: http_headers.hpp:2105
restinio::status_code::not_implemented
constexpr http_status_code_t not_implemented
Definition: http_headers.hpp:2087
restinio::status_code::request_header_fields_too_large
constexpr http_status_code_t request_header_fields_too_large
Definition: http_headers.hpp:2112
restinio::status_code::payload_too_large
constexpr http_status_code_t payload_too_large
Definition: http_headers.hpp:2074
restinio::status_code::failed_dependency
constexpr http_status_code_t failed_dependency
Definition: http_headers.hpp:2106
restinio::status_code::unprocessable_entity
constexpr http_status_code_t unprocessable_entity
Definition: http_headers.hpp:2104
restinio::status_code::conflict
constexpr http_status_code_t conflict
Definition: http_headers.hpp:2066
restinio::status_code::network_authentication_required
constexpr http_status_code_t network_authentication_required
Definition: http_headers.hpp:2113
restinio::status_code::not_modified
constexpr http_status_code_t not_modified
Definition: http_headers.hpp:2054
restinio::status_code::no_content
constexpr http_status_code_t no_content
Definition: http_headers.hpp:2047
restinio::status_code::accepted
constexpr http_status_code_t accepted
Definition: http_headers.hpp:2045
restinio::status_code::created
constexpr http_status_code_t created
Definition: http_headers.hpp:2044
restinio::status_code::http_version_not_supported
constexpr http_status_code_t http_version_not_supported
Definition: http_headers.hpp:2091
restinio::status_code::multi_status
constexpr http_status_code_t multi_status
Definition: http_headers.hpp:2103
restinio::status_code::processing
constexpr http_status_code_t processing
Definition: http_headers.hpp:2102
restinio::status_code::bad_gateway
constexpr http_status_code_t bad_gateway
Definition: http_headers.hpp:2088
restinio::status_code::use_proxy
constexpr http_status_code_t use_proxy
Definition: http_headers.hpp:2055
restinio::status_code::found
constexpr http_status_code_t found
Definition: http_headers.hpp:2052
restinio::status_code::continue_
constexpr http_status_code_t continue_
Definition: http_headers.hpp:2040
restinio::status_code::temporary_redirect
constexpr http_status_code_t temporary_redirect
Definition: http_headers.hpp:2056
restinio::status_code::method_not_allowed
constexpr http_status_code_t method_not_allowed
Definition: http_headers.hpp:2062
restinio::status_code::permanent_redirect
constexpr http_status_code_t permanent_redirect
Definition: http_headers.hpp:2099
restinio::status_code::length_required
constexpr http_status_code_t length_required
Definition: http_headers.hpp:2068
restinio::status_code::insufficient_storage
constexpr http_status_code_t insufficient_storage
Definition: http_headers.hpp:2107
restinio::status_code::service_unavailable
constexpr http_status_code_t service_unavailable
Definition: http_headers.hpp:2089
restinio::status_code::precondition_required
constexpr http_status_code_t precondition_required
Definition: http_headers.hpp:2110
restinio::status_code::request_time_out
constexpr http_status_code_t request_time_out
Definition: http_headers.hpp:2065
restinio::status_code::internal_server_error
constexpr http_status_code_t internal_server_error
Definition: http_headers.hpp:2086
restinio::status_code::too_many_requests
constexpr http_status_code_t too_many_requests
Definition: http_headers.hpp:2111
restinio::status_code::proxy_authentication_required
constexpr http_status_code_t proxy_authentication_required
Definition: http_headers.hpp:2064
restinio::status_code::payment_required
constexpr http_status_code_t payment_required
Definition: http_headers.hpp:2059
restinio::status_code::moved_permanently
constexpr http_status_code_t moved_permanently
Definition: http_headers.hpp:2051
restinio::status_code::reset_content
constexpr http_status_code_t reset_content
Definition: http_headers.hpp:2048
restinio::status_code::expectation_failed
constexpr http_status_code_t expectation_failed
Definition: http_headers.hpp:2085
restinio::status_code::non_authoritative_information
constexpr http_status_code_t non_authoritative_information
Definition: http_headers.hpp:2046
restinio
Definition: asio_include.hpp:21
restinio::status_gone
http_status_line_t status_gone()
Definition: http_headers.hpp:2247
restinio::status_not_acceptable
http_status_line_t status_not_acceptable()
Definition: http_headers.hpp:2235
restinio::status_non_authoritative_information
http_status_line_t status_non_authoritative_information()
Definition: http_headers.hpp:2184
restinio::status_locked
http_status_line_t status_locked()
Definition: http_headers.hpp:2308
restinio::status_not_implemented
http_status_line_t status_not_implemented()
Definition: http_headers.hpp:2274
restinio::status_unprocessable_entity
http_status_line_t status_unprocessable_entity()
Definition: http_headers.hpp:2305
restinio::nullable_pointer_t
T * nullable_pointer_t
Type for pointer that can be nullptr.
Definition: common_types.hpp:154
restinio::status_http_version_not_supported
http_status_line_t status_http_version_not_supported()
Definition: http_headers.hpp:2286
restinio::status_payment_required
http_status_line_t status_payment_required()
Definition: http_headers.hpp:2223
restinio::status_conflict
http_status_line_t status_conflict()
Definition: http_headers.hpp:2244
restinio::status_permanent_redirect
http_status_line_t status_permanent_redirect()
Definition: http_headers.hpp:2295
restinio::status_partial_content
http_status_line_t status_partial_content()
Definition: http_headers.hpp:2193
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::status_no_content
http_status_line_t status_no_content()
Definition: http_headers.hpp:2187
restinio::status_network_authentication_required
http_status_line_t status_network_authentication_required()
Definition: http_headers.hpp:2327
restinio::status_not_modified
http_status_line_t status_not_modified()
Definition: http_headers.hpp:2208
restinio::status_failed_dependency
http_status_line_t status_failed_dependency()
Definition: http_headers.hpp:2311
restinio::status_moved_permanently
http_status_line_t status_moved_permanently()
Definition: http_headers.hpp:2199
restinio::status_forbidden
http_status_line_t status_forbidden()
Definition: http_headers.hpp:2226
restinio::http_connection_header_t
http_connection_header_t
Values for conection header field.
Definition: http_headers.hpp:1567
restinio::http_connection_header_t::close
@ close
restinio::http_connection_header_t::keep_alive
@ keep_alive
restinio::operator<<
std::ostream & operator<<(std::ostream &o, response_parts_attr_t attr)
Definition: common_types.hpp:82
restinio::status_continue
http_status_line_t status_continue()
Definition: http_headers.hpp:2169
restinio::status_requested_range_not_satisfiable
http_status_line_t status_requested_range_not_satisfiable()
Definition: http_headers.hpp:2265
restinio::status_internal_server_error
http_status_line_t status_internal_server_error()
Definition: http_headers.hpp:2271
restinio::status_use_proxy
http_status_line_t status_use_proxy()
Definition: http_headers.hpp:2211
restinio::status_request_time_out
http_status_line_t status_request_time_out()
Definition: http_headers.hpp:2241
restinio::status_created
http_status_line_t status_created()
Definition: http_headers.hpp:2178
restinio::status_unauthorized
http_status_line_t status_unauthorized()
Definition: http_headers.hpp:2220
restinio::status_temporary_redirect
http_status_line_t status_temporary_redirect()
Definition: http_headers.hpp:2214
restinio::status_gateway_time_out
http_status_line_t status_gateway_time_out()
Definition: http_headers.hpp:2283
restinio::status_found
http_status_line_t status_found()
Definition: http_headers.hpp:2202
restinio::status_multiple_choices
http_status_line_t status_multiple_choices()
Definition: http_headers.hpp:2196
restinio::http_method_unknown
constexpr http_method_id_t http_method_unknown()
Definition: http_headers.hpp:1808
restinio::status_insufficient_storage
http_status_line_t status_insufficient_storage()
Definition: http_headers.hpp:2314
restinio::status_unsupported_media_type
http_status_line_t status_unsupported_media_type()
Definition: http_headers.hpp:2262
restinio::status_too_many_requests
http_status_line_t status_too_many_requests()
Definition: http_headers.hpp:2321
restinio::status_bad_gateway
http_status_line_t status_bad_gateway()
Definition: http_headers.hpp:2277
restinio::status_expectation_failed
http_status_line_t status_expectation_failed()
Definition: http_headers.hpp:2268
restinio::status_see_other
http_status_line_t status_see_other()
Definition: http_headers.hpp:2205
restinio::string_to_field
http_field_t string_to_field(string_view_t field) noexcept
Helper function to get method string name.
Definition: http_headers.hpp:251
restinio::field_to_string
const char * field_to_string(http_field_t f) noexcept
Helper sunction to get method string name.
Definition: http_headers.hpp:553
restinio::status_reset_content
http_status_line_t status_reset_content()
Definition: http_headers.hpp:2190
restinio::status_ok
http_status_line_t status_ok()
Definition: http_headers.hpp:2175
restinio::http_field_t
http_field_t
C++ enum that repeats nodejs c-style enum.
Definition: http_headers.hpp:233
restinio::http_field_t::field_unspecified
@ field_unspecified
restinio::status_switching_protocols
http_status_line_t status_switching_protocols()
Definition: http_headers.hpp:2172
restinio::status_payload_too_large
http_status_line_t status_payload_too_large()
Definition: http_headers.hpp:2256
restinio::status_uri_too_long
http_status_line_t status_uri_too_long()
Definition: http_headers.hpp:2259
restinio::status_request_header_fields_too_large
http_status_line_t status_request_header_fields_too_large()
Definition: http_headers.hpp:2324
restinio::status_processing
http_status_line_t status_processing()
Definition: http_headers.hpp:2299
restinio::status_precondition_failed
http_status_line_t status_precondition_failed()
Definition: http_headers.hpp:2253
restinio::status_method_not_allowed
http_status_line_t status_method_not_allowed()
Definition: http_headers.hpp:2232
restinio::status_accepted
http_status_line_t status_accepted()
Definition: http_headers.hpp:2181
restinio::status_proxy_authentication_required
http_status_line_t status_proxy_authentication_required()
Definition: http_headers.hpp:2238
restinio::status_precondition_required
http_status_line_t status_precondition_required()
Definition: http_headers.hpp:2318
restinio::status_bad_request
http_status_line_t status_bad_request()
Definition: http_headers.hpp:2217
restinio::status_not_found
http_status_line_t status_not_found()
Definition: http_headers.hpp:2229
restinio::status_multi_status
http_status_line_t status_multi_status()
Definition: http_headers.hpp:2302
restinio::status_service_unavailable
http_status_line_t status_service_unavailable()
Definition: http_headers.hpp:2280
restinio::status_length_required
http_status_line_t status_length_required()
Definition: http_headers.hpp:2250
std
STL namespace.
optional.hpp
string_caseless_compare.hpp
Helpers for caseless comparison of strings.
string_view.hpp
restinio::http_header_common_t
Req/Resp headers common data.
Definition: http_headers.hpp:1580
restinio::http_header_common_t::should_keep_alive
void should_keep_alive(bool keep_alive) noexcept
Definition: http_headers.hpp:1617
restinio::http_header_common_t::content_length
void content_length(std::uint64_t l) noexcept
Definition: http_headers.hpp:1607
restinio::http_header_common_t::http_major
void http_major(std::uint16_t v) noexcept
Definition: http_headers.hpp:1589
restinio::http_header_common_t::should_keep_alive
bool should_keep_alive() const noexcept
Definition: http_headers.hpp:1611
restinio::http_header_common_t::m_http_connection_header_field_value
http_connection_header_t m_http_connection_header_field_value
Definition: http_headers.hpp:1648
restinio::http_header_common_t::http_major
std::uint16_t http_major() const noexcept
Http version.
Definition: http_headers.hpp:1585
restinio::http_header_common_t::connection
http_connection_header_t connection() const
Get the value of 'connection' header field.
Definition: http_headers.hpp:1626
restinio::http_header_common_t::m_http_major
std::uint16_t m_http_major
Http version.
Definition: http_headers.hpp:1641
restinio::http_header_common_t::m_content_length
std::uint64_t m_content_length
Length of body of an http-message.
Definition: http_headers.hpp:1646
restinio::http_header_common_t::content_length
std::uint64_t content_length() const noexcept
Length of body of an http-message.
Definition: http_headers.hpp:1603
restinio::http_header_common_t::http_minor
void http_minor(std::uint16_t v) noexcept
Definition: http_headers.hpp:1597
restinio::http_header_common_t::http_minor
std::uint16_t http_minor() const noexcept
Definition: http_headers.hpp:1593
restinio::http_header_common_t::m_http_minor
std::uint16_t m_http_minor
Definition: http_headers.hpp:1642
restinio::http_header_common_t::connection
void connection(http_connection_header_t ch) noexcept
Set the value of 'connection' header field.
Definition: http_headers.hpp:1633
restinio::http_request_header_t
Req header.
Definition: http_headers.hpp:1859
restinio::http_request_header_t::method
void method(http_method_id_t m) noexcept
Definition: http_headers.hpp:1885
restinio::http_request_header_t::request_target
void request_target(std::string t)
Definition: http_headers.hpp:1893
restinio::http_request_header_t::fragment
string_view_t fragment() const
Get the fragment part of the request URL.
Definition: http_headers.hpp:1941
restinio::http_request_header_t::m_method
http_method_id_t m_method
Definition: http_headers.hpp:1981
restinio::http_request_header_t::path
string_view_t path() const noexcept
Request URL-structure.
Definition: http_headers.hpp:1913
restinio::http_request_header_t::m_query_separator_pos
std::size_t m_query_separator_pos
Definition: http_headers.hpp:1983
restinio::http_request_header_t::request_target
const std::string & request_target() const noexcept
Definition: http_headers.hpp:1889
restinio::http_request_header_t::append_request_target
void append_request_target(const char *at, size_t length)
Helpfull function for using in parser callback.
Definition: http_headers.hpp:1954
restinio::http_request_header_t::m_fragment_separator_pos
std::size_t m_fragment_separator_pos
Definition: http_headers.hpp:1984
restinio::http_request_header_t::memchr_helper
static std::size_t memchr_helper(int chr, const char *from, std::size_t size)
Definition: http_headers.hpp:1861
restinio::http_request_header_t::method
http_method_id_t method() const noexcept
Definition: http_headers.hpp:1881
restinio::http_request_header_t::query
string_view_t query() const noexcept
Get the query part of the request URL.
Definition: http_headers.hpp:1924
restinio::http_request_header_t::http_request_header_t
http_request_header_t()=default
restinio::http_request_header_t::http_request_header_t
http_request_header_t(http_method_id_t method, std::string request_target_)
Definition: http_headers.hpp:1872
restinio::http_request_header_t::m_request_target
std::string m_request_target
Definition: http_headers.hpp:1982
restinio::http_response_header_t
Resp header.
Definition: http_headers.hpp:2338
restinio::http_response_header_t::status_code
void status_code(http_status_code_t c) noexcept
Definition: http_headers.hpp:2352
restinio::http_response_header_t::http_response_header_t
http_response_header_t()
Definition: http_headers.hpp:2340
restinio::http_response_header_t::status_line
const http_status_line_t & status_line() const noexcept
Definition: http_headers.hpp:2364
restinio::http_response_header_t::reason_phrase
void reason_phrase(std::string r)
Definition: http_headers.hpp:2360
restinio::http_response_header_t::status_line
void status_line(http_status_line_t sl)
Definition: http_headers.hpp:2370
restinio::http_response_header_t::status_code
http_status_code_t status_code() const noexcept
Definition: http_headers.hpp:2348
restinio::http_response_header_t::m_status_line
http_status_line_t m_status_line
Definition: http_headers.hpp:2376
restinio::http_response_header_t::http_response_header_t
http_response_header_t(http_status_line_t status_line)
Definition: http_headers.hpp:2343
restinio::http_response_header_t::reason_phrase
const std::string & reason_phrase() const noexcept
Definition: http_headers.hpp:2356
const
#define const
Definition: zconf.h:230