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

Commit5925e6f

Browse files
committed
Adding tests and support for UDP based resolving with the HTTP client.
1 parent1c2a006 commit5925e6f

File tree

8 files changed

+93
-73
lines changed

8 files changed

+93
-73
lines changed

‎boost/network/protocol/http/client.hpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ namespace boost { namespace network { namespace http {
5151

5252
while (error && endpoint_iterator != end) {
5353
socket_.close();
54-
socket_.connect(*endpoint_iterator++, error);
54+
socket_.connect(
55+
tcp::endpoint(
56+
endpoint_iterator->endpoint().address()
57+
, endpoint_iterator->endpoint().port()
58+
)
59+
, error
60+
);
61+
++endpoint_iterator;
5562
}
5663

5764
if (error)
@@ -87,8 +94,8 @@ namespace boost { namespace network { namespace http {
8794
<<"Host:" << request_.host() <<"\r\n"
8895
<<"Accept: */*\r\n";
8996

90-
headers_range<http::request>::type range =headers(request_);
91-
BOOST_FOREACH(headers_range<http::request>::type::value_typeconst & header, range) {
97+
typenameheaders_range<http::basic_request<Tag>>::type range =headers(request_);
98+
BOOST_FOREACH(typenameheaders_range<http::basic_request<Tag>>::type::value_typeconst & header, range) {
9299
request_stream << header.first <<":" << header.second <<"\r\n";
93100
};
94101

@@ -169,7 +176,7 @@ namespace boost { namespace network { namespace http {
169176
response_ <<body(body_stream.str());
170177
};
171178

172-
responseconstsync_request_skeleton(basic_request<Tag>const & request_, string_type method,bool get_body) {
179+
basic_response<Tag>constsync_request_skeleton(basic_request<Tag>const & request_, string_type method,bool get_body) {
173180
using boost::asio::ip::tcp;
174181

175182
basic_request<Tag>request_copy(request_);
@@ -191,8 +198,8 @@ namespace boost { namespace network { namespace http {
191198
if (follow_redirect_) {
192199
uint16_t status = response_.status();
193200
if (status >=300 && status <=307) {
194-
headers_range<http::request>::type location_range =headers(response_)["Location"];
195-
range_iterator<headers_range<http::request>::type>::type location_header =begin(location_range);
201+
typenameheaders_range<http::basic_response<Tag>>::type location_range =headers(response_)["Location"];
202+
typenamerange_iterator<typenameheaders_range<http::basic_request<Tag>>::type>::type location_header =begin(location_range);
196203
if (location_header !=end(location_range)) {
197204
request_copy.uri(location_header->second);
198205
}elsethrowstd::runtime_error("Location header not defined in redirect response.");
@@ -241,47 +248,47 @@ namespace boost { namespace network { namespace http {
241248
resolver_base::endpoint_cache_.clear();
242249
}
243250

244-
responseconsthead (basic_request<Tag>const & request_) {
251+
basic_response<Tag>consthead (basic_request<Tag>const & request_) {
245252
returnsync_request_skeleton(request_,"HEAD",false);
246253
};
247254

248-
responseconstget (basic_request<Tag>const & request_) {
255+
basic_response<Tag>constget (basic_request<Tag>const & request_) {
249256
returnsync_request_skeleton(request_,"GET",true);
250257
};
251258

252-
responseconstpost (basic_request<Tag>const & request_) {
259+
basic_response<Tag>constpost (basic_request<Tag>const & request_) {
253260
returnsync_request_skeleton(request_,"POST",true);
254261
};
255262

256-
responseconstpost (basic_request<Tag>const & request_, string_typeconst & content_type, string_typeconst & body_) {
263+
basic_response<Tag>constpost (basic_request<Tag>const & request_, string_typeconst & content_type, string_typeconst & body_) {
257264
basic_request<Tag> request_copy = request_;
258265
request_copy <<body(body_)
259266
<<header("Content-Type", content_type)
260267
<<header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
261268
returnpost(request_copy);
262269
};
263270

264-
responseconstpost (basic_request<Tag>const & request_, string_typeconst & body_) {
271+
basic_response<Tag>constpost (basic_request<Tag>const & request_, string_typeconst & body_) {
265272
returnpost(request_,"x-application/octet-stream", body_);
266273
};
267274

268-
responseconstput (basic_request<Tag>const & request_) {
275+
basic_response<Tag>constput (basic_request<Tag>const & request_) {
269276
returnsync_request_skeleton(request_,"PUT",true);
270277
};
271278

272-
responseconstput (basic_request<Tag>const & request_, string_typeconst & body_) {
279+
basic_response<Tag>constput (basic_request<Tag>const & request_, string_typeconst & body_) {
273280
returnput(request_,"x-application/octet-stream", body_);
274281
};
275282

276-
responseconstput (basic_request<Tag>const & request_, string_typeconst & content_type, string_typeconst & body_) {
283+
basic_response<Tag>constput (basic_request<Tag>const & request_, string_typeconst & content_type, string_typeconst & body_) {
277284
basic_request<Tag> request_copy = request_;
278285
request_copy <<body(body_)
279286
<<header("Content-Type", content_type)
280287
<<header("Content-Length", boost::lexical_cast<string_type>(body_.size()));
281288
returnput(request_copy);
282289
};
283290

284-
responseconstdelete_ (basic_request<Tag>const & request_) {
291+
basic_response<Tag>constdelete_ (basic_request<Tag>const & request_) {
285292
returnsync_request_skeleton(request_,"DELETE",true);
286293
};
287294

‎boost/network/tags.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace boost {
1313
namespacenetwork {
1414
namespacetags {
1515

16-
structdefault_string;
17-
structdefault_wstring;
18-
structhttp_default_8bit_tcp_resolve;
19-
structhttp_default_8bit_udp_resolve;
20-
structpod;
16+
structdefault_string {};
17+
structdefault_wstring {};
18+
structhttp_default_8bit_tcp_resolve {};
19+
structhttp_default_8bit_udp_resolve {};
20+
structpod {};
2121

2222
typedef default_string default_;
2323

‎boost/network/traits/char.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,25 @@
66
#ifndef BOOST_NETWORK_TRAITS_CHAR_HPP
77
#defineBOOST_NETWORK_TRAITS_CHAR_HPP
88

9+
#include<boost/network/tags.hpp>
10+
911
namespaceboost {namespacenetwork {
1012

13+
template<classTag>
14+
structunsupported_tag;
15+
1116
template<classTag>
1217
structchar_ {
18+
typedef unsupported_tag<Tag> type;
19+
};
20+
21+
template<>
22+
structchar_<tags::http_default_8bit_tcp_resolve> {
23+
typedefchar type;
24+
};
25+
26+
template<>
27+
structchar_<tags::http_default_8bit_udp_resolve> {
1328
typedefchar type;
1429
};
1530

‎boost/network/traits/headers_container.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#ifndef __BOOST_NETWORK_TRAITS_HEADERS_CONTAINER_INC__
88
#define__BOOST_NETWORK_TRAITS_HEADERS_CONTAINER_INC__
99

10-
1110
#include<map>
1211
#include<boost/network/tags.hpp>
1312
#include<boost/network/traits/string.hpp>
@@ -25,23 +24,6 @@ struct headers_container {
2524
> type;
2625
};
2726

28-
29-
// template <>
30-
// struct headers_container<tags::default_string> {
31-
// typedef std::multimap<
32-
// string<tags::default_string>::type,
33-
// string<tags::default_string>::type
34-
// > type;
35-
// };
36-
//
37-
//
38-
// template <>
39-
// struct headers_container<tags::default_wstring> {
40-
// typedef std::multimap<
41-
// string<tags::default_wstring>::type,
42-
// string<tags::default_wstring>::type
43-
// > type;
44-
// };
4527
}// namespace network
4628
}// namespace boost
4729

‎boost/network/traits/ostringstream.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ namespace boost { namespace network {
3535
typedef std::ostringstream type;
3636
};
3737

38+
template<>
39+
structostringstream<tags::http_default_8bit_udp_resolve> {
40+
typedef std::ostringstream type;
41+
};
42+
3843
}// namespace network
3944

4045
}// namespace boost

‎boost/network/traits/string.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414
namespaceboost {namespacenetwork {
1515

16+
template<classTag>
17+
structunsupported_tag;
18+
1619
template<classTag>
1720
structstring {
18-
typedefvoid type;
21+
typedefunsupported_tag<Tag> type;
1922
};
2023

2124
template<>
@@ -38,6 +41,11 @@ namespace boost { namespace network {
3841
typedef std::string type;
3942
};
4043

44+
template<>
45+
structstring<tags::http_default_8bit_udp_resolve> {
46+
typedef std::string type;
47+
};
48+
4149
}// namespace network
4250

4351
}// namespace boost

‎boost/network/traits/vector.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010

1111
namespaceboost {namespacenetwork {
1212

13+
template<classTag>
14+
structunsupported_tag;
15+
1316
template<classTag>
1417
structvector {
1518

1619
template<classType>
1720
structapply {
18-
typedefvoid type;
21+
typedefunsupported_tag<Tag> type;
1922
};
2023

2124
};

‎libs/network/test/http_1_0_test.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,63 +8,63 @@
88
#include<boost/test/unit_test.hpp>
99
#include<boost/network.hpp>
1010
#include<iostream>
11+
#include<boost/mpl/list.hpp>
1112

12-
BOOST_AUTO_TEST_CASE(http_get_test) {
13-
usingnamespaceboost::network;
14-
http::requestrequest("http://www.boost.org/");
15-
http::client client_;
16-
http::response response_;
13+
usingnamespaceboost::network;
14+
15+
typedef boost::mpl::list<tags::http_default_8bit_tcp_resolve, tags::http_default_8bit_udp_resolve> tag_types;
16+
17+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test, T, tag_types) {
18+
http::basic_request<T>request("http://www.boost.org/");
19+
http::basic_client<T,1,0> client_;
20+
http::basic_response<T> response_;
1721
response_ = client_.get(request);
18-
headers_range<http::response>::type range =headers(response_)["Content-Type"];
22+
typenameheaders_range<typenamehttp::basic_response<T>>::type range =headers(response_)["Content-Type"];
1923
BOOST_CHECK (begin(range) !=end(range) );
2024
BOOST_CHECK (body(response_).size() !=0 );
2125
}
2226

23-
BOOST_AUTO_TEST_CASE(http_get_test_different_port) {
24-
usingnamespaceboost::network;
25-
http::requestrequest("http://www.boost.org:80/");
26-
http::client client_;
27-
http::response response_;
27+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_different_port, T, tag_types) {
28+
http::basic_request<T>request("http://www.boost.org:80/");
29+
http::basic_client<T,1,0> client_;
30+
http::basic_response<T> response_;
2831
response_ = client_.get(request);
29-
headers_range<http::response>::type range =headers(response_)["Content-Type"];
32+
typenameheaders_range<typenamehttp::basic_response<T>>::type range =headers(response_)["Content-Type"];
3033
BOOST_CHECK (begin(range) !=end(range) );
3134
BOOST_CHECK (body(response_).size() !=0 );
3235
}
3336

34-
BOOST_AUTO_TEST_CASE(http_get_test_timeout) {
35-
usingnamespaceboost::network;
36-
http::requestrequest("http://localhost:12121/");
37-
http::client client_;
38-
http::response response_;
37+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout, T, tag_types) {
38+
http::basic_request<T>request("http://localhost:12121/");
39+
http::basic_client<T,1,0> client_;
40+
http::basic_response<T> response_;
3941
BOOST_CHECK_THROW ( response_ = client_.get(request), boost::system::system_error );
4042
}
4143

42-
BOOST_AUTO_TEST_CASE(http_get_details) {
43-
usingnamespaceboost::network;
44-
http::requestrequest("http://www.boost.org/");
45-
http::client client_;
46-
http::response response_;
44+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_details, T, tag_types) {
45+
http::basic_request<T>request("http://www.boost.org/");
46+
http::basic_client<T,1,0> client_;
47+
http::basic_response<T> response_;
4748
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
4849
BOOST_CHECK_EQUAL ( response_.version().substr(0,7),std::string("HTTP/1.") );
4950
BOOST_CHECK_EQUAL ( response_.status(),200u );
5051
BOOST_CHECK_EQUAL ( response_.status_message(),std::string("OK") );
5152
}
5253

53-
BOOST_AUTO_TEST_CASE(http_cached_resolve) {
54-
usingnamespaceboost::network;
55-
http::requestrequest("http://www.boost.org");
56-
http::requestother_request("http://www.boost.org/users/license.html");
57-
http::clientclient_(http::client::cache_resolved);
58-
http::response response_;
54+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_cached_resolve, T, tag_types) {
55+
http::basic_request<T>request("http://www.boost.org");
56+
http::basic_request<T>other_request("http://www.boost.org/users/license.html");
57+
http::basic_client<T,1,0>client_(http::basic_client<T,1,0>::cache_resolved);
58+
http::basic_response<T> response_;
5959
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
6060
BOOST_CHECK_NO_THROW ( response_ = client_.get(other_request) );
6161
}
6262

63-
BOOST_AUTO_TEST_CASE(http_redirection_test) {
64-
usingnamespaceboost::network;
65-
http::requestrequest("http://boost.org");
66-
http::clientclient_(http::client::follow_redirect);
67-
http::response response_;
63+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_redirection_test, T, tag_types) {
64+
http::basic_request<T>request("http://boost.org");
65+
http::basic_client<T,1,0>client_(http::basic_client<T,1,0>::follow_redirect);
66+
http::basic_response<T> response_;
6867
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
6968
BOOST_CHECK_EQUAL ( response_.status(),200u );
7069
}
70+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp