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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/FetchHeaderList.cpp

Issue 2587463002: [Fetch API] Appending headers of the same name should have their values (Closed)
Patch Set: it will be nicer. 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 unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 } 23 }
24 24
25 FetchHeaderList::FetchHeaderList() {} 25 FetchHeaderList::FetchHeaderList() {}
26 26
27 FetchHeaderList::~FetchHeaderList() {} 27 FetchHeaderList::~FetchHeaderList() {}
28 28
29 void FetchHeaderList::append(const String& name, const String& value) { 29 void FetchHeaderList::append(const String& name, const String& value) {
30 // "To append a name/value (|name|/|value|) pair to a header list (|list|), 30 // "To append a name/value (|name|/|value|) pair to a header list (|list|),
31 // append a new header whose name is |name|, byte lowercased, and value is 31 // append a new header whose name is |name|, byte lowercased, and value is
32 // |value|, to |list|." 32 // |value|, to |list|."
33 m_headerList.append(WTF::wrapUnique(new Header(name.lower(), value))); 33 if (!value.isEmpty())
jsbell 2016/12/16 22:29:37 This seems incorrect - the caller (Headers::append
34 m_headerList.append(WTF::wrapUnique(new Header(name.lower(), value)));
34 } 35 }
35 36
36 void FetchHeaderList::set(const String& name, const String& value) { 37 void FetchHeaderList::set(const String& name, const String& value) {
37 // "To set a name/value (|name|/|value|) pair in a header list (|list|), run 38 // "To set a name/value (|name|/|value|) pair in a header list (|list|), run
38 // these steps: 39 // these steps:
39 // 1. Byte lowercase |name|. 40 // 1. Byte lowercase |name|.
40 // 2. If there are any headers in |list| whose name is |name|, set the value 41 // 2. If there are any headers in |list| whose name is |name|, set the value
41 // of the first such header to |value| and remove the others. 42 // of the first such header to |value| and remove the others.
42 // 3. Otherwise, append a new header whose name is |name| and value is 43 // 3. Otherwise, append a new header whose name is |name| and value is
43 // |value|, to |list|." 44 // |value|, to |list|."
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 for (size_t i = 0; i < m_headerList.size();) { 81 for (size_t i = 0; i < m_headerList.size();) {
81 if (m_headerList[i]->first == lowercasedName) 82 if (m_headerList[i]->first == lowercasedName)
82 m_headerList.remove(i); 83 m_headerList.remove(i);
83 else 84 else
84 ++i; 85 ++i;
85 } 86 }
86 } 87 }
87 88
88 bool FetchHeaderList::get(const String& name, String& result) const { 89 bool FetchHeaderList::get(const String& name, String& result) const {
89 const String lowercasedName = name.lower(); 90 const String lowercasedName = name.lower();
90 for (size_t i = 0; i < m_headerList.size(); ++i) { 91 for (const auto& header : m_headerList) {
91 if (m_headerList[i]->first == lowercasedName) { 92 DCHECK(!header->second.isEmpty());
92 result = m_headerList[i]->second; 93 if (header->first == lowercasedName) {
93 return true; 94 if (result.isEmpty()) {
95 result = header->second;
96 } else {
97 result.append(",");
98 result.append(header->second);
99 }
94 } 100 }
95 } 101 }
96 return false; 102 return !result.isEmpty();
97 } 103 }
98 104
99 void FetchHeaderList::getAll(const String& name, Vector<String>& result) const { 105 void FetchHeaderList::getAll(const String& name, Vector<String>& result) const {
100 const String lowercasedName = name.lower(); 106 const String lowercasedName = name.lower();
101 result.clear(); 107 result.clear();
102 for (size_t i = 0; i < m_headerList.size(); ++i) { 108 for (size_t i = 0; i < m_headerList.size(); ++i) {
103 if (m_headerList[i]->first == lowercasedName) 109 if (m_headerList[i]->first == lowercasedName)
104 result.append(m_headerList[i]->second); 110 result.append(m_headerList[i]->second);
105 } 111 }
106 } 112 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return isValidHTTPToken(name); 160 return isValidHTTPToken(name);
155 } 161 }
156 162
157 bool FetchHeaderList::isValidHeaderValue(const String& value) { 163 bool FetchHeaderList::isValidHeaderValue(const String& value) {
158 // "A value is a byte sequence that matches the field-value token production 164 // "A value is a byte sequence that matches the field-value token production
159 // and contains no 0x0A or 0x0D bytes." 165 // and contains no 0x0A or 0x0D bytes."
160 return isValidHTTPHeaderValue(value); 166 return isValidHTTPHeaderValue(value);
161 } 167 }
162 168
163 } // namespace blink 169 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698