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

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

Issue 2840193002: fetch: Align RequestInit's |headers| with the spec. (Closed)
Patch Set: Created 3 years, 8 months 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/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 cordOrHeaders.h"
10 #include "core/dom/Iterator.h" 10 #include "core/dom/Iterator.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return new Headers; 52 return new Headers;
53 } 53 }
54 54
55 Headers* Headers::Create( 55 Headers* Headers::Create(
56 const ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders& init, 56 const ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders& init,
57 ExceptionState& exception_state) { 57 ExceptionState& exception_state) {
58 // "The Headers(|init|) constructor, when invoked, must run these steps:" 58 // "The Headers(|init|) constructor, when invoked, must run these steps:"
59 // "1. Let |headers| be a new Headers object whose guard is "none". 59 // "1. Let |headers| be a new Headers object whose guard is "none".
60 Headers* headers = Create(exception_state); 60 Headers* headers = Create(exception_state);
61 // "2. If |init| is given, fill headers with |init|. Rethrow any exception." 61 // "2. If |init| is given, fill headers with |init|. Rethrow any exception."
62 if (init.isByteStringSequenceSequence()) { 62 headers->FillWith(init, exception_state);
63 headers->FillWith(init.getAsByteStringSequenceSequence(), exception_state);
64 } else if (init.isByteStringByteStringRecord()) {
65 headers->FillWith(init.getAsByteStringByteStringRecord(), exception_state);
66 } else if (init.isHeaders()) {
67 // This branch will not be necessary once http://crbug.com/690428 is fixed.
68 headers->FillWith(init.getAsHeaders(), exception_state);
69 } else {
70 NOTREACHED();
71 }
72 // "3. Return |headers|." 63 // "3. Return |headers|."
73 return headers; 64 return headers;
74 } 65 }
75 66
76 Headers* Headers::Create(FetchHeaderList* header_list) { 67 Headers* Headers::Create(FetchHeaderList* header_list) {
77 return new Headers(header_list); 68 return new Headers(header_list);
78 } 69 }
79 70
80 Headers* Headers::Clone() const { 71 Headers* Headers::Clone() const {
81 FetchHeaderList* header_list = header_list_->Clone(); 72 FetchHeaderList* header_list = header_list_->Clone();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // There used to be specific steps describing filling a Headers object with 227 // There used to be specific steps describing filling a Headers object with
237 // another Headers object, but it has since been removed because it should be 228 // another Headers object, but it has since been removed because it should be
238 // handled like a sequence (http://crbug.com/690428). 229 // handled like a sequence (http://crbug.com/690428).
239 for (const auto& header : object->header_list_->List()) { 230 for (const auto& header : object->header_list_->List()) {
240 append(header.first, header.second, exception_state); 231 append(header.first, header.second, exception_state);
241 if (exception_state.HadException()) 232 if (exception_state.HadException())
242 return; 233 return;
243 } 234 }
244 } 235 }
245 236
237 void Headers::FillWith(
238 const ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders& init,
239 ExceptionState& exception_state) {
240 DCHECK_EQ(header_list_->size(), 0U);
241 if (init.isByteStringSequenceSequence()) {
242 FillWith(init.getAsByteStringSequenceSequence(), exception_state);
243 } else if (init.isByteStringByteStringRecord()) {
244 FillWith(init.getAsByteStringByteStringRecord(), exception_state);
245 } else if (init.isHeaders()) {
246 // This branch will not be necessary once http://crbug.com/690428 is fixed.
247 FillWith(init.getAsHeaders(), exception_state);
248 } else {
249 NOTREACHED();
250 }
251 }
252
246 void Headers::FillWith(const Vector<Vector<String>>& object, 253 void Headers::FillWith(const Vector<Vector<String>>& object,
247 ExceptionState& exception_state) { 254 ExceptionState& exception_state) {
248 DCHECK(!header_list_->size()); 255 DCHECK(!header_list_->size());
249 // "1. If |object| is a sequence, then for each |header| in |object|, run 256 // "1. If |object| is a sequence, then for each |header| in |object|, run
250 // these substeps: 257 // these substeps:
251 // 1. If |header| does not contain exactly two items, then throw a 258 // 1. If |header| does not contain exactly two items, then throw a
252 // TypeError. 259 // TypeError.
253 // 2. Append |header|’s first item/|header|’s second item to |headers|. 260 // 2. Append |header|’s first item/|header|’s second item to |headers|.
254 // Rethrow any exception." 261 // Rethrow any exception."
255 for (size_t i = 0; i < object.size(); ++i) { 262 for (size_t i = 0; i < object.size(); ++i) {
(...skipping 28 matching lines...) Expand all
284 visitor->Trace(header_list_); 291 visitor->Trace(header_list_);
285 } 292 }
286 293
287 PairIterable<String, String>::IterationSource* Headers::StartIteration( 294 PairIterable<String, String>::IterationSource* Headers::StartIteration(
288 ScriptState*, 295 ScriptState*,
289 ExceptionState&) { 296 ExceptionState&) {
290 return new HeadersIterationSource(header_list_); 297 return new HeadersIterationSource(header_list_);
291 } 298 }
292 299
293 } // namespace blink 300 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698