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

Commit50f3a4c

Browse files
committed
Fixed bug in error handling in the HTTP client.
1 parent6771a55 commit50f3a4c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

‎http/src/http/v2/client/client.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ namespace network {
9999
boost::asio::io_service::strand strand_;
100100
std::unique_ptr<client_connection::async_resolver> resolver_;
101101
std::shared_ptr<client_connection::async_connection> mock_connection_;
102-
// TODO configure deadline timer for timeouts
103102
bool timedout_;
104103
boost::asio::deadline_timer timer_;
105104
std::thread lifetime_thread_;
@@ -409,6 +408,16 @@ namespace network {
409408
const boost::system::error_code &ec, std::size_t bytes_read,
410409
std::shared_ptr<request_context> context,
411410
std::shared_ptr<response> res) {
411+
if (timedout_) {
412+
set_error(boost::asio::error::timed_out, context);
413+
return;
414+
}
415+
416+
if (ec && ec != boost::asio::error::eof) {
417+
set_error(ec, context);
418+
return;
419+
}
420+
412421
// update progress.
413422
context->total_bytes_read_ += bytes_read;
414423
if (auto progress = context->options_.progress()) {
@@ -425,8 +434,9 @@ namespace network {
425434

426435
std::istreamis(&context->response_buffer_);
427436
string_type line;
437+
line.reserve(bytes_read);
428438
while (!getline_with_newline(is, line).eof()) {
429-
res->append_body(line);
439+
res->append_body(std::move(line));
430440
}
431441

432442
// Keep reading the response body until we have nothing else to read.

‎http/src/network/http/v2/client/response.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ class response {
166166
* \param name The header name.
167167
* \param value The header value.
168168
*/
169-
voidadd_header(conststring_type&name,conststring_type&value) {
170-
headers_.push_back(std::make_pair(name, value));
169+
voidadd_header(string_type name, string_type value) {
170+
headers_.emplace_back(name, value);
171171
}
172172

173173
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp