8
8
// http://www.boost.org/LICENSE_1_0.txt)
9
9
10
10
#include < boost/network/version.hpp>
11
+ #include < boost/network/detail/debug.hpp>
11
12
#include < boost/thread/future.hpp>
12
13
#include < boost/throw_exception.hpp>
13
14
#include < boost/cstdint.hpp>
@@ -237,7 +238,7 @@ namespace boost { namespace network { namespace http { namespace impl {
237
238
boost::bind (
238
239
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
239
240
http_async_connection<Tag,version_major,version_minor>::shared_from_this (),
240
- body , get_body, callback,
241
+ headers , get_body, callback,
241
242
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
242
243
)
243
244
)
@@ -247,29 +248,43 @@ namespace boost { namespace network { namespace http { namespace impl {
247
248
this ->body_promise .set_value (" " );
248
249
return ;
249
250
}
250
- this ->parse_body (
251
- *socket_,
252
- request_strand_.wrap (
253
- boost::bind (
254
- &http_async_connection<Tag,version_major,version_minor>::handle_received_data,
255
- http_async_connection<Tag,version_major,version_minor>::shared_from_this (),
256
- body, get_body, callback,
257
- boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
258
- )
259
- ),
260
- remainder );
261
- break ;
262
- case body:
263
- if (!get_body) {
251
+ if (callback) {
252
+ typename protocol_base::buffer_type::const_iterator begin = this ->part .begin ();
253
+ std::advance (begin, remainder );
254
+ typename protocol_base::buffer_type::const_iterator end = begin;
255
+ std::advance (end, this ->part .size () - remainder );
256
+ callback (make_iterator_range (begin, end), ec);
257
+ socket_->async_read_some (
258
+ boost::asio::mutable_buffers_1 (this ->part .c_array (), this ->part .size ()),
259
+ request_strand_.wrap (
260
+ boost::bind (
261
+ &http_async_connection<Tag,version_major,version_minor>::handle_received_data,
262
+ http_async_connection<Tag,version_major,version_minor>::shared_from_this (),
263
+ body, get_body, callback,
264
+ boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)
265
+ )
266
+ );
264
267
this ->body_promise .set_value (" " );
265
- return ;
268
+ } else {
269
+ this ->parse_body (
270
+ *socket_,
271
+ request_strand_.wrap (
272
+ boost::bind (
273
+ &http_async_connection<Tag,version_major,version_minor>::handle_received_data,
274
+ http_async_connection<Tag,version_major,version_minor>::shared_from_this (),
275
+ body, get_body, callback,
276
+ boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
277
+ )
278
+ ),
279
+ remainder );
266
280
}
281
+ break ;
282
+ case body:
267
283
if (ec == boost::asio::error::eof) {
268
- if (! callback. empty () ) {
284
+ if (callback) {
269
285
typename protocol_base::buffer_type::const_iterator begin = this ->part .begin (), end = begin;
270
286
std::advance (end, bytes_transferred);
271
287
callback (make_iterator_range (begin, end), ec);
272
- this ->body_promise .set_value (" " );
273
288
} else {
274
289
string_type body_string;
275
290
std::swap (body_string, this ->partial_parsed );
@@ -285,7 +300,7 @@ namespace boost { namespace network { namespace http { namespace impl {
285
300
this ->part .assign (' \0 ' );
286
301
this ->response_parser_ .reset ();
287
302
} else {
288
- if (! callback. empty () ) {
303
+ if (callback) {
289
304
typename protocol_base::buffer_type::const_iterator begin = this ->part .begin (), end = begin;
290
305
std::advance (end, bytes_transferred);
291
306
callback (make_iterator_range (begin, end), ec);
0 commit comments