OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/spdy/spdy_header_indexing.h" | |
6 | |
7 #include "net/spdy/spdy_bug_tracker.h" | |
8 | |
9 namespace net { | |
10 | |
11 int32_t FLAGS_gfe_spdy_indexing_set_bound = 50; | |
12 int32_t FLAGS_gfe_spdy_tracking_set_bound = 1000; | |
13 | |
14 HeaderIndexing::HeaderIndexing() | |
15 : indexing_set_bound_(FLAGS_gfe_spdy_indexing_set_bound), | |
16 tracking_set_bound_(FLAGS_gfe_spdy_tracking_set_bound) { | |
17 SPDY_BUG_IF(indexing_set_bound_ >= tracking_set_bound_) | |
18 << "Tracking set should be larger than indexing set"; | |
19 } | |
20 | |
21 HeaderIndexing::~HeaderIndexing() {} | |
22 | |
23 void HeaderIndexing::CreateInitIndexingHeaders() { | |
24 const SpdyString initial_fields[] = { | |
25 // Estimated top 100 fields. | |
26 "alt-svc", | |
27 "date", | |
28 "cache-control", | |
29 "content-type", | |
30 "expires", | |
31 "location", | |
32 "x-xss-protection", | |
33 "p3p", | |
34 "set-cookie", | |
35 "alternate-protocol", | |
36 "last-modified", | |
37 "server", | |
38 "x-snapchat-request-id", | |
39 "content-disposition", | |
40 "strict-transport-security", | |
41 "x-content-type-options", | |
42 "content-security-policy", | |
43 "x-frame-options", | |
44 "x-snapchat-notice", | |
45 "pragma", | |
46 ":status", | |
47 "content-length", | |
48 "etag", | |
49 "x-cloud-trace-context", | |
50 "vary", | |
51 "access-control-expose-headers", | |
52 "content-encoding", | |
53 "access-control-allow-origin", | |
54 "age", | |
55 ":protocol", | |
56 "via", | |
57 "x-robots-tag", | |
58 "link", | |
59 "access-control-allow-headers", | |
60 "x-google-session-info", | |
61 "x-google-backends", | |
62 "x-google-gfe-request-trace", | |
63 "warning", | |
64 "x-guploader-uploadid", | |
65 "x-cup-server-proof", | |
66 "timing-allow-origin", | |
67 "x-google-trace", | |
68 "access-control-allow-credentials", | |
69 "google-delayed-impression", | |
70 "google-creative-id", | |
71 "access-control-allow-methods", | |
72 "x-ua-compatible", | |
73 "x-google-gfe-response-code-details-trace", | |
74 "google-lineitem-id", | |
75 "version", | |
76 "x-google-dos-service-trace", | |
77 "x-google-service", | |
78 "x-google-gfe-service-trace", | |
79 "sane-time-millis", | |
80 "x-google-netmon-label", | |
81 "x-google-apiary-auth-scopes", | |
82 "x-seed-signature", | |
83 "content-security-policy-report-only", | |
84 "x-auto-login", | |
85 "x-original-content-length", | |
86 "accept-ranges", | |
87 "x-goog-hash", | |
88 "x-google-gfe-response-body-transformations", | |
89 "cf-ray", | |
90 "x-content-security-policy-report-only", | |
91 "x-google-shellfish-status", | |
92 "x-amz-id-2", | |
93 "get-dictionary", | |
94 "grpc-message", | |
95 "x-hw", | |
96 "x-google-gfe-backend-request-info", | |
97 "x-goog-upload-header-x-google-session-info", | |
98 "x-amz-cf-id", | |
99 "x-powered-by", | |
100 "www-authenticate", | |
101 "access-control-max-age", | |
102 "x-spf-response-type", | |
103 "x-goog-meta-encoded_request", | |
104 "x-goog-generation", | |
105 "x-google-gslb-service", | |
106 "x-google-servertype", | |
107 "x-cache", | |
108 "x-chromium-appcache-fallback-override", | |
109 "x-goog-upload-url", | |
110 "x-goog-upload-control-url", | |
111 "content-range", | |
112 "x-seen-by", | |
113 "x-google-apps-framework-action", | |
114 "content-location", | |
115 "x-daystart", | |
116 "x-varnish", | |
117 "fastly-debug-digest", | |
118 "x-daynum", | |
119 "x-goog-stored-content-encoding", | |
120 "x-goog-storage-class", | |
121 "x-google-cookies-blocked", | |
122 "x-range-md5", | |
123 "x-served-by", | |
124 "x-client-wire-protocol", | |
125 "content-language", | |
126 }; | |
127 | |
128 indexing_set_.clear(); | |
129 indexing_set_ = | |
130 HeaderSet(initial_fields, initial_fields + arraysize(initial_fields)); | |
131 tracking_set_ = | |
132 HeaderSet(initial_fields, initial_fields + arraysize(initial_fields)); | |
133 } | |
134 | |
135 bool HeaderIndexing::ShouldIndex(SpdyStringPiece header, | |
136 SpdyStringPiece /* value */) { | |
137 total_header_count_++; | |
138 if (header.empty()) { | |
139 return false; | |
140 } | |
141 // header is in indexing set. | |
142 SpdyString header_str(header.data(), header.size()); | |
143 if (indexing_set_.find(header_str) != indexing_set_.end()) { | |
144 return true; | |
145 } | |
146 // header not in indexing set. Check tracking set. | |
147 if (tracking_set_.find(header_str) != tracking_set_.end()) { | |
148 // Seen this header before. Add it to indexing set. | |
149 TryInsertHeader(std::move(header_str), &indexing_set_, indexing_set_bound_); | |
150 missed_header_in_tracking_++; | |
151 } else { | |
152 // Add header to tracking set. | |
153 TryInsertHeader(std::move(header_str), &tracking_set_, tracking_set_bound_); | |
154 missed_header_in_indexing_++; | |
155 } | |
156 return false; | |
157 } | |
158 | |
159 void HeaderIndexing::TryInsertHeader(SpdyString&& header, | |
160 HeaderSet* set, | |
161 size_t bound) { | |
162 std::pair<HeaderSet::iterator, bool> result = set->insert(std::move(header)); | |
163 if (set->size() > bound) { | |
164 // Reach the size limit. Remove the header next to the newly added header. | |
165 // If the new header is at the end, look for the "next" element at the | |
166 // beginning. | |
167 HeaderSet::iterator it = std::next(result.first); | |
168 if (it != set->end()) { | |
169 set->erase(it); | |
170 } else { | |
171 set->erase(set->begin()); | |
172 } | |
173 } | |
174 } | |
175 | |
176 } // namespace net | |
OLD | NEW |