@@ -433,8 +433,11 @@ struct http_async_connection
433433
434434// The invocation of the callback is synchronous to allow us to
435435// 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+ }
438441auto self =this ->shared_from_this ();
439442 delegate_->read_some (
440443boost::asio::mutable_buffers_1 (this ->part .data (),
@@ -473,7 +476,11 @@ struct http_async_connection
473476// We call the callback function synchronously passing the error
474477// condition (in this case, end of file) so that it can handle it
475478// 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+ }
477484 }else {
478485 string_type body_string;
479486if (this ->is_chunk_encoding && remove_chunk_markers_) {
@@ -490,9 +497,7 @@ struct http_async_connection
490497this ->body_promise .set_value (body_string);
491498 }else {
492499std::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);
496501this ->body_promise .set_value (body_string);
497502 }
498503 }
@@ -514,7 +519,11 @@ struct http_async_connection
514519this ->part .begin ();
515520typename protocol_base::buffer_type::const_iterator end = begin;
516521std::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+ }
518527auto self =this ->shared_from_this ();
519528 delegate_->read_some (
520529boost::asio::mutable_buffers_1 (this ->part .data (),
@@ -577,37 +586,6 @@ struct http_async_connection
577586 }
578587 }
579588
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-
611589int timeout_;
612590bool remove_chunk_markers_;
613591 boost::asio::steady_timer timer_;