Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5bc6c29

Browse files
committed
Updated some tests and examples that use the HTTP URI.
Conflicts:libs/network/test/xmpp/xmpp_client_tests.cpp
1 parentadd64a9 commit5bc6c29

File tree

9 files changed

+119
-112
lines changed

9 files changed

+119
-112
lines changed

‎boost/network/protocol/http/impl/request.hpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include<boost/fusion/sequence/intrinsic/at_key.hpp>
1616
#include<boost/fusion/sequence/intrinsic/value_at_key.hpp>
1717

18-
#include<boost/network/uri.hpp>
18+
#include<boost/network/uri/http/uri.hpp>
1919
#include<boost/network/traits/vector.hpp>
2020

2121
#include<boost/network/protocol/http/message/async_message.hpp>
@@ -50,7 +50,7 @@ namespace http {
5050
structbasic_request :publicbasic_message<Tag>
5151
{
5252

53-
mutable boost::network::uri::http::uri uri_;
53+
mutable boost::network::uri::http::basic_uri<Tag> uri_;
5454
typedef basic_message<Tag> base_type;
5555

5656
public:
@@ -115,7 +115,7 @@ namespace http {
115115
uri_ = new_uri;
116116
}
117117

118-
boost::network::uri::http::uriconsturi()const {
118+
boost::network::uri::http::basic_uri<Tag>const &uri()const {
119119
return uri_;
120120
}
121121

‎boost/network/uri.hpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88

99
#include<boost/network/traits/string.hpp>
1010
#include<boost/network/uri/uri.hpp>
11+
#include<boost/network/protocol/http/tags.hpp>
1112
#include<boost/network/uri/http/uri.hpp>
1213

1314

1415
namespaceboost {namespacenetwork {namespaceuri {
1516

1617
typedef basic_uri<boost::network::tags::default_string> uri;
1718
typedef basic_uri<boost::network::tags::default_wstring> wuri;
18-
//
19-
//namespace http {
20-
//typedef basic_uri<boost::network::http::tags::http_default_8bit_tcp_resolve> uri;
21-
//}
22-
//
19+
20+
namespacehttp {
21+
typedef basic_uri<boost::network::http::tags::http_default_8bit_udp_resolve> uri;
22+
}
23+
2324
}// namespace uri
2425
}// namespace network
2526
}// namespace boost

‎boost/network/uri/detail/parse_uri.hpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,17 @@ struct uri_grammar : qi::grammar<Iterator, detail::uri_parts<String>()> {
112112
>> qi::raw[
113113
qi::uint_parser<boost::uint8_t,10,1,3>()
114114
];
115+
115116
// IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
116117
ipv4address %= qi::raw[
117118
dec_octet >>qi::repeat(3)[qi::lit('.') >> dec_octet]
118119
];
120+
119121
// reg-name = *( unreserved / pct-encoded / sub-delims )
120122
reg_name %= qi::raw[
121123
*(unreserved | pct_encoded | sub_delims)
122124
];
125+
123126
// TODO, host = IP-literal / IPv4address / reg-name
124127
host %=
125128
iter_pos
@@ -140,6 +143,7 @@ struct uri_grammar : qi::grammar<Iterator, detail::uri_parts<String>()> {
140143
>> qi::omit[qi::raw[*(pchar |qi::char_("/?"))]]
141144
>> iter_pos
142145
;
146+
143147
// fragment = *( pchar / "/" / "?" )
144148
fragment %=
145149
iter_pos

‎boost/network/uri/http/uri.hpp‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,52 @@ class basic_uri
3333
}
3434

3535
};
36+
}// namespace http
3637

38+
template<
39+
classTag
40+
>
41+
boolis_http(const http::basic_uri<Tag> &uri) {
42+
staticconstchar scheme_http[] = {'h','t','t','p'};
43+
returnboost::equal(uri.scheme_range(), scheme_http);
44+
}
45+
46+
template<
47+
classTag
48+
>
49+
boolis_https(const http::basic_uri<Tag> &uri) {
50+
staticconstchar scheme_https[] = {'h','t','t','p','s'};
51+
returnboost::equal(uri.scheme_range(), scheme_https);
52+
}
53+
54+
template<
55+
classTag
56+
>
57+
inline
58+
boolis_valid(const http::basic_uri<Tag> &uri) {
59+
returnis_http(uri) ||is_https(uri);
60+
}
3761

3862
template<
3963
classTag
4064
>
4165
inline
42-
typename basic_uri<Tag>::string_typeport(const basic_uri<Tag> &uri) {
66+
typename basic_uri<Tag>::string_typeport(consthttp::basic_uri<Tag> &uri) {
4367
typedeftypename basic_uri<Tag>::range_type range_type;
4468
typedeftypename basic_uri<Tag>::string_type string_type;
4569

4670
staticconstchar default_http_port[] ="80";
4771
staticconstchar default_https_port[] ="443";
4872

73+
range_type scheme = uri.scheme_range();
4974
range_type port = uri.port_range();
50-
string_type scheme = uri.scheme();
5175

5276
if (boost::empty(port)) {
53-
if (scheme =="http") {
77+
if (is_http(uri)) {
5478
returnstring_type(boost::begin(default_http_port),
5579
boost::end(default_http_port));
5680
}
57-
elseif (scheme =="https") {
81+
elseif (is_https(uri)) {
5882
returnstring_type(boost::begin(default_https_port),
5983
boost::end(default_https_port));
6084
}
@@ -63,7 +87,6 @@ typename basic_uri<Tag>::string_type port(const basic_uri<Tag> &uri) {
6387
}
6488

6589
typedef basic_uri<tags::default_string> uri;
66-
}// namespace http
6790
}// namespace uri
6891
}// namespace network
6992
}// namespace boost

‎boost/network/uri/uri.hpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ typename basic_uri<Tag>::string_type fragment(const basic_uri<Tag> &uri) {
334334
return uri.fragment();
335335
}
336336

337+
template<
338+
classTag
339+
>
340+
inline
341+
typename basic_uri<Tag>::string_typeauthority(const basic_uri<Tag> &uri) {
342+
typename basic_uri<Tag>::const_range_typeuser_info(uri.user_info_range());
343+
typename basic_uri<Tag>::const_range_typeport(uri.port_range());
344+
returntypename basic_uri<Tag>::string_type(user_info.begin(), port.end());
345+
}
346+
337347
template<
338348
classTag
339349
>

‎libs/network/example/simple_wget.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
#include<boost/network/protocol/http/client.hpp>
18-
#include<boost/network/uri/http/uri.hpp>
18+
#include<boost/network/uri.hpp>
1919
#include<string>
2020
#include<fstream>
2121
#include<iostream>

‎libs/network/example/uri.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
This is a simple program that validates a URI.
1111
*/
1212
#include<boost/network/uri.hpp>
13-
#include<boost/network/uri/http/uri.hpp>
1413
#include<string>
1514
#include<iostream>
1615

‎libs/network/test/uri/url_http_test.cpp‎

Lines changed: 33 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66

7-
87
#defineBOOST_TEST_MODULE HTTP URL Test
98
#include<boost/config/warning_disable.hpp>
109
#include<boost/test/unit_test.hpp>
@@ -20,84 +19,43 @@ typedef boost::mpl::list<
2019
> tag_types;
2120

2221

22+
BOOST_AUTO_TEST_CASE_TEMPLATE(valid_http, T, tag_types)
23+
{
24+
typedef uri::http::basic_uri<T> uri_type;
25+
typedeftypename uri_type::string_type string_type;
26+
const std::stringurl("http://example.com/");
27+
uri_typeinstance(string_type(boost::begin(url),boost::end(url)));
28+
BOOST_REQUIRE(uri::is_http(instance));
29+
BOOST_REQUIRE(uri::is_valid(instance));
30+
}
31+
32+
BOOST_AUTO_TEST_CASE_TEMPLATE(valid_https, T, tag_types)
33+
{
34+
typedef uri::http::basic_uri<T> uri_type;
35+
typedeftypename uri_type::string_type string_type;
36+
const std::stringurl("https://example.com/");
37+
uri_typeinstance(string_type(boost::begin(url),boost::end(url)));
38+
BOOST_REQUIRE(uri::is_https(instance));
39+
BOOST_REQUIRE(uri::is_valid(instance));
40+
}
41+
42+
BOOST_AUTO_TEST_CASE_TEMPLATE(invalid_https, T, tag_types)
43+
{
44+
typedef uri::http::basic_uri<T> uri_type;
45+
typedeftypename uri_type::string_type string_type;
46+
const std::stringurl("http://example.com/");
47+
uri_typeinstance(string_type(boost::begin(url),boost::end(url)));
48+
BOOST_REQUIRE(!uri::is_https(instance));
49+
BOOST_REQUIRE(uri::is_valid(instance));
50+
}
51+
2352
BOOST_AUTO_TEST_CASE_TEMPLATE(not_http, T, tag_types)
2453
{
2554
typedef uri::http::basic_uri<T> uri_type;
2655
typedeftypename uri_type::string_type string_type;
2756
const std::stringurl("mailto:john.doe@example.com");
2857
uri_typeinstance(string_type(boost::begin(url),boost::end(url)));
29-
//BOOST_CHECK(!uri::is_valid(instance));
58+
BOOST_REQUIRE(!uri::is_http(instance));
59+
BOOST_REQUIRE(!uri::is_https(instance));
60+
BOOST_REQUIRE(!uri::is_valid(instance));
3061
}
31-
32-
// BOOST_AUTO_TEST_CASE(http_url_test) {
33-
// typedef uri::basic_uri<http::tags::http_default_8bit_tcp_resolve> uri_type;
34-
// typedef uri_type::string_type string_type;
35-
//
36-
// const std::string url("http://www.boost.org/");
37-
// const std::string scheme("http");
38-
// const std::string host("www.boost.org");
39-
// const std::string path("/");
40-
//
41-
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
42-
// boost::optional<string_type> host_ = uri::host(instance);
43-
// boost::optional<boost::uint16_t> port_ = uri::port(instance);
44-
//
45-
// BOOST_REQUIRE(uri::is_valid(instance));
46-
// BOOST_CHECK_EQUAL(instance.raw(), url);
47-
// BOOST_CHECK( !port_ );
48-
// string_type scheme_ = uri::scheme(instance);
49-
// BOOST_CHECK_EQUAL(scheme_, scheme);
50-
// BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
51-
// BOOST_CHECK(boost::equal(uri::host(instance), host));
52-
// BOOST_CHECK(boost::equal(uri::path(instance), path));
53-
// }
54-
//
55-
// BOOST_AUTO_TEST_CASE(full_http_url_test) {
56-
// typedef uri::basic_uri<http::tags::http_default_8bit_tcp_resolve> uri_type;
57-
// typedef uri_type::string_type string_type;
58-
//
59-
// const std::string url("http://user:password@www.boost.org:8000/path?query#fragment");
60-
// const std::string scheme("http");
61-
// const std::string user_info("user:password");
62-
// const std::string host("www.boost.org");
63-
// const boost::uint16_t port = 8000;
64-
// const std::string path("/path");
65-
// const std::string query("query");
66-
// const std::string fragment("fragment");
67-
//
68-
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
69-
// BOOST_REQUIRE(uri::is_valid(instance));
70-
// BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
71-
// BOOST_CHECK(boost::equal(uri::user_info(instance), user_info));
72-
// BOOST_CHECK(boost::equal(uri::host(instance), host));
73-
// BOOST_CHECK_EQUAL(uri::port(instance), port);
74-
// BOOST_CHECK(boost::equal(uri::path(instance), path));
75-
// BOOST_CHECK(boost::equal(uri::query(instance), query));
76-
// BOOST_CHECK(boost::equal(uri::fragment(instance), fragment));
77-
// }
78-
//
79-
// BOOST_AUTO_TEST_CASE(https_url_test) {
80-
// typedef uri::basic_uri<http::tags::http_default_8bit_tcp_resolve> uri_type;
81-
// typedef uri_type::string_type string_type;
82-
//
83-
// const std::string url("https://www.boost.org/");
84-
// const std::string scheme("https");
85-
// const std::string host("www.boost.org");
86-
// const boost::uint16_t port = 443;
87-
// const std::string path("/");
88-
//
89-
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
90-
// BOOST_REQUIRE(uri::is_valid(instance));
91-
// BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
92-
// BOOST_CHECK(boost::equal(uri::host(instance), host));
93-
// BOOST_CHECK_EQUAL(uri::port(instance), port);
94-
// BOOST_CHECK(boost::equal(uri::path(instance), path));
95-
// }
96-
//
97-
//BOOST_AUTO_TEST_CASE(invalid_http_url_test) {
98-
// typedef uri::basic_uri<http::tags::http_default_8bit_tcp_resolve> uri_type;
99-
// typedef uri_type::string_type string_type;
100-
// const std::string url("ftp://www.boost.org/");
101-
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
102-
// BOOST_CHECK(!uri::is_valid(instance));
103-
//}

‎libs/network/test/uri/url_test.cpp‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include<boost/network/tags.hpp>
1111
#include<boost/mpl/list.hpp>
1212
#include<boost/range/algorithm/equal.hpp>
13+
#include<boost/filesystem/path.hpp>
1314

1415
usingnamespaceboost::network;
1516

@@ -43,7 +44,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(full_uri_test, T, tag_types) {
4344
const std::stringscheme("http");
4445
const std::stringuser_info("user:password");
4546
const std::stringhost("www.boost.org");
46-
// boost::uint16_t port = 8000;
4747
const std::string port ="8000";
4848
const std::stringpath("/path");
4949
const std::stringquery("query");
@@ -106,29 +106,29 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ipv4_address_test, T, tag_types) {
106106
BOOST_CHECK(boost::equal(uri::path(instance), path));
107107
}
108108

109-
// IPv6 is not yet supported by the parser
110-
//BOOST_AUTO_TEST_CASE_TEMPLATE(ipv6_address_test, T, tag_types) {
111-
//typedef uri::basic_uri<T> uri_type;
112-
//typedef typename uri_type::string_type string_type;
109+
//// IPv6 is not yet supported by the parser
110+
//BOOST_AUTO_TEST_CASE_TEMPLATE(ipv6_address_test, T, tag_types) {
111+
// typedef uri::basic_uri<T> uri_type;
112+
// typedef typename uri_type::string_type string_type;
113113
//
114-
//const std::string url("http://1080:0:0:0:8:800:200C:417A/");
115-
//const std::string scheme("http");
116-
//const std::string host("1080:0:0:8:800:200C:417A");
117-
//const std::string path("/");
114+
// const std::string url("http://1080:0:0:0:8:800:200C:417A/");
115+
// const std::string scheme("http");
116+
// const std::string host("1080:0:0:8:800:200C:417A");
117+
// const std::string path("/");
118118
//
119-
//uri_type instance(string_type(boost::begin(url), boost::end(url)));
120-
// BOOST_REQUIRE(uri::is_valid(instance));
121-
//std::cout << uri::scheme(instance) << std::endl;
122-
//std::cout << uri::user_info(instance) << std::endl;
123-
//std::cout << uri::host(instance) << std::endl;
124-
//std::cout << uri::port(instance) << std::endl;
125-
//std::cout << uri::path(instance) << std::endl;
126-
//std::cout << uri::query(instance) << std::endl;
127-
// std::cout <<uri::fragment(instance) << std::endl;
128-
//BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
129-
//BOOST_CHECK(boost::equal(uri::host(instance), host));
130-
//BOOST_CHECK(boost::equal(uri::path(instance), path));
131-
//}
119+
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
120+
//std::cout <<uri::scheme(instance) << std::endl;
121+
// std::cout << uri::user_info(instance) << std::endl;
122+
// std::cout << uri::host(instance) << std::endl;
123+
// std::cout << uri::port(instance) << std::endl;
124+
// std::cout << uri::path(instance) << std::endl;
125+
// std::cout << uri::query(instance) << std::endl;
126+
// std::cout << uri::fragment(instance) << std::endl;
127+
//BOOST_REQUIRE(uri::is_valid(instance));
128+
// BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
129+
// BOOST_CHECK(boost::equal(uri::host(instance), host));
130+
// BOOST_CHECK(boost::equal(uri::path(instance), path));
131+
//}
132132

133133
BOOST_AUTO_TEST_CASE_TEMPLATE(ftp_test, T, tag_types) {
134134
typedef uri::basic_uri<T> uri_type;
@@ -215,3 +215,15 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(assignment_test, T, tag_types) {
215215
BOOST_CHECK(instance.to_string() == copy.to_string());
216216
BOOST_CHECK(instance == copy);
217217
}
218+
219+
BOOST_AUTO_TEST_CASE_TEMPLATE(authority_test, T, tag_types) {
220+
typedef uri::basic_uri<T> uri_type;
221+
typedeftypename uri_type::string_type string_type;
222+
223+
const std::stringurl("http://user:password@www.boost.org:8000/path?query#fragment");
224+
const std::stringauthority("user:password@www.boost.org:8000");
225+
226+
uri_typeinstance(string_type(boost::begin(url),boost::end(url)));
227+
BOOST_REQUIRE(uri::is_valid(instance));
228+
BOOST_CHECK(boost::equal(uri::authority(instance), authority));
229+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp