|
8 | 8 | // http://www.boost.org/LICENSE_1_0.txt)
|
9 | 9 |
|
10 | 10 | #include <boost/network/protocol/http/response.hpp>
|
| 11 | +#include <boost/network/protocol/http/client/connection/connection_delegate_factory.hpp> |
| 12 | +#include <boost/network/protocol/http/traits/delegate_factory.hpp> |
11 | 13 | #include <boost/network/protocol/http/client/connection/async_normal.hpp>
|
12 |
| -#ifdef BOOST_NETWORK_ENABLE_HTTPS |
13 |
| -#include <boost/network/protocol/http/client/connection/async_ssl.hpp> |
14 |
| -#endif |
15 | 14 |
|
16 | 15 | namespace boost { namespace network { namespace http { namespace impl {
|
17 | 16 |
|
18 |
| - template <class Tag, unsigned version_major, unsigned version_minor> |
19 |
| - struct async_connection_base { |
20 |
| - typedef typename resolver_policy<Tag>::type resolver_base; |
21 |
| - typedef typename resolver_base::resolver_type resolver_type; |
22 |
| - typedef typename resolver_base::resolve_function resolve_function; |
23 |
| - typedef typename string<Tag>::type string_type; |
24 |
| - typedef basic_request<Tag> request; |
25 |
| - typedef basic_response<Tag> response; |
26 |
| - typedef |
27 |
| - function<void(iterator_range<char const *> const &, system::error_code const &)> |
28 |
| - body_callback_function_type; |
29 |
| - |
30 |
| - static boost::shared_ptr<async_connection_base<Tag,version_major,version_minor> > new_connection(resolve_function resolve, resolver_type & resolver, bool follow_redirect, bool https, optional<string_type> certificate_filename=optional<string_type>(), optional<string_type> const & verify_path=optional<string_type>()) { |
31 |
| - boost::shared_ptr<async_connection_base<Tag,version_major,version_minor> > temp; |
32 |
| - if (https) { |
33 |
| -#ifdef BOOST_NETWORK_ENABLE_HTTPS |
34 |
| - temp.reset(new https_async_connection<Tag,version_major,version_minor>(resolver, resolve, follow_redirect, certificate_filename, verify_path)); |
35 |
| - return temp; |
36 |
| -#else |
37 |
| - throw std::runtime_error("HTTPS not supported."); |
38 |
| -#endif |
39 |
| - } |
40 |
| - temp.reset(new http_async_connection<Tag,version_major,version_minor>(resolver, resolve, follow_redirect)); |
41 |
| - assert(temp.get() != 0); |
42 |
| - return temp; |
43 |
| - } |
44 |
| - |
45 |
| - virtual response start(request const & request, string_type const & method, bool get_body, body_callback_function_type callback) = 0; |
46 |
| - |
47 |
| - virtual ~async_connection_base() {} |
48 |
| - |
49 |
| - }; |
| 17 | + template <class Tag, unsigned version_major, unsigned version_minor> |
| 18 | + struct async_connection_base { |
| 19 | + typedef async_connection_base<Tag,version_major,version_minor> this_type; |
| 20 | + typedef typename resolver_policy<Tag>::type resolver_base; |
| 21 | + typedef typename resolver_base::resolver_type resolver_type; |
| 22 | + typedef typename resolver_base::resolve_function resolve_function; |
| 23 | + typedef typename string<Tag>::type string_type; |
| 24 | + typedef basic_request<Tag> request; |
| 25 | + typedef basic_response<Tag> response; |
| 26 | + typedef iterator_range<char const *> char_const_range; |
| 27 | + typedef function<void(char_const_range const &, system::error_code const &)> |
| 28 | + body_callback_function_type; |
| 29 | + typedef shared_ptr<this_type> connection_ptr; |
| 30 | + |
| 31 | + // This is the factory function which constructs the appropriate async |
| 32 | + // connection implementation with the correct delegate chosen based on the |
| 33 | + // tag. |
| 34 | + static connection_ptr new_connection( |
| 35 | + resolve_function resolve, |
| 36 | + resolver_type & resolver, |
| 37 | + bool follow_redirect, |
| 38 | + bool https, |
| 39 | + optional<string_type> certificate_filename=optional<string_type>(), |
| 40 | + optional<string_type> const & verify_path=optional<string_type>()) { |
| 41 | + typedef http_async_connection<Tag,version_major,version_minor> |
| 42 | + async_connection; |
| 43 | + typedef typename delegate_factory<Tag>::type delegate_factory_type; |
| 44 | + connection_ptr temp; |
| 45 | + temp.reset( |
| 46 | + new async_connection( |
| 47 | + resolver, |
| 48 | + resolve, |
| 49 | + follow_redirect, |
| 50 | + delegate_factory_type::new_connection_delegate( |
| 51 | + resolver.get_io_service(), |
| 52 | + https, |
| 53 | + certificate_filename, |
| 54 | + verify_path))); |
| 55 | + BOOST_ASSERT(temp.get() != 0); |
| 56 | + return temp; |
| 57 | + } |
| 58 | + |
| 59 | + // This is the pure virtual entry-point for all asynchronous connections. |
| 60 | + virtual response start( |
| 61 | + request const & request, |
| 62 | + string_type const & method, |
| 63 | + bool get_body, |
| 64 | + body_callback_function_type callback) = 0; |
| 65 | + |
| 66 | + virtual ~async_connection_base() {} |
| 67 | + |
| 68 | + }; |
50 | 69 |
|
51 | 70 | } // namespace impl
|
52 | 71 |
|
|
0 commit comments