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

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

Issue 2839683003: Server-Timing (Closed)
Patch Set: make those robots happy, attempt #4 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 9721bf6c1c4a765922aa8b02368d5166abb222fb..c7d792cbd56cf85b30d1796a1a3180b8e7b3da62 100644
--- a/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
+++ b/third_party/WebKit/Source/platform/network/HTTPParsers.cpp
@@ -849,4 +849,67 @@ bool ParseContentRangeHeaderFor206(const String& content_range,
last_byte_position, instance_length);
}
+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 != end && *position == '=') {
+ position = ParseServerTimingToken(position + 1, end, value);
+ }
+ if (position != end && *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