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

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: Add HeadersInit typedef Created 3 years, 7 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 Vector<std::pair<String, String>> headers_; 45 Vector<std::pair<String, String>> headers_;
46 size_t current_; 46 size_t current_;
47 }; 47 };
48 48
49 } // namespace 49 } // namespace
50 50
51 Headers* Headers::Create(ExceptionState&) { 51 Headers* Headers::Create(ExceptionState&) {
52 return new Headers; 52 return new Headers;
53 } 53 }
54 54
55 Headers* Headers::Create( 55 Headers* Headers::Create(const HeadersInit& init,
56 const ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders& init, 56 ExceptionState& exception_state) {
57 ExceptionState& exception_state) {
58 // "The Headers(|init|) constructor, when invoked, must run these steps:" 57 // "The Headers(|init|) constructor, when invoked, must run these steps:"
59 // "1. Let |headers| be a new Headers object whose guard is "none". 58 // "1. Let |headers| be a new Headers object whose guard is "none".
60 Headers* headers = Create(exception_state); 59 Headers* headers = Create(exception_state);
61 // "2. If |init| is given, fill headers with |init|. Rethrow any exception." 60 // "2. If |init| is given, fill headers with |init|. Rethrow any exception."
62 if (init.isByteStringSequenceSequence()) { 61 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|." 62 // "3. Return |headers|."
73 return headers; 63 return headers;
74 } 64 }
75 65
76 Headers* Headers::Create(FetchHeaderList* header_list) { 66 Headers* Headers::Create(FetchHeaderList* header_list) {
77 return new Headers(header_list); 67 return new Headers(header_list);
78 } 68 }
79 69
80 Headers* Headers::Clone() const { 70 Headers* Headers::Clone() const {
81 FetchHeaderList* header_list = header_list_->Clone(); 71 FetchHeaderList* header_list = header_list_->Clone();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // There used to be specific steps describing filling a Headers object with 211 // There used to be specific steps describing filling a Headers object with
222 // another Headers object, but it has since been removed because it should be 212 // another Headers object, but it has since been removed because it should be
223 // handled like a sequence (http://crbug.com/690428). 213 // handled like a sequence (http://crbug.com/690428).
224 for (const auto& header : object->header_list_->List()) { 214 for (const auto& header : object->header_list_->List()) {
225 append(header.first, header.second, exception_state); 215 append(header.first, header.second, exception_state);
226 if (exception_state.HadException()) 216 if (exception_state.HadException())
227 return; 217 return;
228 } 218 }
229 } 219 }
230 220
221 void Headers::FillWith(const HeadersInit& init,
222 ExceptionState& exception_state) {
223 DCHECK_EQ(header_list_->size(), 0U);
224 if (init.isByteStringSequenceSequence()) {
225 FillWith(init.getAsByteStringSequenceSequence(), exception_state);
226 } else if (init.isByteStringByteStringRecord()) {
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 {
232 NOTREACHED();
233 }
234 }
235
231 void Headers::FillWith(const Vector<Vector<String>>& object, 236 void Headers::FillWith(const Vector<Vector<String>>& object,
232 ExceptionState& exception_state) { 237 ExceptionState& exception_state) {
233 DCHECK(!header_list_->size()); 238 DCHECK(!header_list_->size());
234 // "1. If |object| is a sequence, then for each |header| in |object|, run 239 // "1. If |object| is a sequence, then for each |header| in |object|, run
235 // these substeps: 240 // these substeps:
236 // 1. If |header| does not contain exactly two items, then throw a 241 // 1. If |header| does not contain exactly two items, then throw a
237 // TypeError. 242 // TypeError.
238 // 2. Append |header|’s first item/|header|’s second item to |headers|. 243 // 2. Append |header|’s first item/|header|’s second item to |headers|.
239 // Rethrow any exception." 244 // Rethrow any exception."
240 for (size_t i = 0; i < object.size(); ++i) { 245 for (size_t i = 0; i < object.size(); ++i) {
(...skipping 28 matching lines...) Expand all
269 visitor->Trace(header_list_); 274 visitor->Trace(header_list_);
270 } 275 }
271 276
272 PairIterable<String, String>::IterationSource* Headers::StartIteration( 277 PairIterable<String, String>::IterationSource* Headers::StartIteration(
273 ScriptState*, 278 ScriptState*,
274 ExceptionState&) { 279 ExceptionState&) {
275 return new HeadersIterationSource(header_list_); 280 return new HeadersIterationSource(header_list_);
276 } 281 }
277 282
278 } // namespace blink 283 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698