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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
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 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 842
843 bool ParseContentRangeHeaderFor206(const String& content_range, 843 bool ParseContentRangeHeaderFor206(const String& content_range,
844 int64_t* first_byte_position, 844 int64_t* first_byte_position,
845 int64_t* last_byte_position, 845 int64_t* last_byte_position,
846 int64_t* instance_length) { 846 int64_t* instance_length) {
847 return net::HttpUtil::ParseContentRangeHeaderFor206( 847 return net::HttpUtil::ParseContentRangeHeaderFor206(
848 StringUTF8Adaptor(content_range).AsStringPiece(), first_byte_position, 848 StringUTF8Adaptor(content_range).AsStringPiece(), first_byte_position,
849 last_byte_position, instance_length); 849 last_byte_position, instance_length);
850 } 850 }
851 851
852 template <typename CharType>
853 inline bool IsNotServerTimingHeaderDelimiter(CharType c) {
854 return c != '=' && c != ';' && c != ',';
855 }
856
857 const LChar* ParseServerTimingToken(const LChar* begin,
858 const LChar* end,
859 String& result) {
860 const LChar* position = begin;
861 skipWhile<LChar, IsNotServerTimingHeaderDelimiter>(position, end);
862 result = String(begin, position - begin).StripWhiteSpace();
863 return position;
864 }
865
866 String CheckDoubleQuotedString(const String& value) {
867 if (value.length() < 2 || value[0] != '"' ||
868 value[value.length() - 1] != '"') {
869 return value;
870 }
871
872 StringBuilder out;
873 unsigned pos = 1; // Begin after the opening DQUOTE.
874 unsigned len = value.length() - 1; // End before the closing DQUOTE.
875
876 // Skip past backslashes, but include everything else.
877 while (pos < len) {
878 if (value[pos] == '\\')
879 pos++;
880 if (pos < len)
881 out.Append(value[pos++]);
882 }
883
884 return out.ToString();
885 }
886
887 std::unique_ptr<ServerTimingHeaderVector> ParseServerTimingHeader(
888 const String& headerValue) {
889 std::unique_ptr<ServerTimingHeaderVector> headers =
890 WTF::MakeUnique<ServerTimingHeaderVector>();
891
892 if (!headerValue.IsNull()) {
893 DCHECK(headerValue.Is8Bit());
894
895 const LChar* position = headerValue.Characters8();
896 const LChar* end = position + headerValue.length();
897 while (position < end) {
898 String metric, value, description = "";
899 position = ParseServerTimingToken(position, end, metric);
900 if (position != end && *position == '=') {
901 position = ParseServerTimingToken(position + 1, end, value);
902 }
903 if (position != end && *position == ';') {
904 position = ParseServerTimingToken(position + 1, end, description);
905 }
906 position++;
907
908 headers->push_back(WTF::MakeUnique<ServerTimingHeader>(
909 metric, value.ToDouble(), CheckDoubleQuotedString(description)));
910 }
911 }
912 return headers;
913 }
914
852 } // namespace blink 915 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698