Skip to content

Commit 2e3340f

Browse files
committed
Change test to fetch different targets
1 parent 39a2705 commit 2e3340f

File tree

7 files changed

+54
-45
lines changed

7 files changed

+54
-45
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ libs/mime/test/mime-roundtrip
1010
*.a
1111
_build
1212
/.project
13+
build/

boost/mime.hpp

+19-23
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
#ifndef _BOOST_MIME_HPP
1010
#define _BOOST_MIME_HPP
1111

12+
#include <iosfwd>
1213
#include <list>
1314
#include <string>
1415
#include <vector>
15-
#include <iosfwd>
1616

17-
#include <boost/spirit/include/qi.hpp>
17+
#include <boost/fusion/adapted/struct.hpp>
1818
#include <boost/fusion/include/std_pair.hpp>
1919
#include <boost/spirit/include/phoenix.hpp> // pulls in all of Phoenix
20+
#include <boost/spirit/include/qi.hpp>
2021
#include <boost/spirit/include/support_istream_iterator.hpp>
21-
#include <boost/fusion/adapted/struct.hpp>
2222

23-
#include <boost/shared_ptr.hpp>
24-
#include <boost/format.hpp>
25-
#include <boost/algorithm/string/predicate.hpp>
2623
#include <boost/algorithm/string.hpp>
24+
#include <boost/algorithm/string/predicate.hpp>
25+
#include <boost/format.hpp>
26+
#include <boost/shared_ptr.hpp>
2727

2828
// #define DUMP_MIME_DATA 1
2929

@@ -321,7 +321,8 @@ static void read_multipart_body(Iterator &begin, Iterator end,
321321
"= %d %s") %
322322
mp_body.body_prolog.size() % mp_body.sub_parts.size() %
323323
mp_body.body_epilog.size() %
324-
(mp_body.prolog_is_missing ? "(missing)" : "")) << std::endl;
324+
(mp_body.prolog_is_missing ? "(missing)" : ""))
325+
<< std::endl;
325326
std::cout << std::endl << "****** Multipart Body Prolog *******" << std::endl;
326327
std::copy(mp_body.body_prolog.begin(), mp_body.body_prolog.end(),
327328
std::ostream_iterator<char>(std::cout));
@@ -381,11 +382,7 @@ static boost::shared_ptr<basic_mime<traits> > parse_mime(
381382
template <class traits = detail::default_types>
382383
class basic_mime {
383384
public:
384-
typedef enum {
385-
simple_part,
386-
multi_part,
387-
message_part
388-
} part_kind;
385+
typedef enum { simple_part, multi_part, message_part } part_kind;
389386
// Types for headers
390387
typedef typename traits::string_type string_type;
391388
typedef std::pair<std::string, string_type> headerEntry;
@@ -618,8 +615,7 @@ class basic_mime {
618615
std::string boundary;
619616
try {
620617
boundary = detail::get_boundary(get_content_type_header());
621-
}
622-
catch (std::runtime_error &) {
618+
} catch (std::runtime_error &) {
623619
// FIXME: Make boundary strings (more?) unique
624620
boundary = str(boost::format("------=_NextPart-%s.%08ld") %
625621
detail::k_package_name % std::clock());
@@ -707,9 +703,8 @@ class basic_mime {
707703
else if (get_part_kind() == multi_part) {
708704
if (idx >= m_subparts.size())
709705
throw std::runtime_error(
710-
str(boost::format(
711-
"Trying to access part %d (of %d) sub-part to a "
712-
"multipart/xxx mime part") %
706+
str(boost::format("Trying to access part %d (of %d) sub-part to a "
707+
"multipart/xxx mime part") %
713708
idx % m_subparts.size()));
714709
} else { // message-part
715710
if (get_part_kind() == message_part)
@@ -720,9 +715,8 @@ class basic_mime {
720715

721716
if (idx >= m_subparts.size())
722717
throw std::runtime_error(
723-
str(boost::format(
724-
"Trying to access part %d (of %d) sub-part to a "
725-
"message/xxx mime part") %
718+
str(boost::format("Trying to access part %d (of %d) sub-part to a "
719+
"message/xxx mime part") %
726720
idx % m_subparts.size()));
727721
}
728722
}
@@ -764,12 +758,14 @@ static boost::shared_ptr<basic_mime<traits> > parse_mime(
764758
#ifdef DUMP_MIME_DATA
765759
std::cout << "Content-Type: " << content_type << std::endl;
766760
std::cout << str(boost::format("retVal->get_part_kind () = %d") %
767-
((int)retVal->get_part_kind())) << std::endl;
761+
((int)retVal->get_part_kind()))
762+
<< std::endl;
768763
#endif
769764

770765
if (retVal->get_part_kind() == mime_part::simple_part)
771-
retVal->set_body(detail::read_simplepart_body<
772-
typename mime_part::bodyContainer, Iterator>(begin, end));
766+
retVal->set_body(
767+
detail::read_simplepart_body<typename mime_part::bodyContainer,
768+
Iterator>(begin, end));
773769
else if (retVal->get_part_kind() == mime_part::message_part) {
774770
// If we've got a message/xxxx, then there is no body, and we have
775771
// a single

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ struct async_client
4040
async_client(bool cache_resolved, bool follow_redirect,
4141
bool always_verify_peer, int timeout,
4242
boost::shared_ptr<boost::asio::io_service> service,
43-
optional<string_type> certificate_filename,
44-
optional<string_type> verify_path,
45-
optional<string_type> certificate_file,
46-
optional<string_type> private_key_file,
47-
optional<string_type> ciphers, long ssl_options)
43+
optional<string_type> certificate_filename,
44+
optional<string_type> verify_path,
45+
optional<string_type> certificate_file,
46+
optional<string_type> private_key_file,
47+
optional<string_type> ciphers, long ssl_options)
4848
: connection_base(cache_resolved, follow_redirect, timeout),
4949
service_ptr(service.get()
5050
? service

boost/network/protocol/http/client/connection/async_normal.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ struct http_async_connection
5050
protected http_async_protocol_handler<Tag, version_major, version_minor>,
5151
boost::enable_shared_from_this<
5252
http_async_connection<Tag, version_major, version_minor> > {
53+
54+
http_async_connection(http_async_connection const&) = delete;
55+
5356
typedef async_connection_base<Tag, version_major, version_minor> base;
5457
typedef http_async_protocol_handler<Tag, version_major, version_minor>
5558
protocol_base;
@@ -115,7 +118,6 @@ struct http_async_connection
115118
}
116119

117120
private:
118-
http_async_connection(http_async_connection const&); // = delete
119121

120122
void set_errors(boost::system::error_code const& ec) {
121123
boost::system::system_error error(ec);

boost/network/protocol/http/client/connection/normal_delegate.ipp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void boost::network::http::impl::normal_delegate::connect(
2828

2929
socket_.reset(new asio::ip::tcp::socket(
3030
service_,
31-
asio::ip::tcp::endpoint(asio::ip::tcp::v4(), source_port)));
31+
asio::ip::tcp::endpoint(asio::ip::address(), source_port)));
3232
socket_->async_connect(endpoint, handler);
3333
}
3434

boost/network/protocol/http/client/connection/sync_normal.hpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
// (See accompanying file LICENSE_1_0.txt or copy at
99
// http://www.boost.org/LICENSE_1_0.txt)
1010

11+
#include <boost/asio/deadline_timer.hpp>
1112
#include <boost/network/protocol/http/algorithms/linearize.hpp>
13+
#include <boost/network/protocol/http/response.hpp>
14+
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
15+
#include <boost/network/traits/string.hpp>
1216
#include <iterator>
1317

14-
#include <boost/asio/deadline_timer.hpp>
15-
1618
namespace boost {
1719
namespace network {
1820
namespace http {
@@ -50,11 +52,11 @@ struct http_sync_connection
5052
resolve_(std::move(resolve)),
5153
socket_(resolver.get_io_service()) {}
5254

53-
void init_socket(string_type /*unused*/const& hostname, string_type const& port) {
55+
void init_socket(string_type const& hostname, string_type const& port) {
5456
connection_base::init_socket(socket_, resolver_, hostname, port, resolve_);
5557
}
5658

57-
void send_request_impl(string_type /*unused*/const& method,
59+
void send_request_impl(string_type const& method,
5860
basic_request<Tag> const& request_,
5961
body_generator_function_type generator) {
6062
boost::asio::streambuf request_buffer;
@@ -130,7 +132,7 @@ struct http_sync_connection
130132
};
131133

132134
} // namespace impl
133-
} // namespace http
135+
} // namespace http
134136
} // namespace network
135137
} // namespace boost
136138

libs/network/test/http/client_get_test.cpp

+18-10
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,37 @@ namespace net = boost::network;
1212
namespace http = boost::network::http;
1313

1414
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_test, client, client_types) {
15-
typename client::request request("http://www.boost.org");
15+
typename client::request request("http://cpp-netlib.org/");
1616
client client_;
1717
typename client::response response;
1818
BOOST_REQUIRE_NO_THROW(response = client_.get(request));
1919
typename net::headers_range<typename client::response>::type range =
2020
headers(response)["Content-Type"];
21-
BOOST_CHECK(!boost::empty(range));
22-
BOOST_REQUIRE_NO_THROW(BOOST_CHECK(body(response).size() != 0));
21+
try {
22+
auto data = body(response);
23+
} catch (...) {
24+
BOOST_ASSERT(false);
25+
}
2326
BOOST_CHECK_EQUAL(response.version().substr(0, 7), std::string("HTTP/1."));
24-
BOOST_CHECK_EQUAL(response.status(), 200u);
25-
BOOST_CHECK_EQUAL(response.status_message(), std::string("OK"));
27+
BOOST_CHECK(response.status() == 200u ||
28+
(response.status() >= 300 && response.status() < 400));
2629
}
2730

2831
#ifdef BOOST_NETWORK_ENABLE_HTTPS
2932

3033
BOOST_AUTO_TEST_CASE_TEMPLATE(https_client_get_test, client, client_types) {
31-
typename client::request request("https://www.google.com/");
34+
typename client::request request("https://www.github.com/");
3235
client client_;
33-
typename client::response response_ = client_.get(request);
36+
typename client::response response = client_.get(request);
3437
typename net::headers_range<typename client::response>::type range =
35-
headers(response_)["Content-Type"];
36-
BOOST_CHECK(boost::begin(range) != boost::end(range));
37-
BOOST_CHECK(body(response_).size() != 0);
38+
headers(response)["Content-Type"];
39+
BOOST_CHECK(response.status() == 200 ||
40+
(response.status() >= 300 && response.status() < 400));
41+
try {
42+
auto data = body(response);
43+
} catch (...) {
44+
BOOST_ASSERT(false);
45+
}
3846
}
3947

4048
#endif

0 commit comments

Comments
 (0)