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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/FetchUtils.cpp

Issue 2821003002: Replace DeprecatedEqualIgnoringCase with EqualIgnoringASCIICase in FetchUtils.h (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "platform/loader/fetch/FetchUtils.h" 5 #include "platform/loader/fetch/FetchUtils.h"
6 6
7 #include "platform/HTTPNames.h" 7 #include "platform/HTTPNames.h"
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 "platform/wtf/HashSet.h" 10 #include "platform/wtf/HashSet.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // "A simple header is a header whose name is either one of `Accept`, 88 // "A simple header is a header whose name is either one of `Accept`,
89 // `Accept-Language`, and `Content-Language`, or whose name is 89 // `Accept-Language`, and `Content-Language`, or whose name is
90 // `Content-Type` and value, once parsed, is one of 90 // `Content-Type` and value, once parsed, is one of
91 // `application/x-www-form-urlencoded`, `multipart/form-data`, and 91 // `application/x-www-form-urlencoded`, `multipart/form-data`, and
92 // `text/plain`." 92 // `text/plain`."
93 // Treat 'Save-Data' as a simple header, since it is added by Chrome when 93 // Treat 'Save-Data' as a simple header, since it is added by Chrome when
94 // Data Saver feature is enabled. 94 // Data Saver feature is enabled.
95 // Treat inspector headers as a simple headers, since they are added by blink 95 // Treat inspector headers as a simple headers, since they are added by blink
96 // when the inspector is open. 96 // when the inspector is open.
97 97
98 if (DeprecatedEqualIgnoringCase(name, "accept") || 98 if (EqualIgnoringASCIICase(name, "accept") ||
99 DeprecatedEqualIgnoringCase(name, "accept-language") || 99 EqualIgnoringASCIICase(name, "accept-language") ||
100 DeprecatedEqualIgnoringCase(name, "content-language") || 100 EqualIgnoringASCIICase(name, "content-language") ||
101 DeprecatedEqualIgnoringCase( 101 EqualIgnoringASCIICase(
102 name, HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id) || 102 name, HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id) ||
103 DeprecatedEqualIgnoringCase(name, HTTPNames::X_DevTools_Request_Id) || 103 EqualIgnoringASCIICase(name, HTTPNames::X_DevTools_Request_Id) ||
104 DeprecatedEqualIgnoringCase(name, "save-data")) 104 EqualIgnoringASCIICase(name, "save-data"))
105 return true; 105 return true;
106 106
107 if (DeprecatedEqualIgnoringCase(name, "content-type")) 107 if (EqualIgnoringASCIICase(name, "content-type"))
108 return IsSimpleContentType(value); 108 return IsSimpleContentType(value);
109 109
110 return false; 110 return false;
111 } 111 }
112 112
113 bool FetchUtils::IsSimpleContentType(const AtomicString& media_type) { 113 bool FetchUtils::IsSimpleContentType(const AtomicString& media_type) {
114 AtomicString mime_type = ExtractMIMETypeFromMediaType(media_type); 114 AtomicString mime_type = ExtractMIMETypeFromMediaType(media_type);
115 return DeprecatedEqualIgnoringCase(mime_type, 115 return EqualIgnoringASCIICase(mime_type,
116 "application/x-www-form-urlencoded") || 116 "application/x-www-form-urlencoded") ||
117 DeprecatedEqualIgnoringCase(mime_type, "multipart/form-data") || 117 EqualIgnoringASCIICase(mime_type, "multipart/form-data") ||
118 DeprecatedEqualIgnoringCase(mime_type, "text/plain"); 118 EqualIgnoringASCIICase(mime_type, "text/plain");
119 } 119 }
120 120
121 bool FetchUtils::IsSimpleRequest(const String& method, 121 bool FetchUtils::IsSimpleRequest(const String& method,
122 const HTTPHeaderMap& header_map) { 122 const HTTPHeaderMap& header_map) {
123 if (!IsSimpleMethod(method)) 123 if (!IsSimpleMethod(method))
124 return false; 124 return false;
125 125
126 for (const auto& header : header_map) { 126 for (const auto& header : header_map) {
127 // Preflight is required for MIME types that can not be sent via form 127 // Preflight is required for MIME types that can not be sent via form
128 // submission. 128 // submission.
129 if (!IsSimpleHeader(header.key, header.value)) 129 if (!IsSimpleHeader(header.key, header.value))
130 return false; 130 return false;
131 } 131 }
132 132
133 return true; 133 return true;
134 } 134 }
135 135
136 bool FetchUtils::IsForbiddenMethod(const String& method) { 136 bool FetchUtils::IsForbiddenMethod(const String& method) {
137 // http://fetch.spec.whatwg.org/#forbidden-method 137 // http://fetch.spec.whatwg.org/#forbidden-method
138 // "A forbidden method is a method that is a byte case-insensitive match" 138 // "A forbidden method is a method that is a byte case-insensitive match"
139 // for one of `CONNECT`, `TRACE`, and `TRACK`." 139 // for one of `CONNECT`, `TRACE`, and `TRACK`."
140 return DeprecatedEqualIgnoringCase(method, "TRACE") || 140 return EqualIgnoringASCIICase(method, "TRACE") ||
141 DeprecatedEqualIgnoringCase(method, "TRACK") || 141 EqualIgnoringASCIICase(method, "TRACK") ||
142 DeprecatedEqualIgnoringCase(method, "CONNECT"); 142 EqualIgnoringASCIICase(method, "CONNECT");
143 } 143 }
144 144
145 bool FetchUtils::IsForbiddenHeaderName(const String& name) { 145 bool FetchUtils::IsForbiddenHeaderName(const String& name) {
146 // http://fetch.spec.whatwg.org/#forbidden-header-name 146 // http://fetch.spec.whatwg.org/#forbidden-header-name
147 // "A forbidden header name is a header names that is one of: 147 // "A forbidden header name is a header names that is one of:
148 // `Accept-Charset`, `Accept-Encoding`, `Access-Control-Request-Headers`, 148 // `Accept-Charset`, `Accept-Encoding`, `Access-Control-Request-Headers`,
149 // `Access-Control-Request-Method`, `Connection`, 149 // `Access-Control-Request-Method`, `Connection`,
150 // `Content-Length, Cookie`, `Cookie2`, `Date`, `DNT`, `Expect`, `Host`, 150 // `Content-Length, Cookie`, `Cookie2`, `Date`, `DNT`, `Expect`, `Host`,
151 // `Keep-Alive`, `Origin`, `Referer`, `TE`, `Trailer`, 151 // `Keep-Alive`, `Origin`, `Referer`, `TE`, `Trailer`,
152 // `Transfer-Encoding`, `Upgrade`, `User-Agent`, `Via` 152 // `Transfer-Encoding`, `Upgrade`, `User-Agent`, `Via`
153 // or starts with `Proxy-` or `Sec-` (including when it is just `Proxy-` or 153 // or starts with `Proxy-` or `Sec-` (including when it is just `Proxy-` or
154 // `Sec-`)." 154 // `Sec-`)."
155 155
156 return ForbiddenHeaderNames::Get().Has(name); 156 return ForbiddenHeaderNames::Get().Has(name);
157 } 157 }
158 158
159 bool FetchUtils::IsForbiddenResponseHeaderName(const String& name) { 159 bool FetchUtils::IsForbiddenResponseHeaderName(const String& name) {
160 // http://fetch.spec.whatwg.org/#forbidden-response-header-name 160 // http://fetch.spec.whatwg.org/#forbidden-response-header-name
161 // "A forbidden response header name is a header name that is one of: 161 // "A forbidden response header name is a header name that is one of:
162 // `Set-Cookie`, `Set-Cookie2`" 162 // `Set-Cookie`, `Set-Cookie2`"
163 163
164 return DeprecatedEqualIgnoringCase(name, "set-cookie") || 164 return EqualIgnoringASCIICase(name, "set-cookie") ||
165 DeprecatedEqualIgnoringCase(name, "set-cookie2"); 165 EqualIgnoringASCIICase(name, "set-cookie2");
166 } 166 }
167 167
168 bool FetchUtils::IsSimpleOrForbiddenRequest(const String& method, 168 bool FetchUtils::IsSimpleOrForbiddenRequest(const String& method,
169 const HTTPHeaderMap& header_map) { 169 const HTTPHeaderMap& header_map) {
170 if (!IsSimpleMethod(method)) 170 if (!IsSimpleMethod(method))
171 return false; 171 return false;
172 172
173 for (const auto& header : header_map) { 173 for (const auto& header : header_map) {
174 if (!IsSimpleHeader(header.key, header.value) && 174 if (!IsSimpleHeader(header.key, header.value) &&
175 !IsForbiddenHeaderName(header.key)) 175 !IsForbiddenHeaderName(header.key))
176 return false; 176 return false;
177 } 177 }
178 178
179 return true; 179 return true;
180 } 180 }
181 181
182 AtomicString FetchUtils::NormalizeMethod(const AtomicString& method) { 182 AtomicString FetchUtils::NormalizeMethod(const AtomicString& method) {
183 // https://fetch.spec.whatwg.org/#concept-method-normalize 183 // https://fetch.spec.whatwg.org/#concept-method-normalize
184 184
185 // We place GET and POST first because they are more commonly used than 185 // We place GET and POST first because they are more commonly used than
186 // others. 186 // others.
187 const char* const kMethods[] = { 187 const char* const kMethods[] = {
188 "GET", "POST", "DELETE", "HEAD", "OPTIONS", "PUT", 188 "GET", "POST", "DELETE", "HEAD", "OPTIONS", "PUT",
189 }; 189 };
190 190
191 for (const auto& known : kMethods) { 191 for (const auto& known : kMethods) {
192 if (DeprecatedEqualIgnoringCase(method, known)) { 192 if (EqualIgnoringASCIICase(method, known)) {
193 // Don't bother allocating a new string if it's already all 193 // Don't bother allocating a new string if it's already all
194 // uppercase. 194 // uppercase.
195 return method == known ? method : known; 195 return method == known ? method : known;
196 } 196 }
197 } 197 }
198 return method; 198 return method;
199 } 199 }
200 200
201 String FetchUtils::NormalizeHeaderValue(const String& value) { 201 String FetchUtils::NormalizeHeaderValue(const String& value) {
202 // https://fetch.spec.whatwg.org/#concept-header-value-normalize 202 // https://fetch.spec.whatwg.org/#concept-header-value-normalize
203 // Strip leading and trailing whitespace from header value. 203 // Strip leading and trailing whitespace from header value.
204 // HTTP whitespace bytes are 0x09, 0x0A, 0x0D, and 0x20. 204 // HTTP whitespace bytes are 0x09, 0x0A, 0x0D, and 0x20.
205 205
206 return value.StripWhiteSpace(IsHTTPWhitespace); 206 return value.StripWhiteSpace(IsHTTPWhitespace);
207 } 207 }
208 208
209 } // namespace blink 209 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698