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 "config.h" | 5 #include "config.h" |
6 #include "modules/fetch/Headers.h" | 6 #include "modules/fetch/Headers.h" |
7 | 7 |
8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/V8IteratorResultValue.h" | 10 #include "bindings/core/v8/V8IteratorResultValue.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 FetchHeaderList* headerList = m_headerList->clone(); | 99 FetchHeaderList* headerList = m_headerList->clone(); |
100 Headers* headers = create(headerList); | 100 Headers* headers = create(headerList); |
101 headers->m_guard = m_guard; | 101 headers->m_guard = m_guard; |
102 return headers; | 102 return headers; |
103 } | 103 } |
104 | 104 |
105 void Headers::append(const String& name, const String& value, ExceptionState& ex ceptionState) | 105 void Headers::append(const String& name, const String& value, ExceptionState& ex ceptionState) |
106 { | 106 { |
107 // "To append a name/value (|name|/|value|) pair to a Headers object | 107 // "To append a name/value (|name|/|value|) pair to a Headers object |
108 // (|headers|), run these steps:" | 108 // (|headers|), run these steps:" |
109 // "1. If |name| is not a name or |value| is not a value, throw a | 109 // "1. Normalize value." |
110 String normalizedValue = FetchUtils::normalizeHeaderValue(value); | |
111 // "2. If |name| is not a name or |value| is not a value, throw a | |
110 // TypeError." | 112 // TypeError." |
111 if (!FetchHeaderList::isValidHeaderName(name)) { | 113 if (!FetchHeaderList::isValidHeaderName(name)) { |
112 exceptionState.throwTypeError("Invalid name"); | 114 exceptionState.throwTypeError("Invalid name"); |
113 return; | 115 return; |
114 } | 116 } |
115 if (!FetchHeaderList::isValidHeaderValue(value)) { | 117 if (!FetchHeaderList::isValidFieldContentRFC7230(normalizedValue)) { |
hiroshige
2015/09/09 07:01:48
The spec will also allow the empty string: https:/
shiva.jm
2015/09/10 10:10:26
Done.
| |
116 exceptionState.throwTypeError("Invalid value"); | 118 exceptionState.throwTypeError("Invalid value"); |
117 return; | 119 return; |
118 } | 120 } |
119 // "2. If guard is |request|, throw a TypeError." | 121 // "3. If guard is |request|, throw a TypeError." |
120 if (m_guard == ImmutableGuard) { | 122 if (m_guard == ImmutableGuard) { |
121 exceptionState.throwTypeError("Headers are immutable"); | 123 exceptionState.throwTypeError("Headers are immutable"); |
122 return; | 124 return; |
123 } | 125 } |
124 // "3. Otherwise, if guard is |request| and |name| is a forbidden header | 126 // "4. Otherwise, if guard is |request| and |name| is a forbidden header |
125 // name, return." | 127 // name, return." |
126 if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name)) | 128 if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name)) |
127 return; | 129 return; |
128 // "4. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a | 130 // "5. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a |
129 // simple header, return." | 131 // simple header, return." |
130 if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicStrin g(name), AtomicString(value))) | 132 if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicStrin g(name), AtomicString(normalizedValue))) |
131 return; | 133 return; |
132 // "5. Otherwise, if guard is |response| and |name| is a forbidden response | 134 // "6. Otherwise, if guard is |response| and |name| is a forbidden response |
133 // header name, return." | 135 // header name, return." |
134 if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(na me)) | 136 if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(na me)) |
135 return; | 137 return; |
136 // "6. Append |name|/|value| to header list." | 138 // "7. Append |name|/|value| to header list." |
137 m_headerList->append(name, value); | 139 m_headerList->append(name, normalizedValue); |
138 } | 140 } |
139 | 141 |
140 void Headers::remove(const String& name, ExceptionState& exceptionState) | 142 void Headers::remove(const String& name, ExceptionState& exceptionState) |
141 { | 143 { |
142 // "The delete(|name|) method, when invoked, must run these steps:" | 144 // "The delete(|name|) method, when invoked, must run these steps:" |
143 // "1. If name is not a name, throw a TypeError." | 145 // "1. If name is not a name, throw a TypeError." |
144 if (!FetchHeaderList::isValidHeaderName(name)) { | 146 if (!FetchHeaderList::isValidHeaderName(name)) { |
145 exceptionState.throwTypeError("Invalid name"); | 147 exceptionState.throwTypeError("Invalid name"); |
146 return; | 148 return; |
147 } | 149 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 return false; | 207 return false; |
206 } | 208 } |
207 // "2. Return true if there is a header in header list whose name is |name|, | 209 // "2. Return true if there is a header in header list whose name is |name|, |
208 // and false otherwise." | 210 // and false otherwise." |
209 return m_headerList->has(name); | 211 return m_headerList->has(name); |
210 } | 212 } |
211 | 213 |
212 void Headers::set(const String& name, const String& value, ExceptionState& excep tionState) | 214 void Headers::set(const String& name, const String& value, ExceptionState& excep tionState) |
213 { | 215 { |
214 // "The set(|name|, |value|) method, when invoked, must run these steps:" | 216 // "The set(|name|, |value|) method, when invoked, must run these steps:" |
215 // "1. If |name| is not a name or |value| is not a value, throw a | 217 // "1. Normalize value." |
218 String normalizedValue = FetchUtils::normalizeHeaderValue(value); | |
219 // "2. If |name| is not a name or |value| is not a value, throw a | |
216 // TypeError." | 220 // TypeError." |
217 if (!FetchHeaderList::isValidHeaderName(name)) { | 221 if (!FetchHeaderList::isValidHeaderName(name)) { |
218 exceptionState.throwTypeError("Invalid name"); | 222 exceptionState.throwTypeError("Invalid name"); |
219 return; | 223 return; |
220 } | 224 } |
221 if (!FetchHeaderList::isValidHeaderValue(value)) { | 225 if (!FetchHeaderList::isValidFieldContentRFC7230(normalizedValue)) { |
hiroshige
2015/09/09 07:01:48
ditto.
shiva.jm
2015/09/10 10:10:27
Done.
| |
222 exceptionState.throwTypeError("Invalid value"); | 226 exceptionState.throwTypeError("Invalid value"); |
223 return; | 227 return; |
224 } | 228 } |
225 // "2. If guard is |immutable|, throw a TypeError." | 229 // "3. If guard is |immutable|, throw a TypeError." |
226 if (m_guard == ImmutableGuard) { | 230 if (m_guard == ImmutableGuard) { |
227 exceptionState.throwTypeError("Headers are immutable"); | 231 exceptionState.throwTypeError("Headers are immutable"); |
228 return; | 232 return; |
229 } | 233 } |
230 // "3. Otherwise, if guard is |request| and |name| is a forbidden header | 234 // "4. Otherwise, if guard is |request| and |name| is a forbidden header |
231 // name, return." | 235 // name, return." |
232 if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name)) | 236 if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name)) |
233 return; | 237 return; |
234 // "4. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a | 238 // "5. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a |
235 // simple header, return." | 239 // simple header, return." |
236 if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicStrin g(name), AtomicString(value))) | 240 if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicStrin g(name), AtomicString(normalizedValue))) |
237 return; | 241 return; |
238 // "5. Otherwise, if guard is |response| and |name| is a forbidden response | 242 // "6. Otherwise, if guard is |response| and |name| is a forbidden response |
239 // header name, return." | 243 // header name, return." |
240 if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(na me)) | 244 if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(na me)) |
241 return; | 245 return; |
242 // "6. Set |name|/|value| in header list." | 246 // "7. Set |name|/|value| in header list." |
243 m_headerList->set(name, value); | 247 m_headerList->set(name, normalizedValue); |
244 } | 248 } |
245 | 249 |
246 void Headers::fillWith(const Headers* object, ExceptionState& exceptionState) | 250 void Headers::fillWith(const Headers* object, ExceptionState& exceptionState) |
247 { | 251 { |
248 ASSERT(m_headerList->size() == 0); | 252 ASSERT(m_headerList->size() == 0); |
249 // "To fill a Headers object (|this|) with a given object (|object|), run | 253 // "To fill a Headers object (|this|) with a given object (|object|), run |
250 // these steps:" | 254 // these steps:" |
251 // "1. If |object| is a Headers object, copy its header list as | 255 // "1. If |object| is a Headers object, copy its header list as |
252 // |headerListCopy| and then for each |header| in |headerListCopy|, | 256 // |headerListCopy| and then for each |header| in |headerListCopy|, |
253 // retaining order, append header's |name|/|header|'s value to | 257 // retaining order, append header's |name|/|header|'s value to |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 { | 326 { |
323 visitor->trace(m_headerList); | 327 visitor->trace(m_headerList); |
324 } | 328 } |
325 | 329 |
326 PairIterable<String, String>::IterationSource* Headers::startIteration(ScriptSta te*, ExceptionState&) | 330 PairIterable<String, String>::IterationSource* Headers::startIteration(ScriptSta te*, ExceptionState&) |
327 { | 331 { |
328 return new HeadersIterationSource(m_headerList); | 332 return new HeadersIterationSource(m_headerList); |
329 } | 333 } |
330 | 334 |
331 } // namespace blink | 335 } // namespace blink |
OLD | NEW |