|
13 | 13 |
|
14 | 14 | usingnamespaceboost::network; |
15 | 15 |
|
16 | | -typedef boost::mpl::list<tags::http_default_8bit_tcp_resolve, tags::http_default_8bit_udp_resolve, tags::http_keepalive_8bit_tcp_resolve, tags::http_keepalive_8bit_udp_resolve> tag_types; |
| 16 | +typedef boost::mpl::list< |
| 17 | + tags::http_default_8bit_tcp_resolve, |
| 18 | + tags::http_default_8bit_udp_resolve, |
| 19 | + tags::http_keepalive_8bit_tcp_resolve, |
| 20 | + tags::http_keepalive_8bit_udp_resolve, |
| 21 | + tags::http_async_8bit_tcp_resolve, |
| 22 | + tags::http_async_8bit_udp_resolve |
| 23 | +> tag_types; |
17 | 24 |
|
18 | 25 | BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test, T, tag_types) { |
19 | | - http::basic_request<T>request("http://www.boost.org/"); |
20 | | - http::basic_client<T,1,1> client_; |
21 | | - http::basic_response<T> response_; |
| 26 | +typedef http::basic_client<T,1,1> client_type; |
| 27 | +typename client_type::requestrequest("http://www.boost.org/"); |
| 28 | +typename client_type::response response_; |
| 29 | + client_type client_; |
22 | 30 | BOOST_CHECK_NO_THROW ( response_ = client_.get(request) ); |
23 | | -typename headers_range<typenamehttp::basic_response<T>>::type range =headers(response_)["Content-Type"]; |
| 31 | +typename headers_range<typenameclient_type::response>::type range =headers(response_)["Content-Type"]; |
24 | 32 | BOOST_CHECK (boost::begin(range) !=boost::end(range) ); |
25 | 33 | BOOST_CHECK (body(response_).size() !=0 ); |
26 | 34 | } |
27 | 35 |
|
28 | 36 | BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_different_port, T, tag_types) { |
29 | | - http::basic_request<T>request("http://www.boost.org:80/"); |
30 | | - http::basic_client<T,1,1> client_; |
31 | | - http::basic_response<T> response_; |
| 37 | +typedef http::basic_client<T,1,1> client_type; |
| 38 | +typename client_type::requestrequest("http://www.boost.org:80/"); |
| 39 | +typename client_type::response response_; |
| 40 | + client_type client_; |
32 | 41 | BOOST_CHECK_NO_THROW ( response_ = client_.get(request) ); |
33 | | -typename headers_range<typenamehttp::basic_response<T> >::type range =headers(response_)["Content-Type"]; |
| 42 | +typename headers_range<typenameclient_type::response >::type range =headers(response_)["Content-Type"]; |
34 | 43 | BOOST_CHECK (boost::begin(range) !=boost::end(range) ); |
35 | 44 | BOOST_CHECK (body(response_).size() !=0 ); |
36 | 45 | } |
37 | 46 |
|
38 | 47 | BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout, T, tag_types) { |
39 | | - http::basic_request<T>request("http://localhost:12121/"); |
40 | | - http::basic_client<T,1,1> client_; |
41 | | - http::basic_response<T> response_; |
42 | | -BOOST_CHECK_THROW ( response_ = client_.get(request), boost::system::system_error ); |
| 48 | +typedef http::basic_client<T,1,1> client_type; |
| 49 | +typename client_type::requestrequest("http://localhost:12121/"); |
| 50 | +typename client_type::response response_; |
| 51 | + client_type client_; |
| 52 | +BOOST_CHECK_THROW ( response_ = client_.get(request);body(response_); , boost::system::system_error ); |
43 | 53 | } |
44 | 54 |
|
45 | 55 | BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_details, T, tag_types) { |
46 | | - http::basic_request<T>request("http://www.boost.org/"); |
47 | | - http::basic_client<T,1,1> client_; |
48 | | - http::basic_response<T> response_; |
| 56 | +typedef http::basic_client<T,1,1> client_type; |
| 57 | +typename client_type::requestrequest("http://www.boost.org/"); |
| 58 | +typename client_type::response response_; |
| 59 | + client_type client_; |
49 | 60 | BOOST_CHECK_NO_THROW ( response_ = client_.get(request) ); |
50 | 61 | BOOST_CHECK_EQUAL ( response_.version().substr(0,7),std::string("HTTP/1.") ); |
51 | 62 | BOOST_CHECK_EQUAL ( response_.status(),200u ); |
52 | 63 | BOOST_CHECK_EQUAL ( response_.status_message(),std::string("OK") ); |
53 | 64 | } |
54 | 65 |
|
55 | 66 | BOOST_AUTO_TEST_CASE_TEMPLATE(http_cached_resolve, T, tag_types) { |
56 | | - http::basic_request<T>request("http://www.boost.org"); |
57 | | - http::basic_request<T>other_request("http://www.boost.org/users/license.html"); |
58 | | - http::basic_client<T,1,1>client_(http::basic_client<T,1,1>::cache_resolved); |
59 | | - http::basic_response<T> response_; |
| 67 | +typedef http::basic_client<T,1,1> client_type; |
| 68 | +typename client_type::requestrequest("http://www.boost.org/"), |
| 69 | +other_request("http://www.boost.org/users/license.html"); |
| 70 | +typename client_type::response response_; |
| 71 | + client_typeclient_(client_type::cache_resolved); |
60 | 72 | BOOST_CHECK_NO_THROW ( response_ = client_.get(request) ); |
61 | 73 | BOOST_CHECK_NO_THROW ( response_ = client_.get(other_request) ); |
62 | 74 | response_ = client_.get(other_request); |
63 | 75 | } |
64 | 76 |
|
| 77 | +template<classTag> |
| 78 | +structstatus_ : |
| 79 | + boost::mpl::if_< |
| 80 | + boost::network::is_async<Tag>, |
| 81 | + boost::mpl::integral_c<boost::uint16_t,301u>, |
| 82 | + boost::mpl::integral_c<boost::uint16_t,200u> |
| 83 | + >::type |
| 84 | +{}; |
| 85 | + |
65 | 86 | BOOST_AUTO_TEST_CASE_TEMPLATE(http_redirection_test, T, tag_types) { |
66 | | - http::basic_request<T>request("http://boost.org"); |
67 | | - http::basic_client<T,1,1>client_(http::basic_client<T,1,1>::follow_redirect); |
68 | | - http::basic_response<T> response_; |
| 87 | +typedef http::basic_client<T,1,1> client_type; |
| 88 | +typename client_type::requestrequest("http://boost.org/"); |
| 89 | +typename client_type::response response_; |
| 90 | + client_typeclient_(client_type::follow_redirect); |
69 | 91 | BOOST_CHECK_NO_THROW ( response_ = client_.get(request) ); |
70 | | -BOOST_CHECK_EQUAL ( response_.status(),200u ); |
| 92 | +BOOST_CHECK_EQUAL ( response_.status(),status_<T>::value ); |
71 | 93 | } |
72 | 94 |
|
73 | 95 |
|