|
9 | 9 | #include <boost/network/protocol/http/request.hpp>
|
10 | 10 | #include <boost/network/protocol/http/response.hpp>
|
11 | 11 | #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> |
15 | 13 |
|
16 | 14 | namespace boost { namespace network { namespace http {
|
17 | 15 |
|
18 | 16 | struct basic_client_facade {
|
19 | 17 | typedef client_base::body_callback_function_type body_callback_function_type;
|
20 | 18 |
|
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(); |
33 | 39 |
|
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 |
| - } |
121 | 40 |
|
122 | 41 | protected:
|
123 |
| - |
124 |
| - struct no_io_service {}; |
125 |
| - struct has_io_service {}; |
126 |
| - |
127 | 42 | 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 |
| - |
176 | 43 | };
|
177 | 44 |
|
178 | 45 | } // namespace http
|
|
0 commit comments