1
1
#ifndef BOOST_NETWORK_URL_HTTP_DETAIL_PARSE_SPECIFIC_HPP_
2
2
#define BOOST_NETWORK_URL_HTTP_DETAIL_PARSE_SPECIFIC_HPP_
3
3
4
- // Copyright 2009 Dean Michael Berris.
4
+ // Copyright 2009 Dean Michael Berris, Jeroen Habraken .
5
5
// Distributed under the Boost Software License, Version 1.0.
6
6
// (See accompanying file LICENSE_1_0.txt of copy at
7
7
// http://www.boost.org/LICENSE_1_0.txt)
8
8
9
+ #include < boost/algorithm/string/case_conv.hpp>
10
+
9
11
#include < boost/network/uri/http/detail/uri_parts.hpp>
10
12
#include < boost/network/uri/detail/parse_uri.hpp>
11
- #include < boost/network/uri/detail/constants.hpp>
12
13
#include < boost/network/traits/string.hpp>
13
14
14
15
namespace boost { namespace network { namespace uri {
@@ -51,6 +52,12 @@ namespace boost { namespace network { namespace uri {
51
52
uri_parts<tags::http> & parts
52
53
)
53
54
{
55
+ namespace qi = spirit::qi;
56
+
57
+ // For resiliency, programs interpreting URI should treat upper
58
+ // case letters as equivalent to lower case in scheme names
59
+ boost::to_lower (parts.scheme );
60
+
54
61
// Require that parts.scheme is either http or https
55
62
if (parts.scheme .size () < 4 )
56
63
return false ;
@@ -62,17 +69,6 @@ namespace boost { namespace network { namespace uri {
62
69
} else if (parts.scheme .size () > 5 )
63
70
return false ;
64
71
65
- using spirit::qi::parse;
66
- using spirit::qi::lit;
67
- using spirit::ascii::char_;
68
- using spirit::ascii::space;
69
- using spirit::ascii::alnum;
70
- using spirit::ascii::punct;
71
- using spirit::qi::lexeme;
72
- using spirit::qi::uint_;
73
- using spirit::qi::digit;
74
- using spirit::qi::rule;
75
-
76
72
typedef string<tags::http>::type string_type;
77
73
typedef range_iterator<string_type>::type iterator;
78
74
@@ -81,7 +77,7 @@ namespace boost { namespace network { namespace uri {
81
77
fusion::tuple<
82
78
optional<string_type> &,
83
79
string_type &,
84
- optional<uint32_t > &,
80
+ optional<uint16_t > &,
85
81
optional<string_type> &,
86
82
optional<string_type> &,
87
83
optional<string_type> &
@@ -95,20 +91,24 @@ namespace boost { namespace network { namespace uri {
95
91
parts.fragment
96
92
);
97
93
94
+ qi::rule<iterator, string_type::value_type ()> reserved = qi::char_ (" ;/?:@&=+$," );
95
+ qi::rule<iterator, string_type::value_type ()> unreserved = qi::alnum | qi::char_ (" -_.!~*'()" );
96
+ qi::rule<iterator, string_type ()> escaped = qi::char_ (" %" ) > qi::repeat (2 )[qi::xdigit];
97
+
98
98
hostname<tags::http>::parser<iterator> hostname;
99
- bool ok = parse (
99
+ bool ok = qi:: parse (
100
100
start_, end_,
101
101
(
102
- lit (" //" )
103
- >> -lexeme[
104
- *((alnum| punct) - ' @' )
102
+ qi:: lit (" //" )
103
+ >> -qi:: lexeme[
104
+ *((qi:: alnum | qi:: punct) - ' @' )
105
105
>> ' @'
106
106
]
107
107
>> hostname
108
- >> -lexeme[' :' >> uint_ ]
109
- >> -lexeme[' /' >> *((alnum| punct) - ' ?' )]
110
- >> -lexeme[' ?' >> *((alnum|punct) - ' # ' ) ]
111
- >> -lexeme[' #' >> *(alnum|punct) ]
108
+ >> -qi:: lexeme[' :' >> qi::ushort_ ]
109
+ >> -qi:: lexeme[' /' >> *((qi:: alnum | qi:: punct) - ' ?' )]
110
+ >> -qi:: lexeme[' ?' >> qi::raw[*(reserved | unreserved | escaped)] ]
111
+ >> -qi:: lexeme[' #' >> qi::raw[*(reserved | unreserved | escaped)] ]
112
112
),
113
113
result
114
114
);
0 commit comments