9
9
10
10
#include < boost/asio/placeholders.hpp>
11
11
#include < boost/network/protocol/http/client/connection/async_normal.hpp>
12
+ #include < boost/network/protocol/http/algorithms/linearize.hpp>
13
+ #include < boost/asio/strand.hpp>
12
14
13
15
namespace boost { namespace network { namespace http {
14
16
15
17
namespace placeholders = boost::asio::placeholders;
16
18
17
19
struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_connection_pimpl>
18
20
{
21
+ typedef http_async_connection::callback_type body_callback_function_type;
22
+ typedef resolver_delegate::resolver_iterator resolver_iterator;
23
+ typedef resolver_delegate::iterator_pair resolver_iterator_pair;
24
+
19
25
http_async_connection_pimpl (
20
- resolver_delegate_ptr resolver_delegate,
26
+ shared_ptr<resolver_delegate> resolver_delegate,
27
+ shared_ptr<connection_delegate> connection_delegate,
21
28
asio::io_service & io_service,
22
- bool follow_redirect,
23
- connection_delegate_ptr delegate)
29
+ bool follow_redirect)
24
30
:
25
31
follow_redirect_ (follow_redirect),
26
32
request_strand_ (io_service),
27
33
resolver_delegate_ (resolver_delegate),
28
- delegate_ (delegate ) {}
34
+ connection_delegate_ (connection_delegate ) {}
29
35
30
36
// This is the main entry point for the connection/request pipeline. We're
31
37
// overriding async_connection_base<...>::start(...) here which is called
32
38
// by the client.
33
39
response start (request const & request,
34
- string_type const & method,
40
+ std::string const & method,
35
41
bool get_body,
36
42
body_callback_function_type callback) {
37
43
response response_;
38
- this ->init_response (response_, get_body);
39
- linearize (request, method, version_major, version_minor,
40
- std::ostreambuf_iterator<typename char_<Tag>::type>(&command_streambuf));
44
+ linearize (request, method, 1 , 1 ,
45
+ std::ostreambuf_iterator<char >(&command_streambuf));
41
46
this ->method = method;
42
47
boost::uint16_t port_ = port (request);
43
48
resolver_delegate_->resolve (
@@ -61,13 +66,14 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
61
66
62
67
void set_errors (boost::system::error_code const & ec) {
63
68
boost::system::system_error error (ec);
64
- this ->version_promise .set_exception (boost::copy_exception (error));
65
- this ->status_promise .set_exception (boost::copy_exception (error));
66
- this ->status_message_promise .set_exception (boost::copy_exception (error));
67
- this ->headers_promise .set_exception (boost::copy_exception (error));
68
- this ->source_promise .set_exception (boost::copy_exception (error));
69
- this ->destination_promise .set_exception (boost::copy_exception (error));
70
- this ->body_promise .set_exception (boost::copy_exception (error));
69
+ // FIXME: Wire up the response object for errors.
70
+ // this->version_promise.set_exception(boost::copy_exception(error));
71
+ // this->status_promise.set_exception(boost::copy_exception(error));
72
+ // this->status_message_promise.set_exception(boost::copy_exception(error));
73
+ // this->headers_promise.set_exception(boost::copy_exception(error));
74
+ // this->source_promise.set_exception(boost::copy_exception(error));
75
+ // this->destination_promise.set_exception(boost::copy_exception(error));
76
+ // this->body_promise.set_exception(boost::copy_exception(error));
71
77
}
72
78
73
79
void handle_resolved (boost::uint16_t port,
@@ -80,7 +86,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
80
86
// that there's still more endpoints to try connecting to.
81
87
resolver_iterator iter = boost::begin (endpoint_range);
82
88
asio::ip::tcp::endpoint endpoint (iter->endpoint ().address (), port);
83
- delegate_ ->connect (endpoint,
89
+ connection_delegate_ ->connect (endpoint,
84
90
request_strand_.wrap (
85
91
boost::bind (
86
92
&this_type::handle_connected,
@@ -102,8 +108,8 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
102
108
resolver_iterator_pair endpoint_range,
103
109
boost::system::error_code const & ec) {
104
110
if (!ec) {
105
- BOOST_ASSERT (delegate_ .get () != 0 );
106
- delegate_ ->write (command_streambuf,
111
+ BOOST_ASSERT (connection_delegate_ .get () != 0 );
112
+ connection_delegate_ ->write (command_streambuf,
107
113
request_strand_.wrap (
108
114
boost::bind (
109
115
&this_type::handle_sent_request,
@@ -116,7 +122,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
116
122
if (!boost::empty (endpoint_range)) {
117
123
resolver_iterator iter = boost::begin (endpoint_range);
118
124
asio::ip::tcp::endpoint endpoint (iter->endpoint ().address (), port);
119
- delegate_ ->connect (endpoint,
125
+ connection_delegate_ ->connect (endpoint,
120
126
request_strand_.wrap (
121
127
boost::bind (
122
128
&this_type::handle_connected,
@@ -142,7 +148,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
142
148
boost::system::error_code const & ec,
143
149
std::size_t bytes_transferred) {
144
150
if (!ec) {
145
- delegate_ ->read_some (
151
+ connection_delegate_ ->read_some (
146
152
boost::asio::mutable_buffers_1 (this ->part .c_array (),
147
153
this ->part .size ()),
148
154
request_strand_.wrap (
@@ -163,7 +169,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
163
169
switch (state) {
164
170
case version:
165
171
parsed_ok =
166
- this ->parse_version (delegate_ ,
172
+ this ->parse_version (connection_delegate_ ,
167
173
request_strand_.wrap (
168
174
boost::bind (
169
175
&this_type::handle_received_data,
@@ -175,7 +181,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
175
181
if (!parsed_ok || indeterminate (parsed_ok)) return ;
176
182
case status:
177
183
parsed_ok =
178
- this ->parse_status (delegate_ ,
184
+ this ->parse_status (connection_delegate_ ,
179
185
request_strand_.wrap (
180
186
boost::bind (
181
187
&this_type::handle_received_data,
@@ -187,7 +193,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
187
193
if (!parsed_ok || indeterminate (parsed_ok)) return ;
188
194
case status_message:
189
195
parsed_ok =
190
- this ->parse_status_message (delegate_ ,
196
+ this ->parse_status_message (connection_delegate_ ,
191
197
request_strand_.wrap (
192
198
boost::bind (
193
199
&this_type::handle_received_data,
@@ -205,7 +211,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
205
211
// that the data remaining in the buffer is dealt with before
206
212
// another call to get more data for the body is scheduled.
207
213
fusion::tie (parsed_ok, remainder) =
208
- this ->parse_headers (delegate_ ,
214
+ this ->parse_headers (connection_delegate_ ,
209
215
request_strand_.wrap (
210
216
boost::bind (
211
217
&this_type::handle_received_data,
@@ -251,7 +257,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
251
257
// wait before scheduling another read.
252
258
callback (make_iterator_range (begin, end), ec);
253
259
254
- delegate_ ->read_some (
260
+ connection_delegate_ ->read_some (
255
261
boost::asio::mutable_buffers_1 (this ->part .c_array (),
256
262
this ->part .size ()),
257
263
request_strand_.wrap (
@@ -266,7 +272,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
266
272
// Here we handle the body data ourself and append to an
267
273
// ever-growing string buffer.
268
274
this ->parse_body (
269
- delegate_ ,
275
+ connection_delegate_ ,
270
276
request_strand_.wrap (
271
277
boost::bind (
272
278
&this_type::handle_received_data,
@@ -295,7 +301,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
295
301
// it appropriately.
296
302
callback (make_iterator_range (begin, end), ec);
297
303
} else {
298
- string_type body_string;
304
+ std::string body_string;
299
305
std::swap (body_string, this ->partial_parsed );
300
306
body_string.append (
301
307
this ->part .begin ()
@@ -319,7 +325,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
319
325
typename protocol_base::buffer_type::const_iterator end = begin;
320
326
std::advance (end, bytes_transferred);
321
327
callback (make_iterator_range (begin, end), ec);
322
- delegate_ ->read_some (
328
+ connection_delegate_ ->read_some (
323
329
boost::asio::mutable_buffers_1 (
324
330
this ->part .c_array (),
325
331
this ->part .size ()),
@@ -337,7 +343,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
337
343
// make sure that we deal with the remainder
338
344
// from the headers part in case we do have data
339
345
// that's still in the buffer.
340
- this ->parse_body (delegate_ ,
346
+ this ->parse_body (connection_delegate_ ,
341
347
request_strand_.wrap (
342
348
boost::bind (
343
349
&this_type::handle_received_data,
@@ -360,16 +366,16 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
360
366
this ->destination_promise .set_exception (boost::copy_exception (error));
361
367
switch (state) {
362
368
case version:
363
- this ->version_promise .set_exception (boost::copy_exception (error));
369
+ // this->version_promise.set_exception(boost::copy_exception(error));
364
370
case status:
365
- this ->status_promise .set_exception (boost::copy_exception (error));
371
+ // this->status_promise.set_exception(boost::copy_exception(error));
366
372
case status_message:
367
- this ->status_message_promise .set_exception (boost::copy_exception (error));
373
+ // this->status_message_promise.set_exception(boost::copy_exception(error));
368
374
case headers:
369
- this ->headers_promise .set_exception (boost::copy_exception (error));
375
+ // this->headers_promise.set_exception(boost::copy_exception(error));
370
376
case body:
371
- this ->body_promise .set_exception (boost::copy_exception (error));
372
- break ;
377
+ // this->body_promise.set_exception(boost::copy_exception(error));
378
+ // break;
373
379
default :
374
380
BOOST_ASSERT (false && " Bug, report this to the developers!" );
375
381
}
@@ -378,10 +384,10 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
378
384
379
385
bool follow_redirect_;
380
386
boost::asio::io_service::strand request_strand_;
381
- resolver_delegate_ptr resolver_delegate_;
382
- connection_delegate_ptr delegate_ ;
387
+ shared_ptr<resolver_delegate> resolver_delegate_;
388
+ shared_ptr<connection_delegate> connection_delegate_ ;
383
389
boost::asio::streambuf command_streambuf;
384
- string_type method;
390
+ std::string method;
385
391
};
386
392
387
393
// END OF PIMPL DEFINITION
0 commit comments