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

Unified Diff: third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp

Issue 1378543002: Add UMA for header values in XHR's setRequestHeader() checked against RFC 7230 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reflected comments. 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 | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp
diff --git a/third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp b/third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp
index 7e5e8ef292b0cdce0a6fcd28d3c14b48ba903465..a349e01044173ddc66cf26e3ed9ab188147b0806 100644
--- a/third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp
+++ b/third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp
@@ -70,6 +70,7 @@
#include "platform/network/ParsedContentType.h"
#include "platform/network/ResourceError.h"
#include "platform/network/ResourceRequest.h"
+#include "public/platform/Platform.h"
#include "public/platform/WebURLRequest.h"
#include "wtf/Assertions.h"
#include "wtf/StdLibExtras.h"
@@ -131,6 +132,13 @@ void logConsoleError(ExecutionContext* context, const String& message)
context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message));
}
+enum HeaderValueCategoryByRFC7230 {
+ HeaderValueInvalid,
+ HeaderValueAffectedByNormalization,
+ HeaderValueValid,
+ HeaderValueCategoryByRFC7230End
+};
+
} // namespace
class XMLHttpRequest::BlobLoader final : public GarbageCollectedFinalized<XMLHttpRequest::BlobLoader>, public FileReaderLoaderClient {
@@ -1174,10 +1182,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 + "\"");
@@ -1189,9 +1193,31 @@ void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri
void XMLHttpRequest::setRequestHeaderInternal(const AtomicString& name, const AtomicString& value)
{
+ HeaderValueCategoryByRFC7230 headerValueCategory = HeaderValueValid;
+
HTTPHeaderMap::AddResult result = m_requestHeaders.add(name, value);
- if (!result.isNewEntry)
- result.storedValue->value = result.storedValue->value + ", " + value;
+ if (!result.isNewEntry) {
+ AtomicString newValue = result.storedValue->value + ", " + value;
+
+ // 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.
+ String normalizedNewValue = FetchUtils::normalizeHeaderValue(result.storedValue->value) + ", " + FetchUtils::normalizeHeaderValue(value);
+ if (FetchUtils::normalizeHeaderValue(newValue) != normalizedNewValue)
+ headerValueCategory = HeaderValueAffectedByNormalization;
+
+ result.storedValue->value = newValue;
+ }
+
+ String normalizedValue = FetchUtils::normalizeHeaderValue(value);
+ if (!normalizedValue.isEmpty() && !isValidHTTPFieldContentRFC7230(normalizedValue))
+ headerValueCategory = HeaderValueInvalid;
+
+ Platform::current()->histogramEnumeration("Blink.XHR.setRequestHeader.HeaderValueCategoryInRFC7230", headerValueCategory, HeaderValueCategoryByRFC7230End);
}
const AtomicString& XMLHttpRequest::getRequestHeader(const AtomicString& name) const
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698