From 702ff3245e2bf54a7dc167110d3ee867ac7e6307 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Thu, 2 Aug 2018 18:51:34 -0700 Subject: [PATCH] Deduplicate some code in HTTP headers. --- Release/include/cpprest/http_headers.h | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Release/include/cpprest/http_headers.h b/Release/include/cpprest/http_headers.h index f5bee96535..2bc1975acd 100644 --- a/Release/include/cpprest/http_headers.h +++ b/Release/include/cpprest/http_headers.h @@ -145,13 +145,15 @@ class http_headers template void add(const key_type& name, const _t1& value) { - if (has(name)) + auto printedValue = utility::conversions::details::print_string(value); + auto& mapVal = m_headers[name]; + if (mapVal.empty()) { - m_headers[name].append(_XPLATSTR(", ")).append(utility::conversions::details::print_string(value)); + mapVal = std::move(printedValue); } else { - m_headers[name] = utility::conversions::details::print_string(value); + mapVal.append(_XPLATSTR(", ")).append(std::move(printedValue)); } } @@ -212,20 +214,12 @@ class http_headers bool match(const key_type &name, _t1 &value) const { auto iter = m_headers.find(name); - if (iter != m_headers.end()) - { - // Check to see if doesn't have a value. - if(iter->second.empty()) - { - bind_impl(iter->second, value); - return true; - } - return bind_impl(iter->second, value); - } - else + if (iter == m_headers.end()) { return false; } + + return bind_impl(iter->second, value) || iter->second.empty(); } /// @@ -311,6 +305,7 @@ class http_headers ref = utility::conversions::to_utf16string(text); return true; } + bool bind_impl(const key_type &text, std::string &ref) const { ref = utility::conversions::to_utf8string(text);