|
| 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 | +#defineBOOST_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 | +namespaceboost { |
| 15 | +namespacespirit { |
| 16 | +namespacetraits { |
| 17 | + |
| 18 | +typedef std::basic_string<uint32_t> u32_string; |
| 19 | + |
| 20 | +template<>// <typename Attrib, typename T, typename Enable> |
| 21 | +structassign_to_container_from_value<std::string, u32_string,void> { |
| 22 | +staticvoidcall(u32_stringconst& 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 | +namespaceboost { |
| 34 | +namespacenetwork { |
| 35 | +namespacehttp { |
| 36 | + |
| 37 | +voidparse_version( |
| 38 | + std::stringconst& partial_parsed, |
| 39 | + std::tuple<std::uint8_t, std::uint8_t>& version_pair) { |
| 40 | +usingnamespaceboost::spirit::qi; |
| 41 | +parse(partial_parsed.begin(), partial_parsed.end(), |
| 42 | + (lit("HTTP/") >> ushort_ >>'.' >> ushort_), version_pair); |
| 43 | +} |
| 44 | + |
| 45 | +voidparse_headers( |
| 46 | + std::stringconst& input, std::vector<request_header_narrow>& container) { |
| 47 | +usingnamespaceboost::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 |