11#ifndef BOOST_NETWORK_URL_HTTP_DETAIL_PARSE_SPECIFIC_HPP_
22#define BOOST_NETWORK_URL_HTTP_DETAIL_PARSE_SPECIFIC_HPP_
33
4- // Copyright 2009 Dean Michael Berris.
4+ // Copyright 2009 Dean Michael Berris, Jeroen Habraken .
55// Distributed under the Boost Software License, Version 1.0.
66// (See accompanying file LICENSE_1_0.txt of copy at
77// http://www.boost.org/LICENSE_1_0.txt)
88
9+ #include < boost/algorithm/string/predicate.hpp>
910#include < boost/network/uri/http/detail/uri_parts.hpp>
1011#include < boost/network/uri/detail/parse_uri.hpp>
11- #include < boost/network/uri/detail/constants.hpp>
1212#include < boost/network/traits/string.hpp>
1313
1414namespace boost {namespace network {namespace uri {
@@ -51,27 +51,18 @@ namespace boost { namespace network { namespace uri {
5151 uri_parts<tags::http> & parts
5252 )
5353 {
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 )
5858return 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 " ) )
6161return 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+ }
7566
7667typedef string<tags::http>::type string_type;
7768typedef range_iterator<string_type>::type iterator;
@@ -81,7 +72,7 @@ namespace boost { namespace network { namespace uri {
8172 fusion::tuple<
8273 optional<string_type> &,
8374 string_type &,
84- optional<uint32_t > &,
75+ optional<uint16_t > &,
8576 optional<string_type> &,
8677 optional<string_type> &,
8778 optional<string_type> &
@@ -95,20 +86,26 @@ namespace boost { namespace network { namespace uri {
9586 parts.fragment
9687 );
9788
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+
9898 hostname<tags::http>::parser<iterator> hostname;
99- bool ok =parse (
99+ bool ok =qi:: parse (
100100 start_, end_,
101101 (
102- lit (" //" )
103- >> -lexeme[
104- *((alnum|punct) -' @' )
105- >>' @'
106- ]
102+ qi::lit (" //" )
103+ >> -qi::lexeme[qi::raw[*(unreserved | pct_encoded | sub_delims |qi::char_ (" :" ))] >>' @' ]
107104 >> 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_ ( " /? " ))] ]
112109 ),
113110 result
114111 );