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

Unified Diff: third_party/WebKit/Source/platform/network/HTTPParsers.cpp

Issue 2799093004: Enable ServerTiming support
Patch Set: update code formatting and comments Created 3 years, 8 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
Index: third_party/WebKit/Source/platform/network/HTTPParsers.cpp
diff --git a/third_party/WebKit/Source/platform/network/HTTPParsers.cpp b/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
index d94093a296bd570b116ee3a9e24615b998b62859..f18db6f124c256080d56c23dd9e9480b5d6d8e53 100644
--- a/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
+++ b/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
@@ -871,4 +871,67 @@ bool parseContentRangeHeaderFor206(const String& contentRange,
lastBytePosition, instanceLength);
}
+template <typename CharType>
+inline bool isNotServerTimingHeaderDelimiter(CharType c) {
+ return c != '=' && c != ';' && c != ',';
+}
+
+const LChar* parseServerTimingToken(const LChar* begin,
+ const LChar* end,
+ String& result) {
+ const LChar* position = begin;
+ skipWhile<LChar, isNotServerTimingHeaderDelimiter>(position, end);
+ result = String(begin, position - begin).stripWhiteSpace();
+ return position;
+}
+
+String checkDoubleQuotedString(const String& value) {
+ if (value.length() < 2 || value[0] != '"' ||
+ value[value.length() - 1] != '"') {
+ return value;
+ }
+
+ StringBuilder out;
+ unsigned pos = 1; // Begin after the opening DQUOTE.
+ unsigned len = value.length() - 1; // End before the closing DQUOTE.
+
+ // Skip past backslashes, but include everything else.
+ while (pos < len) {
+ if (value[pos] == '\\')
+ pos++;
+ if (pos < len)
+ out.append(value[pos++]);
+ }
+
+ return out.toString();
+}
+
+std::unique_ptr<ServerTimingHeaderVector> parseServerTimingHeader(
+ const String& headerValue) {
+ std::unique_ptr<ServerTimingHeaderVector> headers =
+ WTF::makeUnique<ServerTimingHeaderVector>();
+
+ if (!headerValue.isNull()) {
+ DCHECK(headerValue.is8Bit());
+
+ const LChar* position = headerValue.characters8();
+ const LChar* end = position + headerValue.length();
+ while (position < end) {
+ String metric, value, description = "";
+ position = parseServerTimingToken(position, end, metric);
+ if (*position == '=') {
+ position = parseServerTimingToken(position + 1, end, value);
+ }
+ if (*position == ';') {
+ position = parseServerTimingToken(position + 1, end, description);
+ }
+ position++;
+
+ headers->push_back(WTF::makeUnique<ServerTimingHeader>(
+ metric, value.toDouble(), checkDoubleQuotedString(description)));
+ }
+ }
+ return headers;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698