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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 if (!FetchUtils::isSimpleHeader(AtomicString(m_headerList[i]->first), | 123 if (!FetchUtils::isSimpleHeader(AtomicString(m_headerList[i]->first), |
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 if (m_headerList.size() > 1) { | |
jsbell
2016/12/12 21:00:24
This would be simpler as:
if (m_headerList.isEmpt
| |
134 std::sort( | |
135 m_headerList.begin(), m_headerList.end(), | |
136 [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) { | |
137 return WTF::codePointCompareLessThan(a->first, b->first); | |
138 }); | |
133 | 139 |
134 // TODO(jsbell): Implement the combining part - this currently just sorts. | 140 for (size_t index = m_headerList.size() - 1; index > 0;) { |
135 | 141 if (m_headerList[index - 1]->first == m_headerList[index]->first) { |
136 std::sort( | 142 m_headerList[index - 1]->second.append(","); |
137 m_headerList.begin(), m_headerList.end(), | 143 m_headerList[index - 1]->second.append(m_headerList[index]->second); |
138 [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) { | 144 m_headerList.remove(index, 1); |
139 return WTF::codePointCompareLessThan(a->first, b->first); | 145 } else { |
140 }); | 146 --index; |
147 } | |
148 } | |
149 } | |
141 } | 150 } |
142 | 151 |
143 bool FetchHeaderList::isValidHeaderName(const String& name) { | 152 bool FetchHeaderList::isValidHeaderName(const String& name) { |
144 // "A name is a case-insensitive byte sequence that matches the field-name | 153 // "A name is a case-insensitive byte sequence that matches the field-name |
145 // token production." | 154 // token production." |
146 return isValidHTTPToken(name); | 155 return isValidHTTPToken(name); |
147 } | 156 } |
148 | 157 |
149 bool FetchHeaderList::isValidHeaderValue(const String& value) { | 158 bool FetchHeaderList::isValidHeaderValue(const String& value) { |
150 // "A value is a byte sequence that matches the field-value token production | 159 // "A value is a byte sequence that matches the field-value token production |
151 // and contains no 0x0A or 0x0D bytes." | 160 // and contains no 0x0A or 0x0D bytes." |
152 return isValidHTTPHeaderValue(value); | 161 return isValidHTTPHeaderValue(value); |
153 } | 162 } |
154 | 163 |
155 } // namespace blink | 164 } // namespace blink |
OLD | NEW |