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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 869 |
870 bool ParseContentRangeHeaderFor206(const String& content_range, | 870 bool ParseContentRangeHeaderFor206(const String& content_range, |
871 int64_t* first_byte_position, | 871 int64_t* first_byte_position, |
872 int64_t* last_byte_position, | 872 int64_t* last_byte_position, |
873 int64_t* instance_length) { | 873 int64_t* instance_length) { |
874 return net::HttpUtil::ParseContentRangeHeaderFor206( | 874 return net::HttpUtil::ParseContentRangeHeaderFor206( |
875 StringUTF8Adaptor(content_range).AsStringPiece(), first_byte_position, | 875 StringUTF8Adaptor(content_range).AsStringPiece(), first_byte_position, |
876 last_byte_position, instance_length); | 876 last_byte_position, instance_length); |
877 } | 877 } |
878 | 878 |
| 879 template <typename CharType> |
| 880 inline bool IsNotServerTimingHeaderDelimiter(CharType c) { |
| 881 return c != '=' && c != ';' && c != ','; |
| 882 } |
| 883 |
| 884 const LChar* ParseServerTimingToken(const LChar* begin, |
| 885 const LChar* end, |
| 886 String& result) { |
| 887 const LChar* position = begin; |
| 888 skipWhile<LChar, IsNotServerTimingHeaderDelimiter>(position, end); |
| 889 result = String(begin, position - begin).StripWhiteSpace(); |
| 890 return position; |
| 891 } |
| 892 |
| 893 String CheckDoubleQuotedString(const String& value) { |
| 894 if (value.length() < 2 || value[0] != '"' || |
| 895 value[value.length() - 1] != '"') { |
| 896 return value; |
| 897 } |
| 898 |
| 899 StringBuilder out; |
| 900 unsigned pos = 1; // Begin after the opening DQUOTE. |
| 901 unsigned len = value.length() - 1; // End before the closing DQUOTE. |
| 902 |
| 903 // Skip past backslashes, but include everything else. |
| 904 while (pos < len) { |
| 905 if (value[pos] == '\\') |
| 906 pos++; |
| 907 if (pos < len) |
| 908 out.Append(value[pos++]); |
| 909 } |
| 910 |
| 911 return out.ToString(); |
| 912 } |
| 913 |
| 914 std::unique_ptr<ServerTimingHeaderVector> ParseServerTimingHeader( |
| 915 const String& headerValue) { |
| 916 std::unique_ptr<ServerTimingHeaderVector> headers = |
| 917 WTF::MakeUnique<ServerTimingHeaderVector>(); |
| 918 |
| 919 if (!headerValue.IsNull()) { |
| 920 DCHECK(headerValue.Is8Bit()); |
| 921 |
| 922 const LChar* position = headerValue.Characters8(); |
| 923 const LChar* end = position + headerValue.length(); |
| 924 while (position < end) { |
| 925 String metric, value, description = ""; |
| 926 position = ParseServerTimingToken(position, end, metric); |
| 927 if (*position == '=') { |
| 928 position = ParseServerTimingToken(position + 1, end, value); |
| 929 } |
| 930 if (*position == ';') { |
| 931 position = ParseServerTimingToken(position + 1, end, description); |
| 932 } |
| 933 position++; |
| 934 |
| 935 headers->push_back(WTF::MakeUnique<ServerTimingHeader>( |
| 936 metric, value.ToDouble(), CheckDoubleQuotedString(description))); |
| 937 } |
| 938 } |
| 939 return headers; |
| 940 } |
| 941 |
879 } // namespace blink | 942 } // namespace blink |
OLD | NEW |