aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/pegtl/contrib/http.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'MoonParser/pegtl/contrib/http.hpp')
-rw-r--r--MoonParser/pegtl/contrib/http.hpp152
1 files changed, 152 insertions, 0 deletions
diff --git a/MoonParser/pegtl/contrib/http.hpp b/MoonParser/pegtl/contrib/http.hpp
new file mode 100644
index 0000000..1446449
--- /dev/null
+++ b/MoonParser/pegtl/contrib/http.hpp
@@ -0,0 +1,152 @@
1// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey
2// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3
4#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_HTTP_HPP
5#define TAOCPP_PEGTL_INCLUDE_CONTRIB_HTTP_HPP
6
7#include "../ascii.hpp"
8#include "../config.hpp"
9#include "../rules.hpp"
10#include "../utf8.hpp"
11#include "abnf.hpp"
12#include "uri.hpp"
13
14namespace tao
15{
16 namespace TAOCPP_PEGTL_NAMESPACE
17 {
18 namespace http
19 {
20 // HTTP 1.1 grammar according to RFC 7230.
21
22 // This grammar is a direct PEG translation of the original HTTP grammar.
23 // It should be considered experimental -- in case of any issues, in particular
24 // missing rules for attached actions, please contact the developers.
25
26 using namespace abnf;
27
28 using OWS = star< WSP >; // optional whitespace
29 using RWS = plus< WSP >; // required whitespace
30 using BWS = OWS; // "bad" whitespace
31
32 // cppcheck-suppress constStatement
33 using obs_text = not_range< 0x00, 0x7F >;
34 using obs_fold = seq< CRLF, plus< WSP > >;
35
36 // clang-format off
37 struct tchar : sor< ALPHA, DIGIT, one< '!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~' > > {};
38 struct token : plus< tchar > {};
39
40 struct field_name : token {};
41
42 struct field_vchar : sor< VCHAR, obs_text > {};
43 struct field_content : list< field_vchar, plus< WSP > > {};
44 struct field_value : star< sor< field_content, obs_fold > > {};
45
46 struct header_field : seq< field_name, one< ':' >, OWS, field_value, OWS > {};
47
48 struct method : token {};
49
50 struct absolute_path : plus< one< '/' >, uri::segment > {};
51
52 struct origin_form : seq< absolute_path, uri::opt_query > {};
53 struct absolute_form : uri::absolute_URI {};
54 struct authority_form : uri::authority {};
55 struct asterisk_form : one< '*' > {};
56
57 struct request_target : sor< origin_form, absolute_form, authority_form, asterisk_form > {};
58
59 struct status_code : rep< 3, DIGIT > {};
60 struct reason_phrase : star< sor< VCHAR, obs_text, WSP > > {};
61
62 struct HTTP_version : if_must< TAOCPP_PEGTL_STRING( "HTTP/" ), DIGIT, one< '.' >, DIGIT > {};
63
64 struct request_line : if_must< method, SP, request_target, SP, HTTP_version, CRLF > {};
65 struct status_line : if_must< HTTP_version, SP, status_code, SP, reason_phrase, CRLF > {};
66 struct start_line : sor< status_line, request_line > {};
67
68 struct message_body : star< OCTET > {};
69 struct HTTP_message : seq< start_line, star< header_field, CRLF >, CRLF, opt< message_body > > {};
70
71 struct Content_Length : plus< DIGIT > {};
72
73 struct uri_host : uri::host {};
74 struct port : uri::port {};
75
76 struct Host : seq< uri_host, opt< one< ':' >, port > > {};
77
78 // PEG are different from CFGs! (this replaces ctext and qdtext)
79 using text = sor< HTAB, range< 0x20, 0x7E >, obs_text >;
80
81 struct quoted_pair : if_must< one< '\\' >, sor< VCHAR, obs_text, WSP > > {};
82 struct quoted_string : if_must< DQUOTE, until< DQUOTE, sor< quoted_pair, text > > > {};
83
84 struct transfer_parameter : seq< token, BWS, one< '=' >, BWS, sor< token, quoted_string > > {};
85 struct transfer_extension : seq< token, star< OWS, one< ';' >, OWS, transfer_parameter > > {};
86 struct transfer_coding : sor< TAOCPP_PEGTL_ISTRING( "chunked" ),
87 TAOCPP_PEGTL_ISTRING( "compress" ),
88 TAOCPP_PEGTL_ISTRING( "deflate" ),
89 TAOCPP_PEGTL_ISTRING( "gzip" ),
90 transfer_extension > {};
91
92 struct rank : sor< seq< one< '0' >, opt< one< '.' >, rep_opt< 3, DIGIT > > >,
93 seq< one< '1' >, opt< one< '.' >, rep_opt< 3, one< '0' > > > > > {};
94
95 struct t_ranking : seq< OWS, one< ';' >, OWS, one< 'q', 'Q' >, one< '=' >, rank > {};
96 struct t_codings : sor< TAOCPP_PEGTL_ISTRING( "trailers" ), seq< transfer_coding, opt< t_ranking > > > {};
97
98 struct TE : opt< sor< one< ',' >, t_codings >, star< OWS, one< ',' >, opt< OWS, t_codings > > > {};
99
100 template< typename T >
101 using make_comma_list = seq< star< one< ',' >, OWS >, T, star< OWS, one< ',' >, opt< OWS, T > > >;
102
103 struct connection_option : token {};
104 struct Connection : make_comma_list< connection_option > {};
105
106 struct Trailer : make_comma_list< field_name > {};
107
108 struct Transfer_Encoding : make_comma_list< transfer_coding > {};
109
110 struct protocol_name : token {};
111 struct protocol_version : token {};
112 struct protocol : seq< protocol_name, opt< one< '/' >, protocol_version > > {};
113 struct Upgrade : make_comma_list< protocol > {};
114
115 struct pseudonym : token {};
116
117 struct received_protocol : seq< opt< protocol_name, one< '/' > >, protocol_version > {};
118 struct received_by : sor< seq< uri_host, opt< one< ':' >, port > >, pseudonym > {};
119
120 struct comment : if_must< one< '(' >, until< one< ')' >, sor< comment, quoted_pair, text > > > {};
121
122 struct Via : make_comma_list< seq< received_protocol, RWS, received_by, opt< RWS, comment > > > {};
123
124 struct http_URI : if_must< TAOCPP_PEGTL_ISTRING( "http://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {};
125 struct https_URI : if_must< TAOCPP_PEGTL_ISTRING( "https://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {};
126
127 struct partial_URI : seq< uri::relative_part, uri::opt_query > {};
128
129 struct chunk_size : plus< HEXDIG > {};
130
131 struct chunk_ext_name : token {};
132 struct chunk_ext_val : sor< quoted_string, token > {};
133 struct chunk_ext : star< if_must< one< ';' >, chunk_ext_name, if_must< one< '=' >, chunk_ext_val > > > {};
134
135 struct chunk_data : until< at< CRLF >, OCTET > {};
136
137 struct chunk : seq< chunk_size, opt< chunk_ext >, CRLF, chunk_data, CRLF > {};
138
139 struct last_chunk : seq< plus< one< '0' > >, opt< chunk_ext >, CRLF > {};
140
141 struct trailer_part : star< header_field, CRLF > {};
142
143 struct chunked_body : seq< until< last_chunk, chunk >, trailer_part, CRLF > {};
144 // clang-format on
145
146 } // namespace http
147
148 } // namespace TAOCPP_PEGTL_NAMESPACE
149
150} // namespace tao
151
152#endif