Skip to content

Commit f48c117

Browse files
committed
Fixed HTTP support
1 parent db2fcc3 commit f48c117

File tree

7 files changed

+35
-268
lines changed

7 files changed

+35
-268
lines changed

boost/network/uri.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
#include <boost/network/tags.hpp>
1010
#include <boost/network/traits/string.hpp>
1111
#include <boost/network/uri/basic_uri.hpp>
12-
// TODO, #include <boost/network/uri/http/uri.hpp>
12+
#include <boost/network/uri/http/uri.hpp>
1313

1414
namespace boost { namespace network { namespace uri {
1515

1616
typedef basic_uri<boost::network::tags::default_string> uri;
1717
typedef basic_uri<boost::network::tags::default_wstring> wuri;
1818

19-
/* TODO, namespace http {
19+
namespace http {
2020
typedef basic_uri<tags::http_default_8bit_tcp_resolve> uri;
21-
} */
21+
}
2222

2323
} // namespace uri
2424
} // namespace network

boost/network/uri/detail/parse_uri.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace boost { namespace network { namespace uri {
2323

2424
namespace detail {
2525

26-
template <class Range, class Tag>
27-
inline bool parse_specific(Range & range, uri_parts<Tag> & parts) {
26+
template <class Tag>
27+
inline bool parse_specific(uri_parts<Tag> & parts) {
2828
return true;
2929
}
3030

@@ -143,12 +143,11 @@ namespace boost { namespace network { namespace uri {
143143
result
144144
);
145145

146-
/* TODO, if (ok) {
146+
if (ok) {
147147
ok = parse_specific(
148-
parts.scheme_specific_part,
149148
parts
150149
);
151-
} */
150+
}
152151

153152
return ok && start_ == end_;
154153
}

boost/network/uri/http/detail/parse_specific.hpp

Lines changed: 9 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -7,122 +7,36 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include <boost/algorithm/string/predicate.hpp>
10-
#include <boost/network/uri/http/detail/uri_parts.hpp>
11-
#include <boost/network/uri/detail/parse_uri.hpp>
12-
#include <boost/network/traits/string.hpp>
1310

14-
#include <boost/spirit/include/qi_core.hpp>
15-
#include <boost/spirit/include/qi_sequence.hpp>
16-
#include <boost/spirit/include/qi_raw.hpp>
17-
#include <boost/spirit/include/qi_plus.hpp>
18-
#include <boost/spirit/include/qi_parse.hpp>
19-
#include <boost/spirit/include/qi_char_.hpp>
20-
#include <boost/spirit/include/qi_uint.hpp>
21-
#include <boost/spirit/include/qi_lexeme.hpp>
22-
#include <boost/spirit/include/qi_eps.hpp>
23-
#include <boost/spirit/include/qi_optional.hpp>
24-
#include <boost/spirit/include/phoenix_operator.hpp>
25-
#include <boost/spirit/include/support_ascii.hpp>
26-
#include <boost/spirit/include/support_argument.hpp>
11+
#include <boost/network/traits/string.hpp>
12+
#include <boost/network/uri/detail/parse_uri.hpp>
2713

2814
namespace boost { namespace network { namespace uri {
2915

3016
namespace detail {
3117

32-
template <class Tag>
33-
struct hostname {
34-
35-
typedef typename string<Tag>::type string_type;
36-
37-
template <class Iterator>
38-
struct parser : spirit::qi::grammar<Iterator, string_type()> {
39-
typedef spirit::qi::grammar<Iterator, string_type()> base_type;
40-
parser() : parser::base_type(start, "hostname") {
41-
using spirit::qi::eps;
42-
using spirit::qi::alnum;
43-
using spirit::qi::_val;
44-
using spirit::qi::_1;
45-
using spirit::qi::lexeme;
46-
using spirit::ascii::char_;
47-
start = eps [_val = ""]
48-
>> +(
49-
alnum[ _val += _1 ]
50-
| lexeme[char_('.') [ _val += '.' ] >> alnum [ _val += _1] ]
51-
| lexeme[char_('-') [ _val += '-' ] >> alnum [ _val += _1] ]
52-
);
53-
}
54-
55-
spirit::qi::rule<Iterator, string_type()> start;
56-
};
57-
};
58-
5918
template <>
6019
inline bool parse_specific<
61-
string<tags::http_default_8bit_tcp_resolve>::type,
6220
tags::http_default_8bit_tcp_resolve
6321
>(
64-
string<tags::http_default_8bit_tcp_resolve>::type & range,
6522
uri_parts<tags::http_default_8bit_tcp_resolve> & parts
6623
)
6724
{
68-
namespace qi = spirit::qi;
69-
70-
// Require that parts.scheme is either http or https, case insensitive
7125
if ((parts.scheme.size() < 4) || (parts.scheme.size() > 5))
7226
return false;
27+
7328
if (parts.scheme.size() == 4) {
74-
if (not boost::iequals(parts.scheme.substr(0, 4), "http"))
29+
if (not boost::iequals(parts.scheme, "http"))
7530
return false;
76-
} else { // size is 5
77-
if (not boost::iequals(parts.scheme.substr(0, 5), "https"))
31+
} else { // size is 5
32+
if (not boost::iequals(parts.scheme, "https"))
7833
return false;
7934
}
80-
81-
typedef string<tags::http_default_8bit_tcp_resolve>::type string_type;
82-
typedef range_iterator<string_type>::type iterator;
83-
84-
iterator start_ = begin(range);
85-
iterator end_ = end(range);
86-
fusion::tuple<
87-
optional<string_type> &,
88-
string_type &,
89-
optional<uint16_t> &,
90-
optional<string_type> &,
91-
optional<string_type> &,
92-
optional<string_type> &
93-
> result =
94-
fusion::tie(
95-
parts.user_info,
96-
parts.host,
97-
parts.port,
98-
parts.path,
99-
parts.query,
100-
parts.fragment
101-
);
10235

103-
qi::rule<iterator, string_type::value_type()> gen_delims = qi::char_(":/?#[]@");
104-
qi::rule<iterator, string_type::value_type()> sub_delims = qi::char_("!$&'()*+,;=");
105-
qi::rule<iterator, string_type::value_type()> reserved = gen_delims | sub_delims;
106-
qi::rule<iterator, string_type::value_type()> unreserved = qi::alnum | qi::char_("-._~");
107-
qi::rule<iterator, string_type()> pct_encoded = qi::raw[qi::char_("%") >> qi::repeat(2)[qi::xdigit]];
108-
qi::rule<iterator, string_type()> pchar = qi::raw[unreserved | pct_encoded | sub_delims | qi::char_(":@")];
109-
110-
hostname<tags::http_default_8bit_tcp_resolve>::parser<iterator> hostname;
111-
bool ok = parse(
112-
start_, end_,
113-
(
114-
qi::lit("//")
115-
>> -qi::lexeme[qi::raw[*(unreserved | pct_encoded | sub_delims | qi::char_(":"))] >> '@']
116-
>> hostname
117-
>> -qi::lexeme[':' >> qi::ushort_]
118-
>> -qi::lexeme['/' >> qi::raw[*pchar >> *('/' >> *pchar)]]
119-
>> -qi::lexeme['?' >> qi::raw[*(pchar | qi::char_("/?"))]]
120-
>> -qi::lexeme['#' >> qi::raw[*(pchar | qi::char_("/?"))]]
121-
),
122-
result
123-
);
36+
if ((not parts.host) || parts.host->empty())
37+
return false;
12438

125-
return ok && start_ == end_;
39+
return true;
12640
}
12741

12842
} // namespace detail

boost/network/uri/http/detail/uri_parts.hpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

boost/network/uri/http/uri.hpp

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <boost/fusion/tuple.hpp>
9+
#include <boost/cstdint.hpp>
10+
#include <boost/algorithm/string/predicate.hpp>
1011

1112
#include <boost/network/tags.hpp>
12-
#include <boost/network/uri/basic_uri_fwd.hpp>
1313
#include <boost/network/traits/string.hpp>
14+
#include <boost/network/uri/basic_uri_fwd.hpp>
1415
#include <boost/network/uri/http/detail/parse_specific.hpp>
15-
#include <boost/network/uri/http/detail/uri_parts.hpp>
16-
#include <boost/network/uri/http/uri_concept.hpp>
17-
#include <boost/algorithm/string/predicate.hpp>
1816

1917
namespace boost { namespace network { namespace uri {
2018

@@ -27,71 +25,18 @@ namespace boost { namespace network { namespace uri {
2725
basic_uri() : uri_base<tags::http_default_8bit_tcp_resolve>() {}
2826
basic_uri(uri_base<tags::http_default_8bit_tcp_resolve>::string_type const & uri) : uri_base<tags::http_default_8bit_tcp_resolve>(uri) {}
2927

30-
string_type host() const {
31-
return parts_.host;
32-
}
33-
34-
uint32_t port() const {
28+
boost::uint32_t port() const {
3529
return parts_.port ? *(parts_.port) :
3630
(boost::iequals(parts_.scheme, string_type("https")) ? 443u : 80u);
3731
}
38-
39-
string_type path() const {
40-
return string_type("/") + (parts_.path ? *parts_.path : string_type());
41-
}
42-
43-
string_type query() const {
44-
return parts_.query ? *parts_.query : string_type();
45-
}
46-
47-
string_type fragment() const {
48-
return parts_.fragment ? *parts_.fragment : string_type();
49-
}
50-
51-
string_type user_info() const {
52-
return parts_.user_info ? *parts_.user_info : string_type();
53-
}
54-
5532
};
5633

57-
inline
58-
basic_uri<tags::http_default_8bit_tcp_resolve>::string_type
59-
host(basic_uri<tags::http_default_8bit_tcp_resolve> const & uri) {
60-
return uri.host();
61-
}
62-
6334
inline
64-
uint32_t
35+
boost::uint32_t
6536
port(basic_uri<tags::http_default_8bit_tcp_resolve> const & uri) {
6637
return uri.port();
6738
}
6839

69-
inline
70-
basic_uri<tags::http_default_8bit_tcp_resolve>::string_type
71-
path(basic_uri<tags::http_default_8bit_tcp_resolve> const & uri) {
72-
return uri.path();
73-
}
74-
75-
inline
76-
basic_uri<tags::http_default_8bit_tcp_resolve>::string_type
77-
query(basic_uri<tags::http_default_8bit_tcp_resolve> const & uri) {
78-
return uri.query();
79-
}
80-
81-
inline
82-
basic_uri<tags::http_default_8bit_tcp_resolve>::string_type
83-
fragment(basic_uri<tags::http_default_8bit_tcp_resolve> const & uri) {
84-
return uri.fragment();
85-
}
86-
87-
inline
88-
basic_uri<tags::http_default_8bit_tcp_resolve>::string_type
89-
user_info(basic_uri<tags::http_default_8bit_tcp_resolve> const & uri) {
90-
return uri.user_info();
91-
}
92-
93-
BOOST_CONCEPT_ASSERT((HttpURI<basic_uri<tags::http_default_8bit_tcp_resolve> >));
94-
9540
} // namespace uri
9641

9742
} // namespace network

boost/network/uri/http/uri_concept.hpp

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)