@@ -431,20 +431,13 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
431431 }else {
432432NETWORK_MESSAGE (" no callback provided, appending to body..." );
433433bool get_more =true ;
434- buffer_type::const_iterator begin =this ->part .begin ();
435- buffer_type::const_iterator end = begin;
436- std::advance (end, bytes_transferred);
437- // check the content length header
438- // auto headers_future = headers_promise.get_future();
439- auto it = headers_.find (" Content-Length" );
440- if (it != headers_.end ()) {
441- try {
442- unsigned content_length =std::stoi (it->second );
443- get_more = (end - begin) < content_length;
444- NETWORK_MESSAGE (" Content-Length:" << content_length);
445- }catch (const std::invalid_argument&) {
446- }catch (const std::out_of_range&) {
447- }
434+ if (content_length_) {
435+ buffer_type::const_iterator begin =this ->part .begin ();
436+ buffer_type::const_iterator end = begin;
437+ std::advance (end, bytes_transferred);
438+ get_more = (end - begin) < *content_length_;
439+ NETWORK_MESSAGE (" content_length =" << * content_length_
440+ <<" , bytes read =" << (end - begin) <<" , read more =" << get_more);
448441 }
449442// Here we don't have a body callback. Let's
450443// make sure that we deal with the remainder
@@ -474,8 +467,6 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
474467this ->source_promise .set_value (" " );
475468this ->part .assign (' \0 ' );
476469this ->response_parser_ .reset ();
477- // NETWORK_MESSAGE("forcing socket disconnect on content length");
478- // connection_delegate_->disconnect();
479470 }
480471 }
481472 }
@@ -742,7 +733,17 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
742733boost::trim (header_pair.second );
743734 headers.insert (header_pair);
744735 }
745- this ->headers_ = headers;
736+ // Set content length
737+ content_length_ = boost::none;
738+ auto it = headers.find (" Content-Length" );
739+ if (it != headers.end ()) {
740+ try {
741+ content_length_ =std::stoi (it->second );
742+ NETWORK_MESSAGE (" Content-Length:" << *content_length_);
743+ }catch (const std::invalid_argument&) {
744+ }catch (const std::out_of_range&) {
745+ }
746+ }
746747 headers_promise.set_value (headers);
747748 }
748749
@@ -824,7 +825,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
824825 boost::promise<boost::uint16_t > status_promise;
825826 boost::promise<std::string> status_message_promise;
826827 boost::promise<std::multimap<std::string, std::string> > headers_promise;
827- std::multimap<std::string, std::string> headers_;
828+ boost::optional< unsigned > content_length_;
828829 boost::promise<std::string> source_promise;
829830 boost::promise<std::string> destination_promise;
830831 boost::promise<std::string> body_promise;