Skip to content

Commit 8edc9a4

Browse files
BillyONealras0219-msft
authored andcommitted
Deduplicate some code in HTTP headers. (#825)
1 parent e388a2e commit 8edc9a4

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

Release/include/cpprest/http_headers.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ class http_headers
145145
template<typename _t1>
146146
void add(const key_type& name, const _t1& value)
147147
{
148-
if (has(name))
148+
auto printedValue = utility::conversions::details::print_string(value);
149+
auto& mapVal = m_headers[name];
150+
if (mapVal.empty())
149151
{
150-
m_headers[name].append(_XPLATSTR(", ")).append(utility::conversions::details::print_string(value));
152+
mapVal = std::move(printedValue);
151153
}
152154
else
153155
{
154-
m_headers[name] = utility::conversions::details::print_string(value);
156+
mapVal.append(_XPLATSTR(", ")).append(std::move(printedValue));
155157
}
156158
}
157159

@@ -212,20 +214,12 @@ class http_headers
212214
bool match(const key_type &name, _t1 &value) const
213215
{
214216
auto iter = m_headers.find(name);
215-
if (iter != m_headers.end())
216-
{
217-
// Check to see if doesn't have a value.
218-
if(iter->second.empty())
219-
{
220-
bind_impl(iter->second, value);
221-
return true;
222-
}
223-
return bind_impl(iter->second, value);
224-
}
225-
else
217+
if (iter == m_headers.end())
226218
{
227219
return false;
228220
}
221+
222+
return bind_impl(iter->second, value) || iter->second.empty();
229223
}
230224

231225
/// <summary>
@@ -311,6 +305,7 @@ class http_headers
311305
ref = utility::conversions::to_utf16string(text);
312306
return true;
313307
}
308+
314309
bool bind_impl(const key_type &text, std::string &ref) const
315310
{
316311
ref = utility::conversions::to_utf8string(text);

0 commit comments

Comments
 (0)