|
| 1 | + |
| 2 | +// Copyright Dean Michael Berris 2009. |
| 3 | +// Distributed under the Boost Software License, Version 1.0. |
| 4 | +// (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 6 | + |
| 7 | +#define BOOST_TEST_MODULE http 1.1 test |
| 8 | +#include <boost/test/unit_test.hpp> |
| 9 | +#include <boost/network.hpp> |
| 10 | +#include <iostream> |
| 11 | +#include <boost/mpl/list.hpp> |
| 12 | + |
| 13 | +using namespace boost::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, 1> client_; |
| 20 | + http::basic_response<T> response_; |
| 21 | + response_ = client_.get(request); |
| 22 | + typename headers_range<typename http::basic_response<T> >::type range = headers(response_)["Content-Type"]; |
| 23 | + BOOST_CHECK ( begin(range) != end(range) ); |
| 24 | + BOOST_CHECK ( body(response_).size() != 0 ); |
| 25 | +} |
| 26 | + |
| 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, 1> client_; |
| 30 | + http::basic_response<T> response_; |
| 31 | + response_ = client_.get(request); |
| 32 | + typename headers_range<typename http::basic_response<T> >::type range = headers(response_)["Content-Type"]; |
| 33 | + BOOST_CHECK ( begin(range) != end(range) ); |
| 34 | + BOOST_CHECK ( body(response_).size() != 0 ); |
| 35 | +} |
| 36 | + |
| 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, 1> client_; |
| 40 | + http::basic_response<T> response_; |
| 41 | + BOOST_CHECK_THROW ( response_ = client_.get(request), boost::system::system_error ); |
| 42 | +} |
| 43 | + |
| 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, 1> client_; |
| 47 | + http::basic_response<T> response_; |
| 48 | + BOOST_CHECK_NO_THROW ( response_ = client_.get(request) ); |
| 49 | + BOOST_CHECK_EQUAL ( response_.version().substr(0,7), std::string("HTTP/1.") ); |
| 50 | + BOOST_CHECK_EQUAL ( response_.status(), 200u ); |
| 51 | + BOOST_CHECK_EQUAL ( response_.status_message(), std::string("OK") ); |
| 52 | +} |
| 53 | + |
| 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, 1> client_(http::basic_client<T, 1, 1>::cache_resolved); |
| 58 | + http::basic_response<T> response_; |
| 59 | + BOOST_CHECK_NO_THROW ( response_ = client_.get(request) ); |
| 60 | + BOOST_CHECK_NO_THROW ( response_ = client_.get(other_request) ); |
| 61 | +} |
| 62 | + |
| 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, 1> client_(http::basic_client<T, 1, 1>::follow_redirect); |
| 66 | + http::basic_response<T> response_; |
| 67 | + BOOST_CHECK_NO_THROW ( response_ = client_.get(request) ); |
| 68 | + BOOST_CHECK_EQUAL ( response_.status(), 200u ); |
| 69 | +} |
| 70 | + |
| 71 | + |
0 commit comments