14 : state_(method_start) {
19 state_ = method_start;
23 boost::tribool RequestParser::consume (
Request& req,
char input) {
28 if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
33 req.method.push_back(input);
34 return boost::indeterminate;
40 return boost::indeterminate;
42 }
else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
46 req.method.push_back(input);
47 return boost::indeterminate;
56 req.uri.push_back(input);
57 return boost::indeterminate;
62 state_ = http_version_h;
63 return boost::indeterminate;
65 }
else if (is_ctl(input)) {
69 req.uri.push_back(input);
70 return boost::indeterminate;
75 state_ = http_version_t_1;
76 return boost::indeterminate;
82 case http_version_t_1:
84 state_ = http_version_t_2;
85 return boost::indeterminate;
91 case http_version_t_2:
93 state_ = http_version_p;
94 return boost::indeterminate;
102 state_ = http_version_slash;
103 return boost::indeterminate;
109 case http_version_slash:
111 req.http_version_major = 0;
112 req.http_version_minor = 0;
113 state_ = http_version_major_start;
114 return boost::indeterminate;
120 case http_version_major_start:
121 if (is_digit(input)) {
122 req.http_version_major = req.http_version_major * 10 + input -
'0';
123 state_ = http_version_major;
124 return boost::indeterminate;
130 case http_version_major:
132 state_ = http_version_minor_start;
133 return boost::indeterminate;
135 }
else if (is_digit(input)) {
136 req.http_version_major = req.http_version_major * 10 + input -
'0';
137 return boost::indeterminate;
143 case http_version_minor_start:
144 if (is_digit(input)) {
145 req.http_version_minor = req.http_version_minor * 10 + input -
'0';
146 state_ = http_version_minor;
147 return boost::indeterminate;
153 case http_version_minor:
155 state_ = expecting_newline_1;
156 return boost::indeterminate;
158 }
else if (is_digit(input)) {
159 req.http_version_minor = req.http_version_minor * 10 + input -
'0';
160 return boost::indeterminate;
166 case expecting_newline_1:
168 state_ = header_line_start;
169 return boost::indeterminate;
175 case header_line_start:
177 state_ = expecting_newline_3;
178 return boost::indeterminate;
180 }
else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
184 state_ = header_name;
185 return boost::indeterminate;
190 state_ = expecting_newline_2;
191 return boost::indeterminate;
193 }
else if (input ==
' ' || input ==
'\t') {
194 return boost::indeterminate;
196 }
else if (is_ctl(input)) {
200 state_ = header_value;
201 return boost::indeterminate;
206 state_ = space_before_header_value;
207 return boost::indeterminate;
209 }
else if (!is_char(input) || is_ctl(input) || is_tspecial(input)) {
213 return boost::indeterminate;
216 case space_before_header_value:
218 state_ = header_value;
219 return boost::indeterminate;
227 state_ = expecting_newline_2;
228 return boost::indeterminate;
230 }
else if (is_ctl(input)) {
234 return boost::indeterminate;
237 case expecting_newline_2:
239 state_ = header_line_start;
240 return boost::indeterminate;
246 case expecting_newline_3:
247 return (input ==
'\n');
255 bool RequestParser::is_char(
int c) {
256 return c >= 0 && c <= 127;
260 bool RequestParser::is_ctl(
int c) {
261 return (c >= 0 && c <= 31) || (c == 127);
265 bool RequestParser::is_tspecial(
int c) {
267 case '(':
case ')':
case '<':
case '>':
case '@':
268 case ',':
case ';':
case ':':
case '\\':
case '"':
269 case '/':
case '[':
case ']':
case '?':
case '=':
270 case '{':
case '}':
case ' ':
case '\t':
278 bool RequestParser::is_digit(
int c) {
279 return c >=
'0' && c <=
'9';