@@ -118,7 +118,7 @@ struct http_async_connection
118
118
}
119
119
120
120
private:
121
- void set_errors (std::error_code const & ec) {
121
+ void set_errors (std::error_code const & ec, body_callback_function_type callback ) {
122
122
std::system_error error (ec);
123
123
this ->version_promise .set_exception (std::make_exception_ptr (error));
124
124
this ->status_promise .set_exception (std::make_exception_ptr (error));
@@ -127,6 +127,8 @@ struct http_async_connection
127
127
this ->source_promise .set_exception (std::make_exception_ptr (error));
128
128
this ->destination_promise .set_exception (std::make_exception_ptr (error));
129
129
this ->body_promise .set_exception (std::make_exception_ptr (error));
130
+ if ( callback )
131
+ callback ( boost::iterator_range<const char *>(), ec );
130
132
this ->timer_ .cancel ();
131
133
}
132
134
@@ -155,9 +157,7 @@ struct http_async_connection
155
157
generator, std::make_pair (++iter_copy, resolver_iterator ()), ec);
156
158
}));
157
159
} else {
158
- set_errors (ec ? ec : ::asio::error::host_not_found);
159
- boost::iterator_range<const char *> range;
160
- if (callback) callback (range, ec);
160
+ set_errors ((ec ? ec : ::asio::error::host_not_found), callback);
161
161
}
162
162
}
163
163
@@ -168,7 +168,7 @@ struct http_async_connection
168
168
resolver_iterator_pair endpoint_range,
169
169
std::error_code const & ec) {
170
170
if (is_timedout_) {
171
- set_errors (::asio::error::timed_out);
171
+ set_errors (::asio::error::timed_out, callback );
172
172
} else if (!ec) {
173
173
BOOST_ASSERT (delegate_.get () != 0 );
174
174
auto self = this ->shared_from_this ();
@@ -193,9 +193,7 @@ struct http_async_connection
193
193
ec);
194
194
}));
195
195
} else {
196
- set_errors (ec ? ec : ::asio::error::host_not_found);
197
- boost::iterator_range<const char *> range;
198
- if (callback) callback (range, ec);
196
+ set_errors ((ec ? ec : ::asio::error::host_not_found), callback);
199
197
}
200
198
}
201
199
}
@@ -239,7 +237,7 @@ struct http_async_connection
239
237
ec, bytes_transferred);
240
238
}));
241
239
} else {
242
- set_errors (is_timedout_ ? ::asio::error::timed_out : ec);
240
+ set_errors (( is_timedout_ ? ::asio::error::timed_out : ec), callback );
243
241
}
244
242
}
245
243
@@ -322,6 +320,8 @@ struct http_async_connection
322
320
// We short-circuit here because the user does not want to get the
323
321
// body (in the case of a HEAD request).
324
322
this ->body_promise .set_value (" " );
323
+ if ( callback )
324
+ callback ( boost::iterator_range<const char *>(), ::asio::error::eof );
325
325
this ->destination_promise .set_value (" " );
326
326
this ->source_promise .set_value (" " );
327
327
// this->part.assign('\0');
@@ -446,8 +446,8 @@ struct http_async_connection
446
446
BOOST_ASSERT (false && " Bug, report this to the developers!" );
447
447
}
448
448
} else {
449
- std::system_error error ( is_timedout_ ? ::asio::error::timed_out
450
- : ec );
449
+ std::error_code report_code = is_timedout_ ? ::asio::error::timed_out : ec;
450
+ std::system_error error (report_code );
451
451
this ->source_promise .set_exception (std::make_exception_ptr (error));
452
452
this ->destination_promise .set_exception (std::make_exception_ptr (error));
453
453
switch (state) {
@@ -467,6 +467,8 @@ struct http_async_connection
467
467
// so no exception should be set
468
468
this ->body_promise .set_exception (std::make_exception_ptr (error));
469
469
}
470
+ else
471
+ callback ( boost::iterator_range<const char *>(), report_code );
470
472
break ;
471
473
default :
472
474
BOOST_ASSERT (false && " Bug, report this to the developers!" );
0 commit comments