Index: Source/core/xmlhttprequest/XMLHttpRequest.cpp |
diff --git a/Source/core/xmlhttprequest/XMLHttpRequest.cpp b/Source/core/xmlhttprequest/XMLHttpRequest.cpp |
index a16849cf16b11ad3f65b6b6b2bca4833990b8aae..82b7f7f33f9d8d121faf7a377ef7337f1ca0d79c 100644 |
--- a/Source/core/xmlhttprequest/XMLHttpRequest.cpp |
+++ b/Source/core/xmlhttprequest/XMLHttpRequest.cpp |
@@ -1183,10 +1183,6 @@ void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri |
return; |
} |
- // Show deprecation warnings and count occurrences of such deprecated header values. |
- if (!value.isEmpty() && !isValidHTTPFieldContentRFC7230(value)) |
- UseCounter::countDeprecation(executionContext(), UseCounter::HeaderValueNotMatchingRFC7230); |
- |
// No script (privileged or not) can set unsafe headers. |
if (FetchUtils::isForbiddenHeaderName(name)) { |
logConsoleError(executionContext(), "Refused to set unsafe header \"" + name + "\""); |
@@ -1198,9 +1194,32 @@ void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri |
void XMLHttpRequest::setRequestHeaderInternal(const AtomicString& name, const AtomicString& value) |
{ |
+ // We show deprecation warnings if |value| is still invalid header value |
+ // after normalization (i.e. contains invalid octets). |
+ String normalizedValue = FetchUtils::normalizeHeaderValue(value); |
+ if (!normalizedValue.isEmpty() && !isValidHTTPFieldContentRFC7230(normalizedValue)) |
+ UseCounter::countDeprecation(executionContext(), UseCounter::HeaderValueNotMatchingRFC7230); |
+ |
HTTPHeaderMap::AddResult result = m_requestHeaders.add(name, value); |
- if (!result.isNewEntry) |
- result.storedValue->value = result.storedValue->value + ", " + value; |
+ if (result.isNewEntry) |
+ return; |
+ |
+ AtomicString newValue = result.storedValue->value + ", " + value; |
+ |
+ // We show deprecation warnings if this call to setRequestHeader() is |
+ // affected by header value normalization. |
+ // Without normalization at XHR level here, the actual header value |
+ // sent to the network is |newValue| with leading/trailing whitespaces |
+ // stripped (i.e. |normalizeHeaderValue(newValue)|). |
+ // With normalization at XHR level here as the spec requires, the |
+ // actual header value sent to the network is |normalizedNewValue|. |
+ // If these two are different, introducing normalization here affects |
+ // the header value sent to the network so we show warnings. |
+ String normalizedNewValue = FetchUtils::normalizeHeaderValue(result.storedValue->value) + ", " + FetchUtils::normalizeHeaderValue(value); |
+ if (FetchUtils::normalizeHeaderValue(newValue) != normalizedNewValue) |
+ UseCounter::countDeprecation(executionContext(), UseCounter::XHRSetRequestHeaderAffectedByNormalization); |
+ |
+ result.storedValue->value = newValue; |
} |
const AtomicString& XMLHttpRequest::getRequestHeader(const AtomicString& name) const |