File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed
boost/network/protocol/http/parser Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,10 @@ namespace boost { namespace network { namespace http {
31
31
http_version_minor,
32
32
http_version_done,
33
33
http_status_digit,
34
- http_status_done
34
+ http_status_done,
35
+ http_status_message_char,
36
+ http_status_message_cr,
37
+ http_status_message_done
35
38
};
36
39
37
40
typedef typename string<Tag>::type::const_iterator iterator_type;
@@ -166,6 +169,34 @@ namespace boost { namespace network { namespace http {
166
169
parsed_ok = false ;
167
170
}
168
171
break ;
172
+ case http_status_done:
173
+ // FIXME find a better way to use is_alnum, is_space
174
+ if (algorithm::is_alnum ()(*current)) {
175
+ state_ = http_status_message_char;
176
+ ++current;
177
+ } else {
178
+ parsed_ok = false ;
179
+ }
180
+ break ;
181
+ case http_status_message_char:
182
+ // FIXME find a better way to use is_alnum, is_space
183
+ if (algorithm::is_alnum ()(*current) || algorithm::is_punct ()(*current) || (*current == ' ' )) {
184
+ ++current;
185
+ } else if (*current == ' \r ' ) {
186
+ state_ = http_status_message_cr;
187
+ ++current;
188
+ } else {
189
+ parsed_ok = false ;
190
+ }
191
+ break ;
192
+ case http_status_message_cr:
193
+ if (*current == ' \n ' ) {
194
+ state_ = http_status_message_done;
195
+ ++current;
196
+ } else {
197
+ parsed_ok = false ;
198
+ }
199
+ break ;
169
200
default :
170
201
parsed_ok = false ;
171
202
}
Original file line number Diff line number Diff line change @@ -132,3 +132,22 @@ BOOST_AUTO_TEST_CASE(incremental_parser_parse_status) {
132
132
std::cout << " PARSED: " << parsed << " state=" << p.state () << std::endl;
133
133
}
134
134
135
+ /* * In this test then we get the rest of the first line of the HTTP
136
+ * Response, and treat it as the status message.
137
+ */
138
+ BOOST_AUTO_TEST_CASE (incremental_parser_parse_status_message) {
139
+ typedef response_parser<tags::default_string> response_parser_type;
140
+ typedef response_parser_type::range_type range_type;
141
+ response_parser_type p (response_parser_type::http_status_done);
142
+
143
+ std::string valid_status_message = " OK\r\n Server: Foo" ;
144
+ logic::tribool parsed_ok;
145
+ range_type result_range;
146
+ fusion::tie (parsed_ok, result_range) = p.parse_until (
147
+ response_parser_type::http_status_message_done,
148
+ valid_status_message);
149
+ BOOST_CHECK_EQUAL (parsed_ok, true );
150
+ std::string parsed = std::string (boost::begin (result_range), boost::end (result_range));
151
+ std::cout << " PARSED: " << parsed << " state=" << p.state () << std::endl;
152
+ }
153
+
You can’t perform that action at this time.
0 commit comments