Skip to content

Commit 23ef8d0

Browse files
committed
Fixed bug in parsing the HTTP headers in the HTTP client.
1 parent d5b65ee commit 23ef8d0

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

contrib/http_examples/read_headers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ main(int argc, char *argv[]) {
2424
auto future_response = client.head(request);
2525
auto response = future_response.get();
2626

27+
std::cout << "HTTP version: " << response.version() << std::endl;
28+
std::cout << "HTTP status: " << static_cast<int>(response.status()) << std::endl;
29+
std::cout << "HTTP status message: " << response.status_message() << std::endl;
30+
std::cout << std::endl;
2731
for (auto header : response.headers()) {
2832
std::cout << header.first << ": " << header.second << std::endl;
2933
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <future>
77
#include <boost/asio/strand.hpp>
88
#include <boost/algorithm/string/trim.hpp>
9-
#include <boost/algorithm/string/split.hpp>
109
#include <boost/algorithm/string/predicate.hpp>
10+
#include <boost/range/algorithm/find_first_of.hpp>
1111
#include <network/uri.hpp>
1212
#include <network/config.hpp>
1313
#include <network/http/v2/client/client.hpp>
@@ -179,9 +179,11 @@ namespace network {
179179
std::istream is(&response_);
180180
string_type header;
181181
while (std::getline(is, header) && (header != "\r")) {
182-
std::vector<string_type> kvp;
183-
boost::split(kvp, header, boost::is_any_of(":"));
184-
res->add_header(kvp[0], boost::trim_copy(kvp[1]));
182+
auto delim = boost::find_first_of(header, ":");
183+
string_type key(std::begin(header), delim);
184+
while (*++delim == ' ') { }
185+
string_type value(delim, std::end(header));
186+
res->add_header(key, value);
185187
}
186188

187189
connection_->async_read(response_,

0 commit comments

Comments
 (0)