Skip to content

Commit 2738ad0

Browse files
author
Dean Michael Berris
committed
Initial support for using Boost.String_algorithms predicates.
1 parent 0faa40c commit 2738ad0

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

boost/network/protocol/http/parser/incremental.hpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <boost/fusion/tuple.hpp>
1212
#include <boost/network/traits/string.hpp>
1313
#include <boost/logic/tribool.hpp>
14+
#include <boost/algorithm/string/classification.hpp>
1415
#include <utility>
1516

1617
namespace boost { namespace network { namespace http {
@@ -28,7 +29,9 @@ namespace boost { namespace network { namespace http {
2829
http_version_major,
2930
http_version_dot,
3031
http_version_minor,
31-
http_version_done
32+
http_version_done,
33+
http_status_digit,
34+
http_status_done
3235
};
3336

3437
typedef typename string<Tag>::type::const_iterator iterator_type;
@@ -141,6 +144,26 @@ namespace boost { namespace network { namespace http {
141144
parsed_ok = false;
142145
}
143146
break;
147+
case http_version_done:
148+
// FIXME find a better way to use is_digit
149+
if (algorithm::is_digit()(*current)) {
150+
state_ = http_status_digit;
151+
++current;
152+
} else {
153+
parsed_ok = false;
154+
}
155+
break;
156+
case http_status_digit:
157+
// FIXME find a better way to use is_digit
158+
if (algorithm::is_digit()(*current)) {
159+
++current;
160+
} else if (*current == ' ') {
161+
state_ = http_status_done;
162+
++current;
163+
} else {
164+
parsed_ok = false;
165+
}
166+
break;
144167
default:
145168
parsed_ok = false;
146169
}

libs/network/test/http_incremental_parser.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ BOOST_AUTO_TEST_CASE(incremental_parser_parse_status) {
116116
response_parser_type::http_status_done,
117117
valid_status);
118118
BOOST_CHECK_EQUAL(parsed_ok, true);
119+
std::string parsed = std::string(boost::begin(result_range), boost::end(result_range));
120+
std::cout << "PARSED: " << parsed << " state=" << p.state() << std::endl;
121+
122+
p.reset(response_parser_type::http_version_done);
123+
std::string invalid_status = "200x ";
124+
fusion::tie(parsed_ok, result_range) = p.parse_until(
125+
response_parser_type::http_status_done,
126+
invalid_status);
127+
BOOST_CHECK_EQUAL(parsed_ok, false);
119128
parsed = std::string(boost::begin(result_range), boost::end(result_range));
120129
std::cout << "PARSED: " << parsed << " state=" << p.state() << std::endl;
121130
}

0 commit comments

Comments
 (0)