Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate some code in HTTP headers. #825

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions Release/include/cpprest/http_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ class http_headers
template<typename _t1>
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));
}
}

Expand Down Expand Up @@ -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();
}

/// <summary>
Expand Down Expand Up @@ -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);
Expand Down