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 #ifndef FetchHeaderList_h | 5 #ifndef FetchHeaderList_h |
6 #define FetchHeaderList_h | 6 #define FetchHeaderList_h |
7 | 7 |
8 #include <memory> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 #include "modules/ModulesExport.h" | 10 #include "modules/ModulesExport.h" |
11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
12 #include "platform/wtf/PassRefPtr.h" | |
13 #include "platform/wtf/Vector.h" | 12 #include "platform/wtf/Vector.h" |
14 #include "platform/wtf/text/WTFString.h" | 13 #include "platform/wtf/text/WTFString.h" |
15 | 14 |
16 namespace blink { | 15 namespace blink { |
17 | 16 |
18 class Header; | 17 class Header; |
19 | 18 |
20 // http://fetch.spec.whatwg.org/#terminology-headers | 19 // http://fetch.spec.whatwg.org/#terminology-headers |
21 class MODULES_EXPORT FetchHeaderList final | 20 class MODULES_EXPORT FetchHeaderList final |
22 : public GarbageCollectedFinalized<FetchHeaderList> { | 21 : public GarbageCollectedFinalized<FetchHeaderList> { |
23 public: | 22 public: |
| 23 struct ByteCaseInsensitiveCompare { |
| 24 bool operator()(const String& lhs, const String& rhs) const { |
| 25 return CodePointCompareLessThan(lhs.LowerASCII(), rhs.LowerASCII()); |
| 26 } |
| 27 }; |
| 28 |
24 typedef std::pair<String, String> Header; | 29 typedef std::pair<String, String> Header; |
25 static FetchHeaderList* Create(); | 30 static FetchHeaderList* Create(); |
26 FetchHeaderList* Clone() const; | 31 FetchHeaderList* Clone() const; |
27 | 32 |
28 ~FetchHeaderList(); | 33 ~FetchHeaderList(); |
29 void Append(const String&, const String&); | 34 void Append(const String&, const String&); |
30 void Set(const String&, const String&); | 35 void Set(const String&, const String&); |
31 // FIXME: Implement parse() | 36 // FIXME: Implement parse() |
32 String ExtractMIMEType() const; | 37 String ExtractMIMEType() const; |
33 | 38 |
34 size_t size() const; | 39 size_t size() const; |
35 void Remove(const String&); | 40 void Remove(const String&); |
36 bool Get(const String&, String&) const; | 41 bool Get(const String&, String&) const; |
37 void GetAll(const String&, Vector<String>&) const; | 42 void GetAll(const String&, Vector<String>&) const; |
38 bool Has(const String&) const; | 43 bool Has(const String&) const; |
39 void ClearList(); | 44 void ClearList(); |
40 | 45 |
41 bool ContainsNonSimpleHeader() const; | 46 bool ContainsNonSimpleHeader() const; |
42 void SortAndCombine(); | 47 Vector<Header> SortAndCombine() const; |
43 | 48 |
44 const Vector<std::unique_ptr<Header>>& List() const { return header_list_; } | 49 const std::multimap<String, String, ByteCaseInsensitiveCompare>& List() |
45 const Header& Entry(size_t index) const { | 50 const { |
46 return *(header_list_[index].get()); | 51 return header_list_; |
47 } | 52 } |
48 | 53 |
49 static bool IsValidHeaderName(const String&); | 54 static bool IsValidHeaderName(const String&); |
50 static bool IsValidHeaderValue(const String&); | 55 static bool IsValidHeaderValue(const String&); |
51 | 56 |
52 DEFINE_INLINE_TRACE() {} | 57 DEFINE_INLINE_TRACE() {} |
53 | 58 |
54 private: | 59 private: |
55 FetchHeaderList(); | 60 FetchHeaderList(); |
56 Vector<std::unique_ptr<Header>> header_list_; | 61 |
| 62 // While using STL data structures in Blink is not very common or |
| 63 // encouraged, we do need a multimap here. The closest WTF structure |
| 64 // comparable to what we need would be a |
| 65 // HashMap<String, Vector<String>> |
| 66 // but it is not a "flat" data structure like std::multimap is. The |
| 67 // size() of the HashMap is the number of distinct header names, not |
| 68 // the total number of headers and values on the list. |
| 69 // This would cause FetchHeaderList::size() to have to manually |
| 70 // iterate through all keys and vectors in the HashMap. Similarly, |
| 71 // list() would require callers to manually iterate through the |
| 72 // HashMap's keys and value vector, and so would |
| 73 // containsNonSimpleHeader(). |
| 74 std::multimap<String, String, ByteCaseInsensitiveCompare> header_list_; |
57 }; | 75 }; |
58 | 76 |
59 } // namespace blink | 77 } // namespace blink |
60 | 78 |
61 #endif // FetchHeaderList_h | 79 #endif // FetchHeaderList_h |
OLD | NEW |