Chromium Code Reviews| Index: Source/modules/fetch/Headers.cpp |
| diff --git a/Source/modules/fetch/Headers.cpp b/Source/modules/fetch/Headers.cpp |
| index 4fa638b4248e2577deb746a1c373fe3ccb26f5dd..1cad1716b93955f99ddd8728404d0da090c46aa5 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::isValidFieldContentRFC7230(normalizedValue)) { |
|
hiroshige
2015/09/09 07:01:48
The spec will also allow the empty string: https:/
shiva.jm
2015/09/10 10:10:26
Done.
|
| 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::isValidFieldContentRFC7230(normalizedValue)) { |
|
hiroshige
2015/09/09 07:01:48
ditto.
shiva.jm
2015/09/10 10:10:27
Done.
|
| 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) |