[http_request] Extract lowercase_headers helper to avoid double-copy

Both start() overloads now use a shared lowercase_headers() template
that does a single pass from any iterator range, avoiding the extra
vector copy that the set overload was doing.
This commit is contained in:
J. Nick Koston
2026-02-16 18:28:04 -06:00
parent a55abd8e5f
commit d2037aef8d

View File

@@ -89,6 +89,16 @@ inline bool should_collect_header(const std::vector<std::string> &collect_header
return false;
}
/// Lowercase a range of strings into a vector
template<typename Iter> inline std::vector<std::string> lowercase_headers(Iter begin, Iter end) {
std::vector<std::string> result;
result.reserve(std::distance(begin, end));
for (auto it = begin; it != end; ++it) {
result.push_back(str_lower_case(*it));
}
return result;
}
/*
* HTTP Container Read Semantics
* =============================
@@ -363,19 +373,15 @@ class HttpRequestComponent : public Component {
std::shared_ptr<HttpContainer> start(const std::string &url, const std::string &method, const std::string &body,
const std::list<Header> &request_headers,
const std::set<std::string> &collect_headers) {
return this->start(url, method, body, request_headers,
std::vector<std::string>(collect_headers.begin(), collect_headers.end()));
return this->perform(url, method, body, request_headers,
lowercase_headers(collect_headers.begin(), collect_headers.end()));
}
std::shared_ptr<HttpContainer> start(const std::string &url, const std::string &method, const std::string &body,
const std::list<Header> &request_headers,
const std::vector<std::string> &collect_headers) {
std::vector<std::string> lower_case_collect_headers;
lower_case_collect_headers.reserve(collect_headers.size());
for (const auto &header : collect_headers) {
lower_case_collect_headers.push_back(str_lower_case(header));
}
return this->perform(url, method, body, request_headers, lower_case_collect_headers);
return this->perform(url, method, body, request_headers,
lowercase_headers(collect_headers.begin(), collect_headers.end()));
}
protected: