Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Unified Diff: third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp

Issue 2559273005: [Fetch API] Implement combining of Headers with same keys. (Closed)
Patch Set: Fix for jsbell comment. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp b/third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp
index abbd34f37ca60b78591f37db5f8b40c32a4f4b05..007807096a82e3026ce8906f910e0509422b8866 100644
--- a/third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp
+++ b/third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp
@@ -130,14 +130,23 @@ bool FetchHeaderList::containsNonSimpleHeader() const {
void FetchHeaderList::sortAndCombine() {
// https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine
// "To sort and combine a header list..."
-
- // TODO(jsbell): Implement the combining part - this currently just sorts.
-
- std::sort(
- m_headerList.begin(), m_headerList.end(),
- [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) {
- return WTF::codePointCompareLessThan(a->first, b->first);
- });
+ if (m_headerList.size() > 1) {
jsbell 2016/12/12 21:00:24 This would be simpler as: if (m_headerList.isEmpt
+ std::sort(
+ m_headerList.begin(), m_headerList.end(),
+ [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) {
+ return WTF::codePointCompareLessThan(a->first, b->first);
+ });
+
+ for (size_t index = m_headerList.size() - 1; index > 0;) {
+ if (m_headerList[index - 1]->first == m_headerList[index]->first) {
+ m_headerList[index - 1]->second.append(",");
+ m_headerList[index - 1]->second.append(m_headerList[index]->second);
+ m_headerList.remove(index, 1);
+ } else {
+ --index;
+ }
+ }
+ }
}
bool FetchHeaderList::isValidHeaderName(const String& name) {

Powered by Google App Engine
This is Rietveld 408576698