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 12 matching lines...) Expand all Loading... |
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 m_headerList.push_back(WTF::wrapUnique(new Header(name.lower(), value))); |
34 } | 34 } |
35 | 35 |
36 void FetchHeaderList::set(const String& name, const String& value) { | 36 void FetchHeaderList::set(const String& name, const String& value) { |
37 // "To set a name/value (|name|/|value|) pair in a header list (|list|), run | 37 // "To set a name/value (|name|/|value|) pair in a header list (|list|), run |
38 // these steps: | 38 // these steps: |
39 // 1. Byte lowercase |name|. | 39 // 1. Byte lowercase |name|. |
40 // 2. If there are any headers in |list| whose name is |name|, set the value | 40 // 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. | 41 // 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 | 42 // 3. Otherwise, append a new header whose name is |name| and value is |
43 // |value|, to |list|." | 43 // |value|, to |list|." |
44 const String lowercasedName = name.lower(); | 44 const String lowercasedName = name.lower(); |
45 for (size_t i = 0; i < m_headerList.size(); ++i) { | 45 for (size_t i = 0; i < m_headerList.size(); ++i) { |
46 if (m_headerList[i]->first == lowercasedName) { | 46 if (m_headerList[i]->first == lowercasedName) { |
47 m_headerList[i]->second = value; | 47 m_headerList[i]->second = value; |
48 for (size_t j = i + 1; j < m_headerList.size();) { | 48 for (size_t j = i + 1; j < m_headerList.size();) { |
49 if (m_headerList[j]->first == lowercasedName) | 49 if (m_headerList[j]->first == lowercasedName) |
50 m_headerList.remove(j); | 50 m_headerList.remove(j); |
51 else | 51 else |
52 ++j; | 52 ++j; |
53 } | 53 } |
54 return; | 54 return; |
55 } | 55 } |
56 } | 56 } |
57 m_headerList.append(WTF::makeUnique<Header>(lowercasedName, value)); | 57 m_headerList.push_back(WTF::makeUnique<Header>(lowercasedName, value)); |
58 } | 58 } |
59 | 59 |
60 String FetchHeaderList::extractMIMEType() const { | 60 String FetchHeaderList::extractMIMEType() const { |
61 // To extract a MIME type from a header list (headers), run these steps: | 61 // To extract a MIME type from a header list (headers), run these steps: |
62 // 1. Let MIMEType be the result of parsing `Content-Type` in headers. | 62 // 1. Let MIMEType be the result of parsing `Content-Type` in headers. |
63 String mimeType; | 63 String mimeType; |
64 if (!get("Content-Type", mimeType)) { | 64 if (!get("Content-Type", mimeType)) { |
65 // 2. If MIMEType is null or failure, return the empty byte sequence. | 65 // 2. If MIMEType is null or failure, return the empty byte sequence. |
66 return String(); | 66 return String(); |
67 } | 67 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 } | 102 } |
103 return found; | 103 return found; |
104 } | 104 } |
105 | 105 |
106 void FetchHeaderList::getAll(const String& name, Vector<String>& result) const { | 106 void FetchHeaderList::getAll(const String& name, Vector<String>& result) const { |
107 const String lowercasedName = name.lower(); | 107 const String lowercasedName = name.lower(); |
108 result.clear(); | 108 result.clear(); |
109 for (size_t i = 0; i < m_headerList.size(); ++i) { | 109 for (size_t i = 0; i < m_headerList.size(); ++i) { |
110 if (m_headerList[i]->first == lowercasedName) | 110 if (m_headerList[i]->first == lowercasedName) |
111 result.append(m_headerList[i]->second); | 111 result.push_back(m_headerList[i]->second); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 bool FetchHeaderList::has(const String& name) const { | 115 bool FetchHeaderList::has(const String& name) const { |
116 const String lowercasedName = name.lower(); | 116 const String lowercasedName = name.lower(); |
117 for (size_t i = 0; i < m_headerList.size(); ++i) { | 117 for (size_t i = 0; i < m_headerList.size(); ++i) { |
118 if (m_headerList[i]->first == lowercasedName) | 118 if (m_headerList[i]->first == lowercasedName) |
119 return true; | 119 return true; |
120 } | 120 } |
121 return false; | 121 return false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 return isValidHTTPToken(name); | 161 return isValidHTTPToken(name); |
162 } | 162 } |
163 | 163 |
164 bool FetchHeaderList::isValidHeaderValue(const String& value) { | 164 bool FetchHeaderList::isValidHeaderValue(const String& value) { |
165 // "A value is a byte sequence that matches the field-value token production | 165 // "A value is a byte sequence that matches the field-value token production |
166 // and contains no 0x0A or 0x0D bytes." | 166 // and contains no 0x0A or 0x0D bytes." |
167 return isValidHTTPHeaderValue(value); | 167 return isValidHTTPHeaderValue(value); |
168 } | 168 } |
169 | 169 |
170 } // namespace blink | 170 } // namespace blink |
OLD | NEW |