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

Side by Side Diff: net/filter/filter.cc

Issue 423813002: Sdch view for net-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Declare SdchProblemCode Created 6 years, 1 month 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/filter/filter.h" 5 #include "net/filter/filter.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "net/base/filename_util_unsafe.h" 9 #include "net/base/filename_util_unsafe.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
11 #include "net/base/mime_util.h" 11 #include "net/base/mime_util.h"
12 #include "net/base/sdch_net_log_params.h"
12 #include "net/filter/gzip_filter.h" 13 #include "net/filter/gzip_filter.h"
13 #include "net/filter/sdch_filter.h" 14 #include "net/filter/sdch_filter.h"
14 #include "net/url_request/url_request_context.h" 15 #include "net/url_request/url_request_context.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
18 namespace net {
19
17 namespace { 20 namespace {
18 21
19 // Filter types (using canonical lower case only): 22 // Filter types (using canonical lower case only):
20 const char kDeflate[] = "deflate"; 23 const char kDeflate[] = "deflate";
21 const char kGZip[] = "gzip"; 24 const char kGZip[] = "gzip";
22 const char kXGZip[] = "x-gzip"; 25 const char kXGZip[] = "x-gzip";
23 const char kSdch[] = "sdch"; 26 const char kSdch[] = "sdch";
24 // compress and x-compress are currently not supported. If we decide to support 27 // compress and x-compress are currently not supported. If we decide to support
25 // them, we'll need the same mime type compatibility hack we have for gzip. For 28 // them, we'll need the same mime type compatibility hack we have for gzip. For
26 // more information, see Firefox's nsHttpChannel::ProcessNormal. 29 // more information, see Firefox's nsHttpChannel::ProcessNormal.
27 30
28 // Mime types: 31 // Mime types:
29 const char kApplicationXGzip[] = "application/x-gzip"; 32 const char kApplicationXGzip[] = "application/x-gzip";
30 const char kApplicationGzip[] = "application/gzip"; 33 const char kApplicationGzip[] = "application/gzip";
31 const char kApplicationXGunzip[] = "application/x-gunzip"; 34 const char kApplicationXGunzip[] = "application/x-gunzip";
32 const char kTextHtml[] = "text/html"; 35 const char kTextHtml[] = "text/html";
33 36
34 // Buffer size allocated when de-compressing data. 37 // Buffer size allocated when de-compressing data.
35 const int kFilterBufSize = 32 * 1024; 38 const int kFilterBufSize = 32 * 1024;
36 39
40 void LogSdchProblem(const FilterContext& filter_context,
41 SdchProblemCode problem) {
42 SdchManager::SdchErrorRecovery(problem);
43 filter_context.GetNetLog().AddEvent(
44 NetLog::TYPE_SDCH_DECODING_ERROR,
45 base::Bind(&NetLogSdchResourceProblemCallback, problem));
46 }
47
37 } // namespace 48 } // namespace
38 49
39 namespace net {
40
41 FilterContext::~FilterContext() { 50 FilterContext::~FilterContext() {
42 } 51 }
43 52
44 Filter::~Filter() {} 53 Filter::~Filter() {}
45 54
46 // static 55 // static
47 Filter* Filter::Factory(const std::vector<FilterType>& filter_types, 56 Filter* Filter::Factory(const std::vector<FilterType>& filter_types,
48 const FilterContext& filter_context) { 57 const FilterContext& filter_context) {
49 if (filter_types.empty()) 58 if (filter_types.empty())
50 return NULL; 59 return NULL;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 !IsSupportedMimeType(mime_type)) 212 !IsSupportedMimeType(mime_type))
204 encoding_types->clear(); 213 encoding_types->clear();
205 } 214 }
206 } 215 }
207 216
208 // If the request was for SDCH content, then we might need additional fixups. 217 // If the request was for SDCH content, then we might need additional fixups.
209 if (!filter_context.SdchResponseExpected()) { 218 if (!filter_context.SdchResponseExpected()) {
210 // It was not an SDCH request, so we'll just record stats. 219 // It was not an SDCH request, so we'll just record stats.
211 if (1 < encoding_types->size()) { 220 if (1 < encoding_types->size()) {
212 // Multiple filters were intended to only be used for SDCH (thus far!) 221 // Multiple filters were intended to only be used for SDCH (thus far!)
213 SdchManager::SdchErrorRecovery( 222 LogSdchProblem(filter_context, SDCH_MULTIENCODING_FOR_NON_SDCH_REQUEST);
214 SdchManager::MULTIENCODING_FOR_NON_SDCH_REQUEST);
215 } 223 }
216 if ((1 == encoding_types->size()) && 224 if ((1 == encoding_types->size()) &&
217 (FILTER_TYPE_SDCH == encoding_types->front())) { 225 (FILTER_TYPE_SDCH == encoding_types->front())) {
218 SdchManager::SdchErrorRecovery( 226 LogSdchProblem(filter_context,
219 SdchManager::SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST); 227 SDCH_SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST);
220 } 228 }
221 return; 229 return;
222 } 230 }
223 231
224 // The request was tagged as an SDCH request, which means the server supplied 232 // The request was tagged as an SDCH request, which means the server supplied
225 // a dictionary, and we advertised it in the request. Some proxies will do 233 // a dictionary, and we advertised it in the request. Some proxies will do
226 // very strange things to the request, or the response, so we have to handle 234 // very strange things to the request, or the response, so we have to handle
227 // them gracefully. 235 // them gracefully.
228 236
229 // If content encoding included SDCH, then everything is "relatively" fine. 237 // If content encoding included SDCH, then everything is "relatively" fine.
230 if (!encoding_types->empty() && 238 if (!encoding_types->empty() &&
231 (FILTER_TYPE_SDCH == encoding_types->front())) { 239 (FILTER_TYPE_SDCH == encoding_types->front())) {
232 // Some proxies (found currently in Argentina) strip the Content-Encoding 240 // Some proxies (found currently in Argentina) strip the Content-Encoding
233 // text from "sdch,gzip" to a mere "sdch" without modifying the compressed 241 // text from "sdch,gzip" to a mere "sdch" without modifying the compressed
234 // payload. To handle this gracefully, we simulate the "probably" deleted 242 // payload. To handle this gracefully, we simulate the "probably" deleted
235 // ",gzip" by appending a tentative gzip decode, which will default to a 243 // ",gzip" by appending a tentative gzip decode, which will default to a
236 // no-op pass through filter if it doesn't get gzip headers where expected. 244 // no-op pass through filter if it doesn't get gzip headers where expected.
237 if (1 == encoding_types->size()) { 245 if (1 == encoding_types->size()) {
238 encoding_types->push_back(FILTER_TYPE_GZIP_HELPING_SDCH); 246 encoding_types->push_back(FILTER_TYPE_GZIP_HELPING_SDCH);
239 SdchManager::SdchErrorRecovery( 247 LogSdchProblem(filter_context, SDCH_OPTIONAL_GUNZIP_ENCODING_ADDED);
240 SdchManager::OPTIONAL_GUNZIP_ENCODING_ADDED);
241 } 248 }
242 return; 249 return;
243 } 250 }
244 251
245 // There are now several cases to handle for an SDCH request. Foremost, if 252 // There are now several cases to handle for an SDCH request. Foremost, if
246 // the outbound request was stripped so as not to advertise support for 253 // the outbound request was stripped so as not to advertise support for
247 // encodings, we might get back content with no encoding, or (for example) 254 // encodings, we might get back content with no encoding, or (for example)
248 // just gzip. We have to be sure that any changes we make allow for such 255 // just gzip. We have to be sure that any changes we make allow for such
249 // minimal coding to work. That issue is why we use TENTATIVE filters if we 256 // minimal coding to work. That issue is why we use TENTATIVE filters if we
250 // add any, as those filters sniff the content, and act as pass-through 257 // add any, as those filters sniff the content, and act as pass-through
(...skipping 13 matching lines...) Expand all
264 // The one unresolved failure mode comes when we advertise a dictionary, and 271 // The one unresolved failure mode comes when we advertise a dictionary, and
265 // the server tries to *send* a gzipped file (not gzip encode content), and 272 // the server tries to *send* a gzipped file (not gzip encode content), and
266 // then we could do a gzip decode :-(. Since SDCH is only (currently) 273 // then we could do a gzip decode :-(. Since SDCH is only (currently)
267 // supported server side on paths that only send HTML content, this mode has 274 // supported server side on paths that only send HTML content, this mode has
268 // never surfaced in the wild (and is unlikely to). 275 // never surfaced in the wild (and is unlikely to).
269 // We will gather a lot of stats as we perform the fixups 276 // We will gather a lot of stats as we perform the fixups
270 if (StartsWithASCII(mime_type, kTextHtml, false)) { 277 if (StartsWithASCII(mime_type, kTextHtml, false)) {
271 // Suspicious case: Advertised dictionary, but server didn't use sdch, and 278 // Suspicious case: Advertised dictionary, but server didn't use sdch, and
272 // we're HTML tagged. 279 // we're HTML tagged.
273 if (encoding_types->empty()) { 280 if (encoding_types->empty()) {
274 SdchManager::SdchErrorRecovery( 281 LogSdchProblem(filter_context, SDCH_ADDED_CONTENT_ENCODING);
275 SdchManager::ADDED_CONTENT_ENCODING);
276 } else if (1 == encoding_types->size()) { 282 } else if (1 == encoding_types->size()) {
277 SdchManager::SdchErrorRecovery( 283 LogSdchProblem(filter_context, SDCH_FIXED_CONTENT_ENCODING);
278 SdchManager::FIXED_CONTENT_ENCODING);
279 } else { 284 } else {
280 SdchManager::SdchErrorRecovery( 285 LogSdchProblem(filter_context, SDCH_FIXED_CONTENT_ENCODINGS);
281 SdchManager::FIXED_CONTENT_ENCODINGS);
282 } 286 }
283 } else { 287 } else {
284 // Remarkable case!?! We advertised an SDCH dictionary, content-encoding 288 // Remarkable case!?! We advertised an SDCH dictionary, content-encoding
285 // was not marked for SDCH processing: Why did the server suggest an SDCH 289 // was not marked for SDCH processing: Why did the server suggest an SDCH
286 // dictionary in the first place??. Also, the content isn't 290 // dictionary in the first place??. Also, the content isn't
287 // tagged as HTML, despite the fact that SDCH encoding is mostly likely for 291 // tagged as HTML, despite the fact that SDCH encoding is mostly likely for
288 // HTML: Did some anti-virus system strip this tag (sometimes they strip 292 // HTML: Did some anti-virus system strip this tag (sometimes they strip
289 // accept-encoding headers on the request)?? Does the content encoding not 293 // accept-encoding headers on the request)?? Does the content encoding not
290 // start with "text/html" for some other reason?? We'll report this as a 294 // start with "text/html" for some other reason?? We'll report this as a
291 // fixup to a binary file, but it probably really is text/html (some how). 295 // fixup to a binary file, but it probably really is text/html (some how).
292 if (encoding_types->empty()) { 296 if (encoding_types->empty()) {
293 SdchManager::SdchErrorRecovery( 297 LogSdchProblem(filter_context, SDCH_BINARY_ADDED_CONTENT_ENCODING);
294 SdchManager::BINARY_ADDED_CONTENT_ENCODING);
295 } else if (1 == encoding_types->size()) { 298 } else if (1 == encoding_types->size()) {
296 SdchManager::SdchErrorRecovery( 299 LogSdchProblem(filter_context, SDCH_BINARY_FIXED_CONTENT_ENCODING);
297 SdchManager::BINARY_FIXED_CONTENT_ENCODING);
298 } else { 300 } else {
299 SdchManager::SdchErrorRecovery( 301 LogSdchProblem(filter_context, SDCH_BINARY_FIXED_CONTENT_ENCODINGS);
300 SdchManager::BINARY_FIXED_CONTENT_ENCODINGS);
301 } 302 }
302 } 303 }
303 304
304 // Leave the existing encoding type to be processed first, and add our 305 // Leave the existing encoding type to be processed first, and add our
305 // tentative decodings to be done afterwards. Vodaphone UK reportedyl will 306 // tentative decodings to be done afterwards. Vodaphone UK reportedyl will
306 // perform a second layer of gzip encoding atop the server's sdch,gzip 307 // perform a second layer of gzip encoding atop the server's sdch,gzip
307 // encoding, and then claim that the content encoding is a mere gzip. As a 308 // encoding, and then claim that the content encoding is a mere gzip. As a
308 // result we'll need (in that case) to do the gunzip, plus our tentative 309 // result we'll need (in that case) to do the gunzip, plus our tentative
309 // gunzip and tentative SDCH decoding. 310 // gunzip and tentative SDCH decoding.
310 // This approach nicely handles the empty() list as well, and should work with 311 // This approach nicely handles the empty() list as well, and should work with
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 401
401 void Filter::PushDataIntoNextFilter() { 402 void Filter::PushDataIntoNextFilter() {
402 IOBuffer* next_buffer = next_filter_->stream_buffer(); 403 IOBuffer* next_buffer = next_filter_->stream_buffer();
403 int next_size = next_filter_->stream_buffer_size(); 404 int next_size = next_filter_->stream_buffer_size();
404 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); 405 last_status_ = ReadFilteredData(next_buffer->data(), &next_size);
405 if (FILTER_ERROR != last_status_) 406 if (FILTER_ERROR != last_status_)
406 next_filter_->FlushStreamBuffer(next_size); 407 next_filter_->FlushStreamBuffer(next_size);
407 } 408 }
408 409
409 } // namespace net 410 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698