OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/fetch/FetchHeaderList.h" | 5 #include "modules/fetch/FetchHeaderList.h" |
6 | 6 |
7 #include "core/fetch/FetchUtils.h" | 7 #include "core/fetch/FetchUtils.h" |
8 #include "platform/network/HTTPParsers.h" | 8 #include "platform/network/HTTPParsers.h" |
9 #include "wtf/PtrUtil.h" | 9 #include "wtf/PtrUtil.h" |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 AtomicString(m_headerList[i]->second))) | 124 AtomicString(m_headerList[i]->second))) |
125 return true; | 125 return true; |
126 } | 126 } |
127 return false; | 127 return false; |
128 } | 128 } |
129 | 129 |
130 void FetchHeaderList::sortAndCombine() { | 130 void FetchHeaderList::sortAndCombine() { |
131 // https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine | 131 // https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine |
132 // "To sort and combine a header list..." | 132 // "To sort and combine a header list..." |
133 | 133 |
134 // TODO(jsbell): Implement the combining part - this currently just sorts. | |
135 | |
136 std::sort( | 134 std::sort( |
137 m_headerList.begin(), m_headerList.end(), | 135 m_headerList.begin(), m_headerList.end(), |
138 [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) { | 136 [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) { |
137 if (a->first == b->first) { | |
jsbell
2016/12/12 16:54:51
nit: no {} needed here
| |
138 return WTF::codePointCompareLessThan(a->second, b->second); | |
jsbell
2016/12/12 16:54:50
Is the sorting here (by value) done to make the so
| |
139 } | |
139 return WTF::codePointCompareLessThan(a->first, b->first); | 140 return WTF::codePointCompareLessThan(a->first, b->first); |
140 }); | 141 }); |
142 | |
143 if (m_headerList.size() > 1) { | |
jsbell
2016/12/12 16:54:51
This test could be inverted to become an early exi
| |
144 for (size_t index = 1; index < m_headerList.size();) { | |
145 if (m_headerList[index - 1]->first == m_headerList[index]->first) { | |
146 m_headerList[index - 1]->second.append(","); | |
147 m_headerList[index - 1]->second.append(m_headerList[index]->second); | |
148 m_headerList.remove(index, 1); | |
jsbell
2016/12/12 16:54:51
This algorithm could be reversed to start at the e
| |
149 } else { | |
150 index++; | |
jsbell
2016/12/12 16:54:51
nit: prefer pre-increment when post-increment is n
| |
151 } | |
152 } | |
153 } | |
141 } | 154 } |
142 | 155 |
143 bool FetchHeaderList::isValidHeaderName(const String& name) { | 156 bool FetchHeaderList::isValidHeaderName(const String& name) { |
144 // "A name is a case-insensitive byte sequence that matches the field-name | 157 // "A name is a case-insensitive byte sequence that matches the field-name |
145 // token production." | 158 // token production." |
146 return isValidHTTPToken(name); | 159 return isValidHTTPToken(name); |
147 } | 160 } |
148 | 161 |
149 bool FetchHeaderList::isValidHeaderValue(const String& value) { | 162 bool FetchHeaderList::isValidHeaderValue(const String& value) { |
150 // "A value is a byte sequence that matches the field-value token production | 163 // "A value is a byte sequence that matches the field-value token production |
151 // and contains no 0x0A or 0x0D bytes." | 164 // and contains no 0x0A or 0x0D bytes." |
152 return isValidHTTPHeaderValue(value); | 165 return isValidHTTPHeaderValue(value); |
153 } | 166 } |
154 | 167 |
155 } // namespace blink | 168 } // namespace blink |
OLD | NEW |