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/predicate.hpp>
9
10
#include < boost/network/uri/http/detail/uri_parts.hpp>
10
11
#include < boost/network/uri/detail/parse_uri.hpp>
11
- #include < boost/network/uri/detail/constants.hpp>
12
12
#include < boost/network/traits/string.hpp>
13
13
14
14
namespace boost { namespace network { namespace uri {
@@ -51,27 +51,18 @@ namespace boost { namespace network { namespace uri {
51
51
uri_parts<tags::http> & parts
52
52
)
53
53
{
54
- // Require that parts.scheme is either http or https
55
- if (parts. scheme . size () < 4 )
56
- return false ;
57
- if (parts.scheme .substr ( 0 , 4 ) != " http " )
54
+ namespace qi = spirit::qi;
55
+
56
+ // Require that parts.scheme is either http or https, case insensitive
57
+ if (parts.scheme .size () < 4 or parts. scheme . size () > 5 )
58
58
return false ;
59
- if (parts.scheme .size () == 5 ) {
60
- if (parts.scheme [ 4 ] != ' s ' )
59
+ if (parts.scheme .size () == 4 ) {
60
+ if (not boost::iequals ( parts.scheme . substr ( 0 , 4 ), " http " ) )
61
61
return false ;
62
- } else if (parts.scheme .size () > 5 )
63
- return false ;
64
-
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;
62
+ } else { // size is 5
63
+ if (not boost::iequals (parts.scheme .substr (0 , 5 ), " https" ))
64
+ return false ;
65
+ }
75
66
76
67
typedef string<tags::http>::type string_type;
77
68
typedef range_iterator<string_type>::type iterator;
@@ -81,7 +72,7 @@ namespace boost { namespace network { namespace uri {
81
72
fusion::tuple<
82
73
optional<string_type> &,
83
74
string_type &,
84
- optional<uint32_t > &,
75
+ optional<uint16_t > &,
85
76
optional<string_type> &,
86
77
optional<string_type> &,
87
78
optional<string_type> &
@@ -95,20 +86,26 @@ namespace boost { namespace network { namespace uri {
95
86
parts.fragment
96
87
);
97
88
89
+ qi::rule<iterator, string_type::value_type ()> gen_delims = qi::char_ (" :/?#[]@" );
90
+ qi::rule<iterator, string_type::value_type ()> sub_delims = qi::char_ (" !$&'()*+,;=" );
91
+
92
+ qi::rule<iterator, string_type::value_type ()> reserved = gen_delims | sub_delims;
93
+ qi::rule<iterator, string_type::value_type ()> unreserved = qi::alnum | qi::char_ (" -._~" );
94
+ qi::rule<iterator, string_type ()> pct_encoded = qi::char_ (" %" ) > qi::repeat (2 )[qi::xdigit];
95
+
96
+ qi::rule<iterator, string_type ()> pchar = qi::raw[unreserved | pct_encoded | sub_delims | qi::char_ (" :@" )];
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) - ' @' )
105
- >> ' @'
106
- ]
102
+ qi::lit (" //" )
103
+ >> -qi::lexeme[qi::raw[*(unreserved | pct_encoded | sub_delims | qi::char_ (" :" ))] >> ' @' ]
107
104
>> hostname
108
- >> -lexeme[' :' >> uint_ ]
109
- >> -lexeme[' /' >> *((alnum|punct) - ' ? ' ) ]
110
- >> -lexeme[' ?' >> *((alnum|punct) - ' # ' ) ]
111
- >> -lexeme[' #' >> *(alnum|punct) ]
105
+ >> -qi:: lexeme[' :' >> qi::ushort_ ]
106
+ >> -qi:: lexeme[' /' > qi::raw[*pchar >> *( ' / ' > *pchar)] ]
107
+ >> -qi:: lexeme[' ?' >> qi::raw[*(pchar | qi::char_ ( " /? " ))] ]
108
+ >> -qi:: lexeme[' #' >> qi::raw[*(pchar | qi::char_ ( " /? " ))] ]
112
109
),
113
110
result
114
111
);
0 commit comments