Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 3 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 4 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
| 5 * Copyright (C) 2009 Google Inc. All rights reserved. | 5 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 6 * Copyright (C) 2011 Apple Inc. All Rights Reserved. | 6 * Copyright (C) 2011 Apple Inc. All Rights Reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 */ | 31 */ |
| 32 | 32 |
| 33 #include "platform/network/HTTPParsers.h" | 33 #include "platform/network/HTTPParsers.h" |
| 34 | 34 |
| 35 #include "net/http/http_content_disposition.h" | 35 #include "net/http/http_content_disposition.h" |
| 36 #include "net/http/http_response_headers.h" | 36 #include "net/http/http_response_headers.h" |
| 37 #include "net/http/http_util.h" | 37 #include "net/http/http_util.h" |
| 38 #include "platform/HTTPNames.h" | 38 #include "platform/HTTPNames.h" |
| 39 #include "platform/json/JSONParser.h" | 39 #include "platform/json/JSONParser.h" |
| 40 #include "platform/loader/fetch/ResourceResponse.h" | 40 #include "platform/loader/fetch/ResourceResponse.h" |
| 41 #include "platform/network/HeaderFieldTokenizer.h" | |
| 41 #include "platform/weborigin/Suborigin.h" | 42 #include "platform/weborigin/Suborigin.h" |
| 42 #include "platform/wtf/DateMath.h" | 43 #include "platform/wtf/DateMath.h" |
| 43 #include "platform/wtf/MathExtras.h" | 44 #include "platform/wtf/MathExtras.h" |
| 44 #include "platform/wtf/text/CString.h" | 45 #include "platform/wtf/text/CString.h" |
| 45 #include "platform/wtf/text/CharacterNames.h" | 46 #include "platform/wtf/text/CharacterNames.h" |
| 46 #include "platform/wtf/text/ParsingUtilities.h" | 47 #include "platform/wtf/text/ParsingUtilities.h" |
| 47 #include "platform/wtf/text/StringBuilder.h" | 48 #include "platform/wtf/text/StringBuilder.h" |
| 48 #include "platform/wtf/text/StringUTF8Adaptor.h" | 49 #include "platform/wtf/text/StringUTF8Adaptor.h" |
| 49 #include "platform/wtf/text/WTFString.h" | 50 #include "platform/wtf/text/WTFString.h" |
| 50 #include "public/platform/WebString.h" | 51 #include "public/platform/WebString.h" |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 | 858 |
| 858 bool ParseContentRangeHeaderFor206(const String& content_range, | 859 bool ParseContentRangeHeaderFor206(const String& content_range, |
| 859 int64_t* first_byte_position, | 860 int64_t* first_byte_position, |
| 860 int64_t* last_byte_position, | 861 int64_t* last_byte_position, |
| 861 int64_t* instance_length) { | 862 int64_t* instance_length) { |
| 862 return net::HttpUtil::ParseContentRangeHeaderFor206( | 863 return net::HttpUtil::ParseContentRangeHeaderFor206( |
| 863 StringUTF8Adaptor(content_range).AsStringPiece(), first_byte_position, | 864 StringUTF8Adaptor(content_range).AsStringPiece(), first_byte_position, |
| 864 last_byte_position, instance_length); | 865 last_byte_position, instance_length); |
| 865 } | 866 } |
| 866 | 867 |
| 867 template <typename CharType> | |
| 868 inline bool IsNotServerTimingHeaderDelimiter(CharType c) { | |
| 869 return c != '=' && c != ';' && c != ','; | |
| 870 } | |
| 871 | |
| 872 const LChar* ParseServerTimingToken(const LChar* begin, | |
| 873 const LChar* end, | |
| 874 String& result) { | |
| 875 const LChar* position = begin; | |
| 876 skipWhile<LChar, IsNotServerTimingHeaderDelimiter>(position, end); | |
| 877 result = String(begin, position - begin).StripWhiteSpace(); | |
| 878 return position; | |
| 879 } | |
| 880 | |
| 881 String CheckDoubleQuotedString(const String& value) { | |
| 882 if (value.length() < 2 || value[0] != '"' || | |
| 883 value[value.length() - 1] != '"') { | |
| 884 return value; | |
| 885 } | |
| 886 | |
| 887 StringBuilder out; | |
| 888 unsigned pos = 1; // Begin after the opening DQUOTE. | |
| 889 unsigned len = value.length() - 1; // End before the closing DQUOTE. | |
| 890 | |
| 891 // Skip past backslashes, but include everything else. | |
| 892 while (pos < len) { | |
| 893 if (value[pos] == '\\') | |
| 894 pos++; | |
| 895 if (pos < len) | |
| 896 out.Append(value[pos++]); | |
| 897 } | |
| 898 | |
| 899 return out.ToString(); | |
| 900 } | |
| 901 | |
| 902 std::unique_ptr<ServerTimingHeaderVector> ParseServerTimingHeader( | 868 std::unique_ptr<ServerTimingHeaderVector> ParseServerTimingHeader( |
| 903 const String& headerValue) { | 869 const String& headerValue) { |
| 904 std::unique_ptr<ServerTimingHeaderVector> headers = | 870 std::unique_ptr<ServerTimingHeaderVector> headers = |
| 905 WTF::MakeUnique<ServerTimingHeaderVector>(); | 871 WTF::MakeUnique<ServerTimingHeaderVector>(); |
| 906 | 872 |
| 907 if (!headerValue.IsNull()) { | 873 if (!headerValue.IsNull()) { |
| 908 DCHECK(headerValue.Is8Bit()); | 874 DCHECK(headerValue.Is8Bit()); |
| 909 | 875 |
| 910 const LChar* position = headerValue.Characters8(); | 876 HeaderFieldTokenizer tokenizer(headerValue); |
| 911 const LChar* end = position + headerValue.length(); | 877 while (!tokenizer.IsConsumed()) { |
| 912 while (position < end) { | 878 StringView metric; |
| 913 String metric, value, description = ""; | 879 if (!tokenizer.ConsumeToken(Mode::kNormal, metric)) { |
| 914 position = ParseServerTimingToken(position, end, metric); | 880 break; |
| 915 if (position != end && *position == '=') { | |
| 916 position = ParseServerTimingToken(position + 1, end, value); | |
| 917 } | 881 } |
| 918 if (position != end && *position == ';') { | 882 |
| 919 position = ParseServerTimingToken(position + 1, end, description); | 883 double duration = 0; |
| 884 String description; | |
| 885 if (tokenizer.Consume('=')) { | |
| 886 StringView durationOutput; | |
| 887 if (tokenizer.ConsumeToken(Mode::kNormal, durationOutput)) { | |
| 888 duration = durationOutput.ToString().ToDouble(); | |
| 889 } | |
| 920 } | 890 } |
| 921 position++; | 891 if (tokenizer.Consume(';')) { |
| 892 tokenizer.ConsumeTokenOrQuotedString(Mode::kNormal, description); | |
| 893 } | |
| 922 | 894 |
| 923 headers->push_back(WTF::MakeUnique<ServerTimingHeader>( | 895 headers->push_back(WTF::MakeUnique<ServerTimingHeader>( |
| 924 metric, value.ToDouble(), CheckDoubleQuotedString(description))); | 896 metric.ToString(), duration, description ? description : "")); |
|
Yoav Weiss
2017/06/08 20:47:46
RE `description ? description : ""` can you initia
| |
| 897 | |
| 898 if (!tokenizer.Consume(',')) { | |
| 899 break; | |
| 900 } | |
| 925 } | 901 } |
| 926 } | 902 } |
| 927 return headers; | 903 return headers; |
| 928 } | 904 } |
| 929 | 905 |
| 930 } // namespace blink | 906 } // namespace blink |
| OLD | NEW |