@@ -431,20 +431,13 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
431
431
} else {
432
432
NETWORK_MESSAGE (" no callback provided, appending to body..." );
433
433
bool 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);
448
441
}
449
442
// Here we don't have a body callback. Let's
450
443
// 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
474
467
this ->source_promise .set_value (" " );
475
468
this ->part .assign (' \0 ' );
476
469
this ->response_parser_ .reset ();
477
- // NETWORK_MESSAGE("forcing socket disconnect on content length");
478
- // connection_delegate_->disconnect();
479
470
}
480
471
}
481
472
}
@@ -742,7 +733,17 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
742
733
boost::trim (header_pair.second );
743
734
headers.insert (header_pair);
744
735
}
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
+ }
746
747
headers_promise.set_value (headers);
747
748
}
748
749
@@ -824,7 +825,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
824
825
boost::promise<boost::uint16_t > status_promise;
825
826
boost::promise<std::string> status_message_promise;
826
827
boost::promise<std::multimap<std::string, std::string> > headers_promise;
827
- std::multimap<std::string, std::string> headers_;
828
+ boost::optional< unsigned > content_length_;
828
829
boost::promise<std::string> source_promise;
829
830
boost::promise<std::string> destination_promise;
830
831
boost::promise<std::string> body_promise;
0 commit comments