Skip to content

Commit 50f3a4c

Browse files
committed
Fixed bug in error handling in the HTTP client.
1 parent 6771a55 commit 50f3a4c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

+12-2
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::istream is(&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

+2-2
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-
void add_header(const string_type &name, const string_type &value) {
170-
headers_.push_back(std::make_pair(name, value));
169+
void add_header(string_type name, string_type value) {
170+
headers_.emplace_back(name, value);
171171
}
172172

173173
/**

0 commit comments

Comments
 (0)