summaryrefslogtreecommitdiffstats
path: root/dom/fetch/InternalHeaders.h
diff options
context:
space:
mode:
authorNew Tobin Paradigm <email@mattatobin.com>2018-04-14 18:11:24 -0400
committerGitHub <noreply@github.com>2018-04-14 18:11:24 -0400
commit9282781bdfa7168685ee3716e283735fd9095975 (patch)
tree17a157801ad2e82b7510b568f6a3cd58eeebc512 /dom/fetch/InternalHeaders.h
parent8b779470cd4f0ccc3d8f3050bddc025101837f77 (diff)
parent9ee567082c6bdf949f6c02a7e6c2e8b7bfef6590 (diff)
downloadUXP-9282781bdfa7168685ee3716e283735fd9095975.tar
UXP-9282781bdfa7168685ee3716e283735fd9095975.tar.gz
UXP-9282781bdfa7168685ee3716e283735fd9095975.tar.lz
UXP-9282781bdfa7168685ee3716e283735fd9095975.tar.xz
UXP-9282781bdfa7168685ee3716e283735fd9095975.zip
Merge pull request #167 from janekptacijarabaci/fetch_headers_1
moebius#140: Fix: Fetch - headers should sort and combine
Diffstat (limited to 'dom/fetch/InternalHeaders.h')
-rw-r--r--dom/fetch/InternalHeaders.h31
1 files changed, 23 insertions, 8 deletions
diff --git a/dom/fetch/InternalHeaders.h b/dom/fetch/InternalHeaders.h
index e47066669..9a6d6dae7 100644
--- a/dom/fetch/InternalHeaders.h
+++ b/dom/fetch/InternalHeaders.h
@@ -45,14 +45,23 @@ private:
HeadersGuardEnum mGuard;
nsTArray<Entry> mList;
+ nsTArray<Entry> mSortedList;
+
+ // This boolean is set to true at any writing operation to mList. It's set to
+ // false when mSortedList is regenerated. This happens when the header is
+ // iterated.
+ bool mListDirty;
+
public:
explicit InternalHeaders(HeadersGuardEnum aGuard = HeadersGuardEnum::None)
: mGuard(aGuard)
+ , mListDirty(false)
{
}
explicit InternalHeaders(const InternalHeaders& aOther)
: mGuard(HeadersGuardEnum::None)
+ , mListDirty(true)
{
ErrorResult result;
Fill(aOther, result);
@@ -79,19 +88,22 @@ public:
bool Has(const nsACString& aName, ErrorResult& aRv) const;
void Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv);
- uint32_t GetIterableLength() const
+ uint32_t GetIterableLength()
{
- return mList.Length();
+ MaybeSortList();
+ return mSortedList.Length();
}
- const NS_ConvertASCIItoUTF16 GetKeyAtIndex(unsigned aIndex) const
+ const NS_ConvertASCIItoUTF16 GetKeyAtIndex(unsigned aIndex)
{
- MOZ_ASSERT(aIndex < mList.Length());
- return NS_ConvertASCIItoUTF16(mList[aIndex].mName);
+ MaybeSortList();
+ MOZ_ASSERT(aIndex < mSortedList.Length());
+ return NS_ConvertASCIItoUTF16(mSortedList[aIndex].mName);
}
- const NS_ConvertASCIItoUTF16 GetValueAtIndex(unsigned aIndex) const
+ const NS_ConvertASCIItoUTF16 GetValueAtIndex(unsigned aIndex)
{
- MOZ_ASSERT(aIndex < mList.Length());
- return NS_ConvertASCIItoUTF16(mList[aIndex].mValue);
+ MaybeSortList();
+ MOZ_ASSERT(aIndex < mSortedList.Length());
+ return NS_ConvertASCIItoUTF16(mSortedList[aIndex].mValue);
}
void Clear();
@@ -152,6 +164,9 @@ private:
const nsACString& aValue);
static bool IsRevalidationHeader(const nsACString& aName);
+
+ void MaybeSortList();
+ void SetListDirty();
};
} // namespace dom