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/Headers.h" | 5 #include "modules/fetch/Headers.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/V8IteratorResultValue.h" | 8 #include "bindings/core/v8/V8IteratorResultValue.h" |
9 #include "bindings/modules/v8/ByteStringSequenceSequenceOrByteStringByteStringRe
cordOrHeaders.h" | 9 #include "bindings/modules/v8/ByteStringSequenceSequenceOrByteStringByteStringRe
cord.h" |
10 #include "core/dom/Iterator.h" | 10 #include "core/dom/Iterator.h" |
11 #include "platform/loader/fetch/FetchUtils.h" | 11 #include "platform/loader/fetch/FetchUtils.h" |
12 #include "platform/wtf/text/WTFString.h" | 12 #include "platform/wtf/text/WTFString.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class HeadersIterationSource final | 18 class HeadersIterationSource final |
19 : public PairIterable<String, String>::IterationSource { | 19 : public PairIterable<String, String>::IterationSource { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 return; | 199 return; |
200 // "5. Otherwise, if guard is |response| and |name| is a forbidden response | 200 // "5. Otherwise, if guard is |response| and |name| is a forbidden response |
201 // header name, return." | 201 // header name, return." |
202 if (guard_ == kResponseGuard && | 202 if (guard_ == kResponseGuard && |
203 FetchUtils::IsForbiddenResponseHeaderName(name)) | 203 FetchUtils::IsForbiddenResponseHeaderName(name)) |
204 return; | 204 return; |
205 // "6. Set |name|/|value| in header list." | 205 // "6. Set |name|/|value| in header list." |
206 header_list_->Set(name, value); | 206 header_list_->Set(name, value); |
207 } | 207 } |
208 | 208 |
| 209 // This overload is not called directly by Web APIs, but rather by other C++ |
| 210 // classes. For example, when initializing a Request object it is possible that |
| 211 // a Request's Headers must be filled with an existing Headers object. |
209 void Headers::FillWith(const Headers* object, ExceptionState& exception_state) { | 212 void Headers::FillWith(const Headers* object, ExceptionState& exception_state) { |
210 DCHECK(header_list_->size() == 0); | 213 DCHECK(header_list_->size() == 0); |
211 // There used to be specific steps describing filling a Headers object with | |
212 // another Headers object, but it has since been removed because it should be | |
213 // handled like a sequence (http://crbug.com/690428). | |
214 for (const auto& header : object->header_list_->List()) { | 214 for (const auto& header : object->header_list_->List()) { |
215 append(header.first, header.second, exception_state); | 215 append(header.first, header.second, exception_state); |
216 if (exception_state.HadException()) | 216 if (exception_state.HadException()) |
217 return; | 217 return; |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 void Headers::FillWith(const HeadersInit& init, | 221 void Headers::FillWith(const HeadersInit& init, |
222 ExceptionState& exception_state) { | 222 ExceptionState& exception_state) { |
223 DCHECK_EQ(header_list_->size(), 0U); | 223 DCHECK_EQ(header_list_->size(), 0U); |
224 if (init.isByteStringSequenceSequence()) { | 224 if (init.isByteStringSequenceSequence()) { |
225 FillWith(init.getAsByteStringSequenceSequence(), exception_state); | 225 FillWith(init.getAsByteStringSequenceSequence(), exception_state); |
226 } else if (init.isByteStringByteStringRecord()) { | 226 } else if (init.isByteStringByteStringRecord()) { |
227 FillWith(init.getAsByteStringByteStringRecord(), exception_state); | 227 FillWith(init.getAsByteStringByteStringRecord(), exception_state); |
228 } else if (init.isHeaders()) { | |
229 // This branch will not be necessary once http://crbug.com/690428 is fixed. | |
230 FillWith(init.getAsHeaders(), exception_state); | |
231 } else { | 228 } else { |
232 NOTREACHED(); | 229 NOTREACHED(); |
233 } | 230 } |
234 } | 231 } |
235 | 232 |
236 void Headers::FillWith(const Vector<Vector<String>>& object, | 233 void Headers::FillWith(const Vector<Vector<String>>& object, |
237 ExceptionState& exception_state) { | 234 ExceptionState& exception_state) { |
238 DCHECK(!header_list_->size()); | 235 DCHECK(!header_list_->size()); |
239 // "1. If |object| is a sequence, then for each |header| in |object|, run | 236 // "1. If |object| is a sequence, then for each |header| in |object|, run |
240 // these substeps: | 237 // these substeps: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 visitor->Trace(header_list_); | 271 visitor->Trace(header_list_); |
275 } | 272 } |
276 | 273 |
277 PairIterable<String, String>::IterationSource* Headers::StartIteration( | 274 PairIterable<String, String>::IterationSource* Headers::StartIteration( |
278 ScriptState*, | 275 ScriptState*, |
279 ExceptionState&) { | 276 ExceptionState&) { |
280 return new HeadersIterationSource(header_list_); | 277 return new HeadersIterationSource(header_list_); |
281 } | 278 } |
282 | 279 |
283 } // namespace blink | 280 } // namespace blink |
OLD | NEW |