Skip to content

Commit 19f108e

Browse files
committed
WIP: Removing dependency on Boost.Parameter.
1 parent 7976b1d commit 19f108e

File tree

11 files changed

+483
-238
lines changed

11 files changed

+483
-238
lines changed

boost/network/protocol/http/client.hpp

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_20091215
22
#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_20091215
33

4-
// Copyright Dean Michael Berris 2007-2010.
4+
// Copyright 2012 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2012 Google, Inc.
56
// Distributed under the Boost Software License, Version 1.0.
6-
// (See accompanying file LICENSE_1_0.txt or copy at
7-
// http://www.boost.org/LICENSE_1_0.txt)
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
89

910
#include <boost/network/version.hpp>
11+
#include <boost/network/protocol/http/client/options.hpp>
1012

1113
#include <boost/asio/io_service.hpp>
1214
#include <boost/network/protocol/http/client/facade.hpp>
@@ -27,43 +29,15 @@ struct client : basic_client_facade {
2729

2830
// Constructor
2931
// =================================================================
30-
// This is a Boost.Parameter-based constructor forwarder, whose
31-
// implementation is actually forwarded to the base type.
32+
// A client can be default constructed.
33+
client();
34+
// This is a simplified constructor that takes a reference to a const
35+
// client_options instance. To find out what the supported options are
36+
// see the boost/network/protocol/http/client/options.hpp file.
3237
//
33-
// The supported parameters are:
34-
// _follow_redirects : bool -- whether to follow HTTP redirect
35-
// responses (default: false)
36-
// _cache_resolved : bool -- whether to cache the resolved
37-
// endpoints (default: false)
38-
// _io_service : boost::asio::io_service &
39-
// -- supply an io_service to the
40-
// client
41-
// _openssl_certificate : string
42-
// -- the name of the certificate file
43-
// to use
44-
// _openssl_verify_path : string
45-
// -- the name of the directory from
46-
// which the certificate authority
47-
// files can be found
48-
// _connection_manager : shared_ptr<connection_manager>
49-
// -- The connection manager to use for
50-
// this client.
51-
52-
BOOST_PARAMETER_CONSTRUCTOR(
53-
client, (base_facade_type), tag,
54-
(optional
55-
(in_out(io_service), (boost::asio::io_service&))
56-
(follow_redirects, (bool))
57-
(cache_resolved, (bool))
58-
(openssl_certificate, (std::string))
59-
(openssl_verify_path, (std::string))
60-
(connection_manager, (shared_ptr<connection_manager>))
61-
(connection_factory, (shared_ptr<connection_factory>))
62-
))
63-
38+
explicit client(client_options const &options);
6439
//
6540
// =================================================================
66-
6741
};
6842

6943
} // namespace http

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ void boost::network::http::ssl_delegate::connect(
3333
socket_.reset(new asio::ssl::stream<asio::ip::tcp::socket>(service_, *context_));
3434
socket_->lowest_layer().async_connect(
3535
endpoint,
36-
::boost::bind(&boost::network::http::impl::ssl_delegate::handle_connected,
37-
boost::network::http::impl::ssl_delegate::shared_from_this(),
36+
::boost::bind(&boost::network::http::ssl_delegate::handle_connected,
37+
boost::network::http::ssl_delegate::shared_from_this(),
3838
asio::placeholders::error,
3939
handler));
4040
}

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

Lines changed: 21 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -9,170 +9,37 @@
99
#include <boost/network/protocol/http/request.hpp>
1010
#include <boost/network/protocol/http/response.hpp>
1111
#include <boost/network/protocol/http/client/base.hpp>
12-
#include <boost/network/protocol/http/client/parameters.hpp>
13-
#include <boost/network/protocol/http/client/connection/simple_connection_factory.hpp>
14-
#include <boost/network/protocol/http/client/simple_connection_manager.hpp>
12+
#include <boost/network/protocol/http/client/options.hpp>
1513

1614
namespace boost { namespace network { namespace http {
1715

1816
struct basic_client_facade {
1917
typedef client_base::body_callback_function_type body_callback_function_type;
2018

21-
template <class ArgPack>
22-
basic_client_facade(ArgPack const & args) {
23-
init_base(args,
24-
typename mpl::if_<
25-
is_same<
26-
typename parameter::value_type<ArgPack, tag::io_service, void>::type,
27-
void
28-
>,
29-
no_io_service,
30-
has_io_service
31-
>::type());
32-
}
19+
basic_client_facade(client_options const &options);
20+
21+
response const head(request const &request, request_options const&options=request_options());
22+
response const get(request const &request,
23+
body_callback_function_type body_handler = body_callback_function_type(),
24+
request_options const &options=request_options());
25+
response const post(request request,
26+
optional<std::string> body = optional<std::string>(),
27+
optional<std::string> content_type = optional<std::string>(),
28+
body_callback_function_type body_handler = body_callback_function_type(),
29+
request_options const&options = request_options());
30+
response const put(request request,
31+
optional<std::string> body = optional<std::string>(),
32+
optional<std::string> content_type = optional<std::string>(),
33+
body_callback_function_type body_handler = body_callback_function_type(),
34+
request_options const & options = request_options());
35+
response const delete_(request const & request,
36+
body_callback_function_type body_handler = body_callback_function_type(),
37+
request_options const & options = request_options());
38+
void clear_resolved_cache();
3339

34-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), head, tag, (required (request,(request const &)))) {
35-
return base->request_skeleton(request, "HEAD", false, body_callback_function_type());
36-
}
37-
38-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), get , tag,
39-
(required
40-
(request,(request const &))
41-
)
42-
(optional
43-
(body_handler,(body_callback_function_type),body_callback_function_type())
44-
)) {
45-
return base->request_skeleton(request, "GET", true, body_handler);
46-
}
47-
48-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), post, tag,
49-
(required
50-
(request,(request)) // yes sir, we make a copy of the original request.
51-
)
52-
(optional
53-
(body,(std::string const &),std::string())
54-
(content_type,(std::string const &),std::string())
55-
(body_handler,(body_callback_function_type),body_callback_function_type())
56-
)) {
57-
if (body.size()) {
58-
request << remove_header("Content-Length")
59-
<< header("Content-Length", boost::lexical_cast<std::string>(body.size()))
60-
<< boost::network::body(body);
61-
}
62-
63-
std::multimap<std::string, std::string> content_type_headers =
64-
headers(request)["Content-Type"];
65-
if (content_type.size()) {
66-
if (!boost::empty(content_type_headers))
67-
request << remove_header("Content-Type");
68-
request << header("Content-Type", content_type);
69-
} else {
70-
if (boost::empty(content_type_headers)) {
71-
static char content_type[] = "x-application/octet-stream";
72-
request << header("Content-Type", content_type);
73-
}
74-
}
75-
return base->request_skeleton(request, "POST", true, body_handler);
76-
}
77-
78-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), put , tag,
79-
(required
80-
(request,(request)) // yes sir, we make a copy of the original request.
81-
)
82-
(optional
83-
(body,(std::string const &),std::string())
84-
(content_type,(std::string const &),std::string())
85-
(body_handler,(body_callback_function_type),body_callback_function_type())
86-
)) {
87-
if (body != std::string()) {
88-
request << remove_header("Content-Length")
89-
<< header("Content-Length", boost::lexical_cast<std::string>(body.size()))
90-
<< boost::network::body(body);
91-
}
92-
93-
std::multimap<std::string, std::string> content_type_headers =
94-
headers(request)["Content-Type"];
95-
if (content_type.size()) {
96-
if (!boost::empty(content_type_headers))
97-
request << remove_header("Content-Type");
98-
request << header("Content-Type", content_type);
99-
} else {
100-
if (boost::empty(content_type_headers)) {
101-
static char content_type[] = "x-application/octet-stream";
102-
request << header("Content-Type", content_type);
103-
}
104-
}
105-
return base->request_skeleton(request, "PUT", true, body_handler);
106-
}
107-
108-
BOOST_PARAMETER_MEMBER_FUNCTION((response const), delete_, tag,
109-
(required
110-
(request,(request const &))
111-
)
112-
(optional
113-
(body_handler,(body_callback_function_type),body_callback_function_type())
114-
)) {
115-
return base->request_skeleton(request, "DELETE", true, body_handler);
116-
}
117-
118-
void clear_resolved_cache() {
119-
base->clear_resolved_cache();
120-
}
12140

12241
protected:
123-
124-
struct no_io_service {};
125-
struct has_io_service {};
126-
12742
boost::scoped_ptr<client_base> base;
128-
129-
template <class ArgPack>
130-
void init_base(ArgPack const & args, no_io_service) {
131-
base.reset(new client_base(
132-
this->get_connection_manager(args)));
133-
}
134-
135-
template <class ArgPack>
136-
void init_base(ArgPack const & args, has_io_service) {
137-
base.reset(
138-
new client_base(
139-
args[_io_service],
140-
this->get_connection_manager(args)));
141-
}
142-
143-
private:
144-
145-
template <class ArgPack>
146-
shared_ptr<connection_manager> get_connection_manager(ArgPack const & args) {
147-
shared_ptr<connection_manager> connection_manager_ = args[_connection_manager|shared_ptr<connection_manager>()];
148-
if (!connection_manager_.get()) {
149-
// Because there's no explicit connection manager, we use the default
150-
// implementation.
151-
connection_manager_.reset(
152-
new (std::nothrow) simple_connection_manager(
153-
args[_cache_resolved|false],
154-
args[_follow_redirects|false],
155-
args[_openssl_certificate|optional<std::string>()],
156-
args[_openssl_verify_path|optional<std::string>()],
157-
this->get_connection_factory(args)));
158-
}
159-
160-
return connection_manager_;
161-
}
162-
163-
template <class ArgPack>
164-
shared_ptr<connection_factory> get_connection_factory(ArgPack const & args) {
165-
shared_ptr<connection_factory> connection_factory_ = args[_connection_factory|shared_ptr<connection_factory>()];
166-
if (!connection_factory_.get()) {
167-
// Because there's no explicit connection factory, we use the default
168-
// implementation.
169-
connection_factory_.reset(
170-
new (std::nothrow) simple_connection_factory());
171-
}
172-
173-
return connection_factory_;
174-
}
175-
17643
};
17744

17845
} // namespace http
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_FACADE_IPP_20120303
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_FACADE_IPP_20120303
3+
4+
#include <boost/network/protocol/http/client/facade.hpp>
5+
6+
namespace boost { namespace network { namespace http {
7+
8+
response const basic_client_facade::head(request const &request,
9+
request_options const&options) {
10+
return base->request_skeleton(request,
11+
"HEAD",
12+
false,
13+
body_callback_function_type(),
14+
options);
15+
}
16+
17+
response const basic_client_facade::get(request const &request,
18+
body_callback_function_type body_handler,
19+
request_options const &options) {
20+
return base->request_skeleton(request, "GET", true, body_handler, options);
21+
}
22+
23+
response const basic_client_facade::post(request request,
24+
optional<std::string> body,
25+
optional<std::string> content_type,
26+
body_callback_function_type body_handler,
27+
request_options const &options) {
28+
if (body) {
29+
request << remove_header("Content-Length")
30+
<< header("Content-Length", boost::lexical_cast<std::string>(body->size()))
31+
<< boost::network::body(*body);
32+
}
33+
34+
std::multimap<std::string, std::string> content_type_headers =
35+
headers(request)["Content-Type"];
36+
if (content_type) {
37+
if (!boost::empty(content_type_headers))
38+
request << remove_header("Content-Type");
39+
request << header("Content-Type", *content_type);
40+
} else {
41+
if (boost::empty(content_type_headers)) {
42+
static char default_content_type[] = "x-application/octet-stream";
43+
request << header("Content-Type", default_content_type);
44+
}
45+
}
46+
return base->request_skeleton(request, "POST", true, body_handler, options);
47+
}
48+
49+
response const basic_client_facade::put(request request,
50+
optional<std::string> body,
51+
optional<std::string> content_type,
52+
body_callback_function_type body_handler,
53+
request_options const & options) {
54+
if (body) {
55+
request << remove_header("Content-Length")
56+
<< header("Content-Length", boost::lexical_cast<std::string>(body->size()))
57+
<< boost::network::body(*body);
58+
}
59+
60+
std::multimap<std::string, std::string> content_type_headers =
61+
headers(request)["Content-Type"];
62+
if (content_type) {
63+
if (!boost::empty(content_type_headers))
64+
request << remove_header("Content-Type");
65+
request << header("Content-Type", *content_type);
66+
} else {
67+
if (boost::empty(content_type_headers)) {
68+
static char default_content_type[] = "x-application/octet-stream";
69+
request << header("Content-Type", default_content_type);
70+
}
71+
}
72+
return base->request_skeleton(request, "PUT", true, body_handler);
73+
}
74+
75+
response const basic_client_facade::delete_(request const & request,
76+
body_callback_function_type body_handler,
77+
request_options const & options) {
78+
return base->request_skeleton(request, "DELETE", true, body_handler);
79+
}
80+
81+
void basic_client_facade::clear_resolved_cache() {
82+
base->clear_resolved_cache();
83+
}
84+
85+
} // namespace http
86+
87+
} // namespace network
88+
89+
} // namespace boost
90+
91+
92+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_FACADE_IPP_20120303
93+

0 commit comments

Comments
 (0)