|
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 | namespaceboost {namespacenetwork {namespacehttp {namespaceimpl { |
17 | 16 |
|
18 | | -template<classTag,unsigned version_major,unsigned version_minor> |
19 | | -structasync_connection_base { |
20 | | -typedeftypename resolver_policy<Tag>::type resolver_base; |
21 | | -typedeftypename resolver_base::resolver_type resolver_type; |
22 | | -typedeftypename resolver_base::resolve_function resolve_function; |
23 | | -typedeftypename string<Tag>::type string_type; |
24 | | -typedef basic_request<Tag> request; |
25 | | -typedef basic_response<Tag> response; |
26 | | -typedef |
27 | | - function<void(iterator_range<charconst *>const &, system::error_codeconst &)> |
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 | | -throwstd::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 responsestart(requestconst & request, string_typeconst & method,bool get_body, body_callback_function_type callback) = 0; |
46 | | - |
47 | | -virtual~async_connection_base() {} |
48 | | - |
49 | | - }; |
| 17 | +template<classTag,unsigned version_major,unsigned version_minor> |
| 18 | +structasync_connection_base { |
| 19 | +typedef async_connection_base<Tag,version_major,version_minor> this_type; |
| 20 | +typedeftypename resolver_policy<Tag>::type resolver_base; |
| 21 | +typedeftypename resolver_base::resolver_type resolver_type; |
| 22 | +typedeftypename resolver_base::resolve_function resolve_function; |
| 23 | +typedeftypename string<Tag>::type string_type; |
| 24 | +typedef basic_request<Tag> request; |
| 25 | +typedef basic_response<Tag> response; |
| 26 | +typedef iterator_range<charconst *> char_const_range; |
| 27 | +typedef function<void(char_const_rangeconst &, system::error_codeconst &)> |
| 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_ptrnew_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 | +typedeftypename delegate_factory<Tag>::type delegate_factory_type; |
| 44 | + connection_ptr temp; |
| 45 | + temp.reset( |
| 46 | +newasync_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 responsestart( |
| 61 | + requestconst & request, |
| 62 | + string_typeconst & 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 |
|
|