Skip to content

Commit ce3bccf

Browse files
committed
Validated that the HEAD response returns the headers.
1 parent 619255a commit ce3bccf

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <future>
77
#include <boost/asio/strand.hpp>
88
#include <boost/algorithm/string/trim.hpp>
9+
#include <boost/algorithm/string/split.hpp>
910
#include <boost/algorithm/string/predicate.hpp>
1011
#include <network/uri.hpp>
1112
#include <network/config.hpp>
@@ -171,6 +172,14 @@ namespace network {
171172
}
172173

173174
// fill headers
175+
std::istream is(&response_);
176+
std::string header;
177+
while ((header != "\r") && std::getline(is, header)) {
178+
std::vector<string_type> kvp;
179+
boost::split(kvp, header, boost::is_any_of(":"));
180+
res->add_header(kvp[0], boost::trim_copy(kvp[1]));
181+
}
182+
174183
connection_->async_read_until(response_,
175184
"\r\n\r\n",
176185
strand_.wrap(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ namespace network {
152152
return status_message_;
153153
}
154154

155+
void add_header(const string_type &name, const string_type &value) {
156+
headers_.push_back(std::make_pair(name, value));
157+
}
158+
155159
/**
156160
* \brief
157161
*/

http/test/v2/features/client/client_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ Describe(http_client) {
3434
Assert::That(response.version(), Equals("HTTP/1.1"));
3535
Assert::That(response.status(), Equals(http::status::code::OK));
3636
Assert::That(response.status_message(), Equals("OK"));
37+
38+
auto headers = response.headers();
39+
Assert::That(std::begin(headers)->first, Equals("Date"));
3740
}
3841

3942
std::unique_ptr<http::client> client_;

0 commit comments

Comments
 (0)