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

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

Issue 2787003002: Fetch API: Stop lowercasing header names. (Closed)
Patch Set: Rebase for landing 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"
11 #include "platform/loader/fetch/FetchUtils.h" 11 #include "platform/loader/fetch/FetchUtils.h"
12 #include "platform/wtf/NotFound.h"
13 #include "platform/wtf/PassRefPtr.h"
14 #include "platform/wtf/RefPtr.h"
15 #include "platform/wtf/text/WTFString.h" 12 #include "platform/wtf/text/WTFString.h"
16 13
17 namespace blink { 14 namespace blink {
18 15
19 namespace { 16 namespace {
20 17
21 class HeadersIterationSource final 18 class HeadersIterationSource final
22 : public PairIterable<String, String>::IterationSource { 19 : public PairIterable<String, String>::IterationSource {
23 public: 20 public:
24 explicit HeadersIterationSource(const FetchHeaderList* headers) 21 explicit HeadersIterationSource(const FetchHeaderList* headers)
25 : headers_(headers->Clone()), current_(0) { 22 : headers_(headers->SortAndCombine()), current_(0) {}
26 headers_->SortAndCombine();
27 }
28 23
29 bool Next(ScriptState* script_state, 24 bool Next(ScriptState* script_state,
30 String& key, 25 String& key,
31 String& value, 26 String& value,
32 ExceptionState& exception) override { 27 ExceptionState& exception) override {
33 // This simply advances an index and returns the next value if any; the 28 // This simply advances an index and returns the next value if any; the
34 // iterated list is not exposed to script so it will never be mutated 29 // iterated list is not exposed to script so it will never be mutated
35 // during iteration. 30 // during iteration.
36 if (current_ >= headers_->size()) 31 if (current_ >= headers_.size())
37 return false; 32 return false;
38 33
39 const FetchHeaderList::Header& header = headers_->Entry(current_++); 34 const FetchHeaderList::Header& header = headers_.at(current_++);
40 key = header.first; 35 key = header.first;
41 value = header.second; 36 value = header.second;
42 return true; 37 return true;
43 } 38 }
44 39
45 DEFINE_INLINE_VIRTUAL_TRACE() { 40 DEFINE_INLINE_VIRTUAL_TRACE() {
46 visitor->Trace(headers_);
47 PairIterable<String, String>::IterationSource::Trace(visitor); 41 PairIterable<String, String>::IterationSource::Trace(visitor);
48 } 42 }
49 43
50 private: 44 private:
51 const Member<FetchHeaderList> headers_; 45 Vector<std::pair<String, String>> headers_;
52 size_t current_; 46 size_t current_;
53 }; 47 };
54 48
55 } // namespace 49 } // namespace
56 50
57 Headers* Headers::Create(ExceptionState&) { 51 Headers* Headers::Create(ExceptionState&) {
58 return new Headers; 52 return new Headers;
59 } 53 }
60 54
61 Headers* Headers::Create( 55 Headers* Headers::Create(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return; 229 return;
236 // "6. Set |name|/|value| in header list." 230 // "6. Set |name|/|value| in header list."
237 header_list_->Set(name, value); 231 header_list_->Set(name, value);
238 } 232 }
239 233
240 void Headers::FillWith(const Headers* object, ExceptionState& exception_state) { 234 void Headers::FillWith(const Headers* object, ExceptionState& exception_state) {
241 DCHECK(header_list_->size() == 0); 235 DCHECK(header_list_->size() == 0);
242 // There used to be specific steps describing filling a Headers object with 236 // There used to be specific steps describing filling a Headers object with
243 // another Headers object, but it has since been removed because it should be 237 // another Headers object, but it has since been removed because it should be
244 // handled like a sequence (http://crbug.com/690428). 238 // handled like a sequence (http://crbug.com/690428).
245 for (size_t i = 0; i < object->header_list_->List().size(); ++i) { 239 for (const auto& header : object->header_list_->List()) {
246 append(object->header_list_->List()[i]->first, 240 append(header.first, header.second, exception_state);
247 object->header_list_->List()[i]->second, exception_state);
248 if (exception_state.HadException()) 241 if (exception_state.HadException())
249 return; 242 return;
250 } 243 }
251 } 244 }
252 245
253 void Headers::FillWith(const Vector<Vector<String>>& object, 246 void Headers::FillWith(const Vector<Vector<String>>& object,
254 ExceptionState& exception_state) { 247 ExceptionState& exception_state) {
255 DCHECK(!header_list_->size()); 248 DCHECK(!header_list_->size());
256 // "1. If |object| is a sequence, then for each |header| in |object|, run 249 // "1. If |object| is a sequence, then for each |header| in |object|, run
257 // these substeps: 250 // these substeps:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 visitor->Trace(header_list_); 284 visitor->Trace(header_list_);
292 } 285 }
293 286
294 PairIterable<String, String>::IterationSource* Headers::StartIteration( 287 PairIterable<String, String>::IterationSource* Headers::StartIteration(
295 ScriptState*, 288 ScriptState*,
296 ExceptionState&) { 289 ExceptionState&) {
297 return new HeadersIterationSource(header_list_); 290 return new HeadersIterationSource(header_list_);
298 } 291 }
299 292
300 } // namespace blink 293 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/FetchResponseData.cpp ('k') | third_party/WebKit/Source/modules/fetch/Request.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698