Skip to content

Commit 6da32c4

Browse files
committed
Removing client dependency on Boost.Parameter.
1 parent 6ba8f9a commit 6da32c4

File tree

10 files changed

+45
-190
lines changed

10 files changed

+45
-190
lines changed

boost/network/protocol/http/client.hpp

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#include <map>
2525

2626
#include <boost/network/protocol/http/client/facade.hpp>
27-
#include <boost/network/protocol/http/client/parameters.hpp>
2827
#include <boost/network/protocol/http/client/macros.hpp>
28+
#include <boost/network/protocol/http/client/options.hpp>
2929

3030
namespace boost { namespace network { namespace http {
3131

@@ -41,38 +41,18 @@ namespace boost { namespace network { namespace http {
4141
typedef basic_response<Tag> response;
4242
typedef typename string<Tag>::type string_type;
4343
typedef Tag tag_type;
44+
typedef client_options<Tag> options;
4445

45-
// Constructor
46+
// Constructors
4647
// =================================================================
47-
// This is a Boost.Parameter-based constructor forwarder, whose
48-
// implementation is actually forwarded to the base type.
49-
//
50-
// The supported parameters are:
51-
// _follow_redirects : bool -- whether to follow HTTP redirect
52-
// responses (default: false)
53-
// _cache_resolved : bool -- whether to cache the resolved
54-
// endpoints (default: false)
55-
// _io_service : boost::asio::io_service &
56-
// -- supply an io_service to the
57-
// client
58-
// _openssl_certificate : string
59-
// -- the name of the certificate file
60-
// to use
61-
// _openssl_verify_path : string
62-
// -- the name of the directory from
63-
// which the certificate authority
64-
// files can be found
65-
66-
BOOST_PARAMETER_CONSTRUCTOR(
67-
basic_client, (base_facade_type), tag,
68-
(optional
69-
(in_out(io_service), (boost::asio::io_service&))
70-
(follow_redirects, (bool))
71-
(cache_resolved, (bool))
72-
(openssl_certificate, (string_type))
73-
(openssl_verify_path, (string_type))
74-
))
75-
48+
// This constructor takes a single options argument of type
49+
// client_options. See boost/network/protocol/http/client/options.hpp
50+
// for more details.
51+
explicit basic_client(options const & options)
52+
: base_facade_type(options) {}
53+
54+
// This default constructor sets up the default options.
55+
basic_client() : base_facade_type(options()) {}
7656
//
7757
// =================================================================
7858

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <boost/asio/io_service.hpp>
1212
#include <boost/asio/strand.hpp>
1313
#include <boost/thread/thread.hpp>
14+
#include <boost/shared_ptr.hpp>
15+
#include <boost/make_shared.hpp>
1416
#include <boost/bind.hpp>
1517

1618
namespace boost { namespace network { namespace http {
@@ -37,9 +39,9 @@ namespace boost { namespace network { namespace http {
3739
function<void(boost::iterator_range<char const *> const &, system::error_code const &)>
3840
body_callback_function_type;
3941

40-
async_client(bool cache_resolved, bool follow_redirect, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path)
42+
async_client(bool cache_resolved, bool follow_redirect, boost::shared_ptr<boost::asio::io_service> service, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path)
4143
: connection_base(cache_resolved, follow_redirect),
42-
service_ptr(new boost::asio::io_service),
44+
service_ptr(service.get() ? service : boost::make_shared<boost::asio::io_service>()),
4345
service_(*service_ptr),
4446
resolver_(service_),
4547
sentinel_(new boost::asio::io_service::work(service_)),
@@ -55,27 +57,13 @@ namespace boost { namespace network { namespace http {
5557
)));
5658
}
5759

58-
async_client(bool cache_resolved, bool follow_redirect, boost::asio::io_service & service, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path)
59-
: connection_base(cache_resolved, follow_redirect),
60-
service_ptr(0),
61-
service_(service),
62-
resolver_(service_),
63-
sentinel_(new boost::asio::io_service::work(service_)),
64-
certificate_filename_(certificate_filename),
65-
verify_path_(verify_path)
66-
{
67-
connection_base::resolver_strand_.reset(new
68-
boost::asio::io_service::strand(service_));
69-
}
70-
7160
~async_client() throw ()
7261
{
7362
sentinel_.reset();
7463
if (lifetime_thread_.get()) {
7564
lifetime_thread_->join();
7665
lifetime_thread_.reset();
7766
}
78-
delete service_ptr;
7967
}
8068

8169
basic_response<Tag> const request_skeleton(
@@ -90,7 +78,7 @@ namespace boost { namespace network { namespace http {
9078
return connection_->send_request(method, request_, get_body, callback);
9179
}
9280

93-
boost::asio::io_service * service_ptr;
81+
boost::shared_ptr<boost::asio::io_service> service_ptr;
9482
boost::asio::io_service & service_;
9583
resolver_type resolver_;
9684
boost::shared_ptr<boost::asio::io_service::work> sentinel_;

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

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <boost/network/protocol/http/request.hpp>
1010
#include <boost/network/protocol/http/response.hpp>
1111
#include <boost/network/protocol/http/client/pimpl.hpp>
12-
#include <boost/network/protocol/http/client/parameters.hpp>
12+
#include <boost/network/protocol/http/client/options.hpp>
1313

1414
namespace boost { namespace network { namespace http {
1515

@@ -28,45 +28,20 @@ namespace boost { namespace network { namespace http {
2828
typedef basic_client_impl<Tag,version_major,version_minor> pimpl_type;
2929
typedef function<void(iterator_range<char const *> const &,system::error_code const &)> body_callback_function_type;
3030

31-
template <class ArgPack>
32-
basic_client_facade(ArgPack const & args)
31+
basic_client_facade(client_options<Tag> const &options)
3332
{
34-
init_pimpl(args,
35-
typename mpl::if_<
36-
is_same<
37-
typename parameter::value_type<ArgPack, tag::io_service, void>::type,
38-
void
39-
>,
40-
no_io_service,
41-
has_io_service
42-
>::type());
33+
init_pimpl(options);
4334
}
4435

45-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), head, tag, (required (request,(request const &)))) {
36+
response const head(request const &request) {
4637
return pimpl->request_skeleton(request, "HEAD", false, body_callback_function_type());
4738
}
4839

49-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), get , tag,
50-
(required
51-
(request,(request const &))
52-
)
53-
(optional
54-
(body_handler,(body_callback_function_type),body_callback_function_type())
55-
)
56-
) {
40+
response const get(request const &request, body_callback_function_type body_handler = body_callback_function_type()) {
5741
return pimpl->request_skeleton(request, "GET", true, body_handler);
5842
}
5943

60-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), post, tag,
61-
(required
62-
(request,(request)) // yes sir, we make a copy of the original request.
63-
)
64-
(optional
65-
(body,(string_type const &),string_type())
66-
(content_type,(string_type const &),string_type())
67-
(body_handler,(body_callback_function_type),body_callback_function_type())
68-
)
69-
) {
44+
response const post(request request, string_type const &body = string_type(), string_type const &content_type = string_type(), body_callback_function_type body_handler = body_callback_function_type()) {
7045
if (body != string_type()) {
7146
request << remove_header("Content-Length")
7247
<< header("Content-Length", boost::lexical_cast<string_type>(body.size()))
@@ -88,16 +63,7 @@ namespace boost { namespace network { namespace http {
8863
return pimpl->request_skeleton(request, "POST", true, body_handler);
8964
}
9065

91-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), put , tag,
92-
(required
93-
(request,(request)) // yes sir, we make a copy of the original request.
94-
)
95-
(optional
96-
(body,(string_type const &),string_type())
97-
(content_type,(string_type const &),string_type())
98-
(body_handler,(body_callback_function_type),body_callback_function_type())
99-
)
100-
) {
66+
response const put(request request, string_type const &body = string_type(), string_type const &content_type = string_type(), body_callback_function_type body_handler = body_callback_function_type()) {
10167
if (body != string_type()) {
10268
request << remove_header("Content-Length")
10369
<< header("Content-Length", boost::lexical_cast<string_type>(body.size()))
@@ -119,14 +85,7 @@ namespace boost { namespace network { namespace http {
11985
return pimpl->request_skeleton(request, "PUT", true, body_handler);
12086
}
12187

122-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), delete_, tag,
123-
(required
124-
(request,(request const &))
125-
)
126-
(optional
127-
(body_handler,(body_callback_function_type),body_callback_function_type())
128-
)
129-
) {
88+
response const delete_(request const &request, body_callback_function_type body_handler = body_callback_function_type()) {
13089
return pimpl->request_skeleton(request, "DELETE", true, body_handler);
13190
}
13291

@@ -141,31 +100,15 @@ namespace boost { namespace network { namespace http {
141100

142101
boost::shared_ptr<pimpl_type> pimpl;
143102

144-
template <class ArgPack>
145-
void init_pimpl(ArgPack const & args, no_io_service) {
103+
void init_pimpl(client_options<Tag> const & options) {
146104
pimpl.reset(
147105
new pimpl_type(
148-
args[_cache_resolved|false]
149-
, args[_follow_redirects|false]
150-
, optional<string_type>(args[_openssl_certificate|optional<string_type>()])
151-
, optional<string_type>(args[_openssl_verify_path|optional<string_type>()])
152-
)
153-
);
106+
options.cache_resolved(),
107+
options.follow_redirects(),
108+
options.openssl_certificate(),
109+
options.openssl_verify_path(),
110+
options.io_service()));
154111
}
155-
156-
template <class ArgPack>
157-
void init_pimpl(ArgPack const & args, has_io_service) {
158-
pimpl.reset(
159-
new pimpl_type(
160-
args[_cache_resolved|false]
161-
, args[_follow_redirects|false]
162-
, args[_io_service]
163-
, optional<string_type>(args[_openssl_certificate|optional<string_type>()])
164-
, optional<string_type>(args[_openssl_verify_path|optional<string_type>()])
165-
)
166-
);
167-
}
168-
169112
};
170113

171114
} // namespace http

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,8 @@ namespace boost { namespace network { namespace http {
6767
typedef typename impl::client_base<Tag,version_major,version_minor>::type base_type;
6868
typedef typename base_type::string_type string_type;
6969

70-
basic_client_impl(bool cache_resolved, bool follow_redirect, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path)
71-
: base_type(cache_resolved, follow_redirect, certificate_filename, verify_path)
72-
{}
73-
74-
basic_client_impl(bool cache_resolved, bool follow_redirect, boost::asio::io_service & service, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path)
75-
: base_type(cache_resolved, follow_redirect, service, certificate_filename, verify_path)
76-
{}
70+
basic_client_impl(bool cache_resolved, bool follow_redirect, optional<string_type> const & certificate_filename, optional<string_type> const & verify_path, boost::shared_ptr<boost::asio::io_service> service)
71+
: base_type(cache_resolved, follow_redirect, service, certificate_filename, verify_path) {}
7772

7873
~basic_client_impl()
7974
{}

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,27 @@ namespace boost { namespace network { namespace http {
2222
typedef function<void(iterator_range<char const *> const &, system::error_code const &)> body_callback_function_type;
2323
friend struct basic_client_impl<Tag,version_major,version_minor>;
2424

25-
boost::asio::io_service * service_ptr;
25+
boost::shared_ptr<boost::asio::io_service> service_ptr;
2626
boost::asio::io_service & service_;
2727
resolver_type resolver_;
2828
optional<string_type> certificate_file, verify_path;
2929

3030
sync_client(bool cache_resolved, bool follow_redirect
31+
, boost::shared_ptr<boost::asio::io_service> service
3132
, optional<string_type> const & certificate_file = optional<string_type>()
3233
, optional<string_type> const & verify_path = optional<string_type>()
3334
)
3435
: connection_base(cache_resolved, follow_redirect),
35-
service_ptr(new boost::asio::io_service),
36+
service_ptr(service.get() ? service : make_shared<boost::asio::io_service>()),
3637
service_(*service_ptr),
3738
resolver_(service_)
3839
, certificate_file(certificate_file)
3940
, verify_path(verify_path)
4041
{}
4142

42-
sync_client(bool cache_resolved, bool follow_redirect, boost::asio::io_service & service
43-
, optional<string_type> const & certificate_file = optional<string_type>()
44-
, optional<string_type> const & verify_path = optional<string_type>()
45-
)
46-
: connection_base(cache_resolved, follow_redirect),
47-
service_ptr(0),
48-
service_(service),
49-
resolver_(service_)
50-
, certificate_file(certificate_file)
51-
, verify_path(verify_path)
52-
{}
53-
5443
~sync_client() {
5544
connection_base::cleanup();
56-
delete service_ptr;
45+
service_ptr.reset();
5746
}
5847

5948
basic_response<Tag> const request_skeleton(basic_request<Tag> const & request_, string_type method, bool get_body, body_callback_function_type callback) {

libs/network/example/http_client.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ int main(int argc, char * argv[]) {
6262
http_client::string_type destination_ = host(request);
6363

6464
request << ::boost::network::header("Connection", "close");
65-
http_client client(http::_follow_redirects=true);
65+
http_client::options client_options;
66+
http_client client(client_options.follow_redirects(true));
6667
http_client::response response = client.get(request);
6768

6869
if (show_headers) {

libs/network/test/http/client_constructor_test.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,14 @@
1212
namespace http = boost::network::http;
1313

1414
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_constructor_test, client, client_types) {
15+
typename client::options options;
1516
client instance;
16-
boost::asio::io_service io_service;
17-
client instance2(io_service);
18-
client instance3(http::_io_service=io_service);
17+
client instance2(options.io_service(boost::make_shared<boost::asio::io_service>()));
1918
}
2019

2120
BOOST_AUTO_TEST_CASE_TEMPLATE(http_cient_constructor_params_test, client, client_types) {
22-
client instance(
23-
http::_follow_redirects=true,
24-
http::_cache_resolved=true
25-
);
26-
boost::asio::io_service io_service;
27-
client instance2(
28-
http::_follow_redirects=true,
29-
http::_io_service=io_service,
30-
http::_cache_resolved=true
31-
);
32-
client instance3(
33-
http::_openssl_certificate="foo",
34-
http::_openssl_verify_path="bar"
35-
);
21+
typename client::options options;
22+
client instance(options.follow_redirects(true).cache_resolved(true));
23+
client instance2(options.openssl_certificate("foo").openssl_verify_path("bar"));
24+
client instance3(options.follow_redirects(true).io_service(boost::make_shared<boost::asio::io_service>()).cache_resolved(true));
3625
}

libs/network/test/http/client_get_streaming_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_streaming_test, client, async_only
3434
body_handler handler_instance(body_string);
3535
{
3636
client client_;
37-
BOOST_CHECK_NO_THROW( response = client_.get(request, http::_body_handler=handler_instance) );
37+
BOOST_CHECK_NO_THROW( response = client_.get(request, handler_instance) );
3838
typename net::headers_range<typename client::response>::type range = headers(response)["Content-Type"];
3939
BOOST_CHECK ( !boost::empty(range) );
4040
BOOST_CHECK_EQUAL ( body(response).size(), 0u );

libs/network/test/http/client_get_timeout_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_0, client, client_types) {
2020
BOOST_CHECK_EQUAL ( 12121, port_ );
2121
BOOST_CHECK_THROW ( response_ = client_.get(request); temp = body(response_); , std::exception );
2222
}
23-

0 commit comments

Comments
 (0)