@@ -433,8 +433,11 @@ struct http_async_connection
433
433
434
434
// The invocation of the callback is synchronous to allow us to
435
435
// wait before scheduling another read.
436
- callback (make_iterator_range (begin, end), ec);
437
-
436
+ if (this ->is_chunk_encoding && remove_chunk_markers_) {
437
+ callback (parse_chunk_encoding (make_iterator_range (begin, end)), ec);
438
+ }else {
439
+ callback (make_iterator_range (begin, end), ec);
440
+ }
438
441
auto self =this ->shared_from_this ();
439
442
delegate_->read_some (
440
443
boost::asio::mutable_buffers_1 (this ->part .data (),
@@ -473,7 +476,11 @@ struct http_async_connection
473
476
// We call the callback function synchronously passing the error
474
477
// condition (in this case, end of file) so that it can handle it
475
478
// appropriately.
476
- callback (make_iterator_range (begin, end), ec);
479
+ if (this ->is_chunk_encoding && remove_chunk_markers_) {
480
+ callback (parse_chunk_encoding (make_iterator_range (begin, end)), ec);
481
+ }else {
482
+ callback (make_iterator_range (begin, end), ec);
483
+ }
477
484
}else {
478
485
string_type body_string;
479
486
if (this ->is_chunk_encoding && remove_chunk_markers_) {
@@ -490,9 +497,7 @@ struct http_async_connection
490
497
this ->body_promise .set_value (body_string);
491
498
}else {
492
499
std::swap (body_string,this ->partial_parsed );
493
- auto it =this ->part .begin ();
494
- std::advance (it, bytes_transferred);
495
- body_string.append (this ->part .begin (), it);
500
+ body_string.append (this ->part .begin (),this ->part .begin () + bytes_transferred);
496
501
this ->body_promise .set_value (body_string);
497
502
}
498
503
}
@@ -514,7 +519,11 @@ struct http_async_connection
514
519
this ->part .begin ();
515
520
typename protocol_base::buffer_type::const_iterator end = begin;
516
521
std::advance (end, bytes_transferred);
517
- callback (make_iterator_range (begin, end), ec);
522
+ if (this ->is_chunk_encoding && remove_chunk_markers_) {
523
+ callback (parse_chunk_encoding (make_iterator_range (begin, end)), ec);
524
+ }else {
525
+ callback (make_iterator_range (begin, end), ec);
526
+ }
518
527
auto self =this ->shared_from_this ();
519
528
delegate_->read_some (
520
529
boost::asio::mutable_buffers_1 (this ->part .data (),
@@ -577,37 +586,6 @@ struct http_async_connection
577
586
}
578
587
}
579
588
580
- string_typeparse_chunk_encoding (string_type& body_string) {
581
- string_type body;
582
- string_type crlf =" \r\n " ;
583
-
584
- typename string_type::iterator begin = body_string.begin ();
585
- for (typename string_type::iterator iter =
586
- std::search (begin, body_string.end (), crlf.begin (), crlf.end ());
587
- iter != body_string.end ();
588
- iter =
589
- std::search (begin, body_string.end (), crlf.begin (), crlf.end ())) {
590
- string_typeline (begin, iter);
591
- if (line.empty ()) {
592
- break ;
593
- }
594
- std::stringstreamstream (line);
595
- int len;
596
- stream >> std::hex >> len;
597
- std::advance (iter,2 );
598
- if (len ==0 ) {
599
- break ;
600
- }
601
- if (len <= body_string.end () - iter) {
602
- body.insert (body.end (), iter, iter + len);
603
- std::advance (iter, len +2 );
604
- }
605
- begin = iter;
606
- }
607
-
608
- return body;
609
- }
610
-
611
589
int timeout_;
612
590
bool remove_chunk_markers_;
613
591
boost::asio::steady_timer timer_;