Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita941fb1

Browse files
committed
Use optional member variable to keep track of content length.
1 parent78afee4 commita941fb1

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

‎include/network/protocol/http/client/connection/async_normal.ipp‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -431,20 +431,13 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
431431
}else {
432432
NETWORK_MESSAGE("no callback provided, appending to body...");
433433
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);
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
474467
this->source_promise.set_value("");
475468
this->part.assign('\0');
476469
this->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
742733
boost::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;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp