Chromium Code Reviews| 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..37b7f1a2c8cd1e9869db6eadca9750d33210cacb 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, |
| + len = value.length() - |
| + 1; // begin after the opening DQUOTE, end before the closing DQUOTE |
|
Yoav Weiss
2017/04/06 20:19:55
Nit: formatting is weird. Move the comment to the
|
| + while (pos < len) { |
| + if (value[pos] == '\\') |
| + pos++; // skip right past the backslash |
|
Yoav Weiss
2017/04/06 20:19:55
Can you move the comments to above the `while` so
|
| + if (pos < len) |
| + out.append(value[pos++]); // but include everything else |
| + } |
| + |
| + 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 |