if (!isSimpleMethod(method))
return false;
- HTTPHeaderMap::const_iterator end = headerMap.end();
- for (HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it) {
+ for (const auto& header : headerMap) {
// Preflight is required for MIME types that can not be sent via form
// submission.
- if (!isSimpleHeader(it->key, it->value))
+ if (!isSimpleHeader(header.key, header.value))
return false;
}
if (!isSimpleMethod(method))
return false;
- HTTPHeaderMap::const_iterator end = headerMap.end();
- for (HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it) {
- if (!isSimpleHeader(it->key, it->value) && !isForbiddenHeaderName(it->key))
+ for (const auto& header : headerMap) {
+ if (!isSimpleHeader(header.key, header.value) && !isForbiddenHeaderName(header.key))
return false;
}
return true;
}
+AtomicString FetchUtils::normalizeMethod(const AtomicString& method)
+{
+ // https://fetch.spec.whatwg.org/#concept-method-normalize
+
+ // We place GET and POST first because they are more commonly used than
+ // others.
+ const char* const methods[] = {
+ "GET",
+ "POST",
+ "DELETE",
+ "HEAD",
+ "OPTIONS",
+ "PUT",
+ };
+
+ for (const auto& known : methods) {
+ if (equalIgnoringCase(method, known)) {
+ // Don't bother allocating a new string if it's already all
+ // uppercase.
+ return method == known ? method : known;
+ }
+ }
+ return method;
+}
+
} // namespace blink