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 "config.h" | 5 #include "config.h" |
6 #include "core/fetch/FetchUtils.h" | 6 #include "core/fetch/FetchUtils.h" |
7 | 7 |
8 #include "platform/network/HTTPHeaderMap.h" | 8 #include "platform/network/HTTPHeaderMap.h" |
9 #include "platform/network/HTTPParsers.h" | 9 #include "platform/network/HTTPParsers.h" |
10 #include "wtf/HashSet.h" | 10 #include "wtf/HashSet.h" |
11 #include "wtf/Threading.h" | 11 #include "wtf/Threading.h" |
12 #include "wtf/text/AtomicString.h" | 12 #include "wtf/text/AtomicString.h" |
13 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class ForbiddenHeaderNames { | 19 class ForbiddenHeaderNames { |
20 WTF_MAKE_NONCOPYABLE(ForbiddenHeaderNames); WTF_MAKE_FAST_ALLOCATED; | 20 WTF_MAKE_NONCOPYABLE(ForbiddenHeaderNames); WTF_MAKE_FAST_ALLOCATED; |
21 public: | 21 public: |
22 bool has(const String& name) const | 22 bool has(const String& name) const |
23 { | 23 { |
24 return m_fixedNames.contains(name) | 24 return m_fixedNames.contains(name) |
25 || name.startsWith(m_proxyHeaderPrefix, false) | 25 || name.startsWith(m_proxyHeaderPrefix, false) |
26 || name.startsWith(m_secHeaderPrefix, false); | 26 || name.startsWith(m_secHeaderPrefix, false); |
27 } | 27 } |
28 | 28 |
29 static const ForbiddenHeaderNames* get(); | 29 static const ForbiddenHeaderNames& get(); |
30 | 30 |
31 private: | 31 private: |
32 ForbiddenHeaderNames(); | 32 ForbiddenHeaderNames(); |
33 | 33 |
34 String m_proxyHeaderPrefix; | 34 String m_proxyHeaderPrefix; |
35 String m_secHeaderPrefix; | 35 String m_secHeaderPrefix; |
36 HashSet<String, CaseFoldingHash> m_fixedNames; | 36 HashSet<String, CaseFoldingHash> m_fixedNames; |
37 }; | 37 }; |
38 | 38 |
39 ForbiddenHeaderNames::ForbiddenHeaderNames() | 39 ForbiddenHeaderNames::ForbiddenHeaderNames() |
(...skipping 16 matching lines...) Expand all Loading... |
56 m_fixedNames.add("origin"); | 56 m_fixedNames.add("origin"); |
57 m_fixedNames.add("referer"); | 57 m_fixedNames.add("referer"); |
58 m_fixedNames.add("te"); | 58 m_fixedNames.add("te"); |
59 m_fixedNames.add("trailer"); | 59 m_fixedNames.add("trailer"); |
60 m_fixedNames.add("transfer-encoding"); | 60 m_fixedNames.add("transfer-encoding"); |
61 m_fixedNames.add("upgrade"); | 61 m_fixedNames.add("upgrade"); |
62 m_fixedNames.add("user-agent"); | 62 m_fixedNames.add("user-agent"); |
63 m_fixedNames.add("via"); | 63 m_fixedNames.add("via"); |
64 } | 64 } |
65 | 65 |
66 const ForbiddenHeaderNames* ForbiddenHeaderNames::get() | 66 const ForbiddenHeaderNames& ForbiddenHeaderNames::get() |
67 { | 67 { |
68 AtomicallyInitializedStatic(const ForbiddenHeaderNames*, instance = new Forb
iddenHeaderNames); | 68 AtomicallyInitializedStaticReference(const ForbiddenHeaderNames, instance, n
ew ForbiddenHeaderNames); |
69 return instance; | 69 return instance; |
70 } | 70 } |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 bool FetchUtils::isSimpleMethod(const String& method) | 74 bool FetchUtils::isSimpleMethod(const String& method) |
75 { | 75 { |
76 // http://fetch.spec.whatwg.org/#simple-method | 76 // http://fetch.spec.whatwg.org/#simple-method |
77 // "A simple method is a method that is `GET`, `HEAD`, or `POST`." | 77 // "A simple method is a method that is `GET`, `HEAD`, or `POST`." |
78 return method == "GET" || method == "HEAD" || method == "POST"; | 78 return method == "GET" || method == "HEAD" || method == "POST"; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // http://fetch.spec.whatwg.org/#forbidden-header-name | 132 // http://fetch.spec.whatwg.org/#forbidden-header-name |
133 // "A forbidden header name is a header names that is one of: | 133 // "A forbidden header name is a header names that is one of: |
134 // `Accept-Charset`, `Accept-Encoding`, `Access-Control-Request-Headers`, | 134 // `Accept-Charset`, `Accept-Encoding`, `Access-Control-Request-Headers`, |
135 // `Access-Control-Request-Method`, `Connection`, | 135 // `Access-Control-Request-Method`, `Connection`, |
136 // `Content-Length, Cookie`, `Cookie2`, `Date`, `DNT`, `Expect`, `Host`, | 136 // `Content-Length, Cookie`, `Cookie2`, `Date`, `DNT`, `Expect`, `Host`, |
137 // `Keep-Alive`, `Origin`, `Referer`, `TE`, `Trailer`, | 137 // `Keep-Alive`, `Origin`, `Referer`, `TE`, `Trailer`, |
138 // `Transfer-Encoding`, `Upgrade`, `User-Agent`, `Via` | 138 // `Transfer-Encoding`, `Upgrade`, `User-Agent`, `Via` |
139 // or starts with `Proxy-` or `Sec-` (including when it is just `Proxy-` or | 139 // or starts with `Proxy-` or `Sec-` (including when it is just `Proxy-` or |
140 // `Sec-`)." | 140 // `Sec-`)." |
141 | 141 |
142 return ForbiddenHeaderNames::get()->has(name); | 142 return ForbiddenHeaderNames::get().has(name); |
143 } | 143 } |
144 | 144 |
145 bool FetchUtils::isForbiddenResponseHeaderName(const String& name) | 145 bool FetchUtils::isForbiddenResponseHeaderName(const String& name) |
146 { | 146 { |
147 // http://fetch.spec.whatwg.org/#forbidden-response-header-name | 147 // http://fetch.spec.whatwg.org/#forbidden-response-header-name |
148 // "A forbidden response header name is a header name that is one of: | 148 // "A forbidden response header name is a header name that is one of: |
149 // `Set-Cookie`, `Set-Cookie2`" | 149 // `Set-Cookie`, `Set-Cookie2`" |
150 | 150 |
151 return equalIgnoringCase(name, "set-cookie") || equalIgnoringCase(name, "set
-cookie2"); | 151 return equalIgnoringCase(name, "set-cookie") || equalIgnoringCase(name, "set
-cookie2"); |
152 } | 152 } |
(...skipping 30 matching lines...) Expand all Loading... |
183 if (equalIgnoringCase(method, known)) { | 183 if (equalIgnoringCase(method, known)) { |
184 // Don't bother allocating a new string if it's already all | 184 // Don't bother allocating a new string if it's already all |
185 // uppercase. | 185 // uppercase. |
186 return method == known ? method : known; | 186 return method == known ? method : known; |
187 } | 187 } |
188 } | 188 } |
189 return method; | 189 return method; |
190 } | 190 } |
191 | 191 |
192 } // namespace blink | 192 } // namespace blink |
OLD | NEW |