1/*
2 * Copyright (C) 2017 Akamai Technologies Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "ServerTimingParser.h"
28
29#include "HeaderFieldTokenizer.h"
30#include "RuntimeEnabledFeatures.h"
31#include "ServerTiming.h"
32
33#include <wtf/text/CString.h>
34
35namespace WebCore {
36
37namespace ServerTimingParser {
38
39Vector<ServerTiming> parseServerTiming(const String& headerValue)
40{
41 ASSERT(RuntimeEnabledFeatures::sharedFeatures().serverTimingEnabled());
42 auto entries = Vector<ServerTiming>();
43 if (headerValue.isNull())
44 return entries;
45
46 ASSERT(headerValue.is8Bit());
47
48 HeaderFieldTokenizer tokenizer(headerValue);
49 while (!tokenizer.isConsumed()) {
50 String name = tokenizer.consumeToken();
51 if (name.isNull())
52 break;
53
54 ServerTiming entry(WTFMove(name));
55
56 while (tokenizer.consume(';')) {
57 String parameterName = tokenizer.consumeToken();
58 if (parameterName.isNull())
59 break;
60
61 String value = "";
62 if (tokenizer.consume('=')) {
63 value = tokenizer.consumeTokenOrQuotedString();
64 tokenizer.consumeBeforeAnyCharMatch({',', ';'});
65 }
66 entry.setParameter(parameterName, value);
67 }
68
69 entries.append(WTFMove(entry));
70
71 if (!tokenizer.consume(','))
72 break;
73 }
74 return entries;
75}
76
77} // namespace ServerTimingParser
78
79} // namespace WebCore
80