|
| 1 | +// Copyright 2013 Google, Inc. |
1 | 2 | // Copyright 2010 Dean Michael Berris.
|
2 | 3 | // Distributed under the Boost Software License, Version 1.0.
|
3 | 4 | // (See accompanying file LICENSE_1_0.txt or copy at
|
4 | 5 | // http://www.boost.org/LICENSE_1_0.txt)
|
5 | 6 |
|
6 |
| -#ifdef BOOST_NETWORK_NO_LIB |
7 |
| -#undef BOOST_NETWORK_NO_LIB |
8 |
| -#endif |
| 7 | +#include <tuple> |
| 8 | +#include <vector> |
| 9 | +#define BOOST_SPIRIT_UNICODE |
| 10 | +#include <boost/spirit/include/qi.hpp> |
| 11 | +#include <boost/fusion/include/std_tuple.hpp> |
| 12 | +#include <boost/network/protocol/http/message/header.hpp> |
9 | 13 |
|
10 |
| -#include <boost/network/protocol/http/server/impl/parsers.ipp> |
| 14 | +namespace boost { |
| 15 | +namespace spirit { |
| 16 | +namespace traits { |
| 17 | + |
| 18 | +typedef std::basic_string<uint32_t> u32_string; |
| 19 | + |
| 20 | +template <> // <typename Attrib, typename T, typename Enable> |
| 21 | +struct assign_to_container_from_value<std::string, u32_string, void> { |
| 22 | + static void call(u32_string const& val, std::string& attr) { |
| 23 | + u32_to_u8_iterator<u32_string::const_iterator> begin = val.begin(), |
| 24 | + end = val.end(); |
| 25 | + for (; begin != end; ++begin) attr += *begin; |
| 26 | + } |
| 27 | +}; |
| 28 | + |
| 29 | +} // namespace traits |
| 30 | +} // namespace spirit |
| 31 | +} // namespace boost |
| 32 | + |
| 33 | +namespace boost { |
| 34 | +namespace network { |
| 35 | +namespace http { |
| 36 | + |
| 37 | +void parse_version( |
| 38 | + std::string const& partial_parsed, |
| 39 | + std::tuple<std::uint8_t, std::uint8_t>& version_pair) { |
| 40 | + using namespace boost::spirit::qi; |
| 41 | + parse(partial_parsed.begin(), partial_parsed.end(), |
| 42 | + (lit("HTTP/") >> ushort_ >> '.' >> ushort_), version_pair); |
| 43 | +} |
| 44 | + |
| 45 | +void parse_headers( |
| 46 | + std::string const& input, std::vector<request_header_narrow>& container) { |
| 47 | + using namespace boost::spirit::qi; |
| 48 | + u8_to_u32_iterator<std::string::const_iterator> begin = input.begin(), |
| 49 | + end = input.end(); |
| 50 | + typedef as<boost::spirit::traits::u32_string> as_u32_string; |
| 51 | + parse(begin, end, |
| 52 | + *(+((alnum | punct) - ':') >> lit(": ") >> |
| 53 | + as_u32_string()[+((unicode::alnum | space | punct) - '\r' - '\n')] >> |
| 54 | + lit("\r\n")) >> |
| 55 | + lit("\r\n"), |
| 56 | + container); |
| 57 | +} |
| 58 | + |
| 59 | +} // namespace http |
| 60 | +} // namespace network |
| 61 | +} // namespace boost |
0 commit comments