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 60b925029db11a41d0c22b37c0c6478617606c0f..3cd06675f951c2996db1d37186689fec879858cc 100644 |
| --- a/third_party/WebKit/Source/platform/network/HTTPParsers.cpp |
| +++ b/third_party/WebKit/Source/platform/network/HTTPParsers.cpp |
| @@ -849,41 +849,6 @@ 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 = |
| @@ -892,21 +857,28 @@ std::unique_ptr<ServerTimingHeaderVector> ParseServerTimingHeader( |
| 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); |
| + unsigned index = 0; |
| + while (index < headerValue.length()) { |
| + StringView metric; |
| + if (!ConsumeToken(Mode::kNormal, headerValue, index, metric)) { |
| + continue; |
| + } |
| + |
| + StringView duration; |
| + String description; |
| + if (Consume('=', headerValue, index)) { |
| + ConsumeToken(Mode::kNormal, headerValue, index, duration); |
| } |
| - if (position != end && *position == ';') { |
| - position = ParseServerTimingToken(position + 1, end, description); |
| + if (Consume(';', headerValue, index)) { |
| + ConsumeTokenOrQuotedString(Mode::kNormal, headerValue, index, |
| + description); |
| } |
| - position++; |
| headers->push_back(WTF::MakeUnique<ServerTimingHeader>( |
| - metric, value.ToDouble(), CheckDoubleQuotedString(description))); |
| + metric.ToString(), duration.ToString().ToDouble(), |
| + description ? description : "")); |
| + |
| + Consume(',', headerValue, index); |
| } |
| } |
| return headers; |
| @@ -944,6 +916,7 @@ bool IsTokenCharacter(Mode mode, UChar c) { |
| bool Consume(char c, const String& input, unsigned& index) { |
| DCHECK_NE(c, ' '); |
| + // TODO: skip all whitespace, not just spaces |
|
Yoav Weiss
2017/05/18 21:45:05
The format should be `// TODO(cvazac): ...`. Also
|
| while (index < input.length() && input[index] == ' ') |
| ++index; |
| @@ -960,6 +933,7 @@ bool ConsumeToken(Mode mode, |
| StringView& output) { |
| DCHECK(output.IsNull()); |
| + // TODO: skip all whitespace, not just spaces |
| while (index < input.length() && input[index] == ' ') |
| ++index; |
| @@ -1002,6 +976,7 @@ bool ConsumeTokenOrQuotedString(Mode mode, |
| const String& input, |
| unsigned& index, |
| String& output) { |
| + // TODO: skip all whitespace, not just spaces |
| while (index < input.length() && input[index] == ' ') |
| ++index; |
| if (input.length() == index) |
| @@ -1017,6 +992,7 @@ bool ConsumeTokenOrQuotedString(Mode mode, |
| bool IsEnd(const String& input, unsigned index) { |
| while (index < input.length()) { |
| + // TODO: skip all whitespace, not just spaces |
| if (input[index] != ' ') |
| return false; |
| ++index; |