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

Unified Diff: Source/modules/fetch/Headers.cpp

Issue 1288263003: Normalize and update the header value checks to RFC 7230 for Fetch Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/fetch/FetchHeaderList.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/fetch/Headers.cpp
diff --git a/Source/modules/fetch/Headers.cpp b/Source/modules/fetch/Headers.cpp
index 4fa638b4248e2577deb746a1c373fe3ccb26f5dd..85d13f62e66fa47ec8c46789f3f12bd5a6ac0179 100644
--- a/Source/modules/fetch/Headers.cpp
+++ b/Source/modules/fetch/Headers.cpp
@@ -106,35 +106,37 @@ void Headers::append(const String& name, const String& value, ExceptionState& ex
{
// "To append a name/value (|name|/|value|) pair to a Headers object
// (|headers|), run these steps:"
- // "1. If |name| is not a name or |value| is not a value, throw a
+ // "1. Normalize |value|."
+ String normalizedValue = FetchUtils::normalizeHeaderValue(value);
+ // "2. If |name| is not a name or |value| is not a value, throw a
// TypeError."
if (!FetchHeaderList::isValidHeaderName(name)) {
exceptionState.throwTypeError("Invalid name");
return;
}
- if (!FetchHeaderList::isValidHeaderValue(value)) {
+ if (!FetchHeaderList::isValidHeaderValueRFC7230(normalizedValue)) {
exceptionState.throwTypeError("Invalid value");
return;
}
- // "2. If guard is |request|, throw a TypeError."
+ // "3. If guard is |request|, throw a TypeError."
if (m_guard == ImmutableGuard) {
exceptionState.throwTypeError("Headers are immutable");
return;
}
- // "3. Otherwise, if guard is |request| and |name| is a forbidden header
+ // "4. Otherwise, if guard is |request| and |name| is a forbidden header
// name, return."
if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name))
return;
- // "4. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a
+ // "5. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a
// simple header, return."
- if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicString(name), AtomicString(value)))
+ if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicString(name), AtomicString(normalizedValue)))
return;
- // "5. Otherwise, if guard is |response| and |name| is a forbidden response
+ // "6. Otherwise, if guard is |response| and |name| is a forbidden response
// header name, return."
if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(name))
return;
- // "6. Append |name|/|value| to header list."
- m_headerList->append(name, value);
+ // "7. Append |name|/|value| to header list."
+ m_headerList->append(name, normalizedValue);
}
void Headers::remove(const String& name, ExceptionState& exceptionState)
@@ -212,35 +214,37 @@ bool Headers::has(const String& name, ExceptionState& exceptionState)
void Headers::set(const String& name, const String& value, ExceptionState& exceptionState)
{
// "The set(|name|, |value|) method, when invoked, must run these steps:"
- // "1. If |name| is not a name or |value| is not a value, throw a
+ // "1. Normalize |value|."
+ String normalizedValue = FetchUtils::normalizeHeaderValue(value);
+ // "2. If |name| is not a name or |value| is not a value, throw a
// TypeError."
if (!FetchHeaderList::isValidHeaderName(name)) {
exceptionState.throwTypeError("Invalid name");
return;
}
- if (!FetchHeaderList::isValidHeaderValue(value)) {
+ if (!FetchHeaderList::isValidHeaderValueRFC7230(normalizedValue)) {
exceptionState.throwTypeError("Invalid value");
return;
}
- // "2. If guard is |immutable|, throw a TypeError."
+ // "3. If guard is |immutable|, throw a TypeError."
if (m_guard == ImmutableGuard) {
exceptionState.throwTypeError("Headers are immutable");
return;
}
- // "3. Otherwise, if guard is |request| and |name| is a forbidden header
+ // "4. Otherwise, if guard is |request| and |name| is a forbidden header
// name, return."
if (m_guard == RequestGuard && FetchUtils::isForbiddenHeaderName(name))
return;
- // "4. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a
+ // "5. Otherwise, if guard is |request-no-CORS| and |name|/|value| is not a
// simple header, return."
- if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicString(name), AtomicString(value)))
+ if (m_guard == RequestNoCORSGuard && !FetchUtils::isSimpleHeader(AtomicString(name), AtomicString(normalizedValue)))
return;
- // "5. Otherwise, if guard is |response| and |name| is a forbidden response
+ // "6. Otherwise, if guard is |response| and |name| is a forbidden response
// header name, return."
if (m_guard == ResponseGuard && FetchUtils::isForbiddenResponseHeaderName(name))
return;
- // "6. Set |name|/|value| in header list."
- m_headerList->set(name, value);
+ // "7. Set |name|/|value| in header list."
+ m_headerList->set(name, normalizedValue);
}
void Headers::fillWith(const Headers* object, ExceptionState& exceptionState)
« no previous file with comments | « Source/modules/fetch/FetchHeaderList.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698