| 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 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 FetchHeaderList* FetchHeaderList::create() { | 14 FetchHeaderList* FetchHeaderList::create() { |
| 14 return new FetchHeaderList(); | 15 return new FetchHeaderList(); |
| 15 } | 16 } |
| 16 | 17 |
| 17 FetchHeaderList* FetchHeaderList::clone() { | 18 FetchHeaderList* FetchHeaderList::clone() const { |
| 18 FetchHeaderList* list = create(); | 19 FetchHeaderList* list = create(); |
| 19 for (size_t i = 0; i < m_headerList.size(); ++i) | 20 for (size_t i = 0; i < m_headerList.size(); ++i) |
| 20 list->append(m_headerList[i]->first, m_headerList[i]->second); | 21 list->append(m_headerList[i]->first, m_headerList[i]->second); |
| 21 return list; | 22 return list; |
| 22 } | 23 } |
| 23 | 24 |
| 24 FetchHeaderList::FetchHeaderList() {} | 25 FetchHeaderList::FetchHeaderList() {} |
| 25 | 26 |
| 26 FetchHeaderList::~FetchHeaderList() {} | 27 FetchHeaderList::~FetchHeaderList() {} |
| 27 | 28 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 120 |
| 120 bool FetchHeaderList::containsNonSimpleHeader() const { | 121 bool FetchHeaderList::containsNonSimpleHeader() const { |
| 121 for (size_t i = 0; i < m_headerList.size(); ++i) { | 122 for (size_t i = 0; i < m_headerList.size(); ++i) { |
| 122 if (!FetchUtils::isSimpleHeader(AtomicString(m_headerList[i]->first), | 123 if (!FetchUtils::isSimpleHeader(AtomicString(m_headerList[i]->first), |
| 123 AtomicString(m_headerList[i]->second))) | 124 AtomicString(m_headerList[i]->second))) |
| 124 return true; | 125 return true; |
| 125 } | 126 } |
| 126 return false; | 127 return false; |
| 127 } | 128 } |
| 128 | 129 |
| 130 void FetchHeaderList::sortAndCombine() { |
| 131 // https://fetch.spec.whatwg.org/#concept-header-list-sort-and-combine |
| 132 // "To sort and combine a header list..." |
| 133 |
| 134 // TODO(jsbell): Implement the combining part - this currently just sorts. |
| 135 |
| 136 std::sort( |
| 137 m_headerList.begin(), m_headerList.end(), |
| 138 [](const std::unique_ptr<Header>& a, const std::unique_ptr<Header>& b) { |
| 139 return WTF::codePointCompareLessThan(a->first, b->first); |
| 140 }); |
| 141 } |
| 142 |
| 129 bool FetchHeaderList::isValidHeaderName(const String& name) { | 143 bool FetchHeaderList::isValidHeaderName(const String& name) { |
| 130 // "A name is a case-insensitive byte sequence that matches the field-name | 144 // "A name is a case-insensitive byte sequence that matches the field-name |
| 131 // token production." | 145 // token production." |
| 132 return isValidHTTPToken(name); | 146 return isValidHTTPToken(name); |
| 133 } | 147 } |
| 134 | 148 |
| 135 bool FetchHeaderList::isValidHeaderValue(const String& value) { | 149 bool FetchHeaderList::isValidHeaderValue(const String& value) { |
| 136 // "A value is a byte sequence that matches the field-value token production | 150 // "A value is a byte sequence that matches the field-value token production |
| 137 // and contains no 0x0A or 0x0D bytes." | 151 // and contains no 0x0A or 0x0D bytes." |
| 138 return isValidHTTPHeaderValue(value); | 152 return isValidHTTPHeaderValue(value); |
| 139 } | 153 } |
| 140 | 154 |
| 141 } // namespace blink | 155 } // namespace blink |
| OLD | NEW |