fix(fetch) always make sure that abort tracker is cleaned, revise ref count (#13459)

This commit is contained in:
Ciro Spaciari
2024-08-23 17:08:57 -07:00
committed by GitHub
parent 0f1d5d5dab
commit 5a108c5027
17 changed files with 1688 additions and 122 deletions

View File

@@ -252,6 +252,30 @@ String HTTPHeaderMap::get(HTTPHeaderName name) const
return index != notFound ? m_commonHeaders[index].value : String();
}
HTTPHeaderMap::HeaderIndex HTTPHeaderMap::indexOf(HTTPHeaderName name) const
{
auto index = m_commonHeaders.findIf([&](auto& header) {
return header.key == name;
});
return (HeaderIndex) { .index = index, .isCommon = true };
}
HTTPHeaderMap::HeaderIndex HTTPHeaderMap::indexOf(const String& name) const
{
auto index = m_uncommonHeaders.findIf([&](auto& header) {
return equalIgnoringASCIICase(header.key, name);
});
return (HeaderIndex) { .index = index, .isCommon = false };
}
String HTTPHeaderMap::getIndex(HTTPHeaderMap::HeaderIndex index) const
{
if (index.index == notFound)
return String();
if (index.isCommon)
return m_commonHeaders[index.index].value;
return m_uncommonHeaders[index.index].value;
}
void HTTPHeaderMap::set(HTTPHeaderName name, const String& value)
{
if (name == HTTPHeaderName::SetCookie) {
@@ -269,6 +293,19 @@ void HTTPHeaderMap::set(HTTPHeaderName name, const String& value)
m_commonHeaders[index].value = value;
}
bool HTTPHeaderMap::setIndex(HTTPHeaderMap::HeaderIndex index, const String& value)
{
if (!index.isValid())
return false;
if (index.isCommon) {
m_commonHeaders[index.index].value = value;
} else {
m_uncommonHeaders[index.index].value = value;
}
return true;
}
bool HTTPHeaderMap::contains(HTTPHeaderName name) const
{
if (name == HTTPHeaderName::SetCookie)
@@ -303,7 +340,7 @@ void HTTPHeaderMap::add(HTTPHeaderName name, const String& value)
return header.key == name;
});
if (index != notFound)
m_commonHeaders[index].value = makeString(m_commonHeaders[index].value, ", "_s, value);
m_commonHeaders[index].value = makeString(m_commonHeaders[index].value, name == HTTPHeaderName::Cookie ? "; "_s : ", "_s, value);
else
m_commonHeaders.append(CommonHeader { name, value });
}