| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/base/filter.h" | 5 #include "net/base/filter.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" |
| 7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 8 #include "net/base/gzip_filter.h" | 9 #include "net/base/gzip_filter.h" |
| 9 #include "net/base/bzip2_filter.h" | 10 #include "net/base/bzip2_filter.h" |
| 10 #include "net/base/sdch_filter.h" | 11 #include "net/base/sdch_filter.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 // Filter types (using canonical lower case only): | 15 // Filter types (using canonical lower case only): |
| 15 const char kDeflate[] = "deflate"; | 16 const char kDeflate[] = "deflate"; |
| 16 const char kGZip[] = "gzip"; | 17 const char kGZip[] = "gzip"; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if ((1 == encoding_types->size()) && | 87 if ((1 == encoding_types->size()) && |
| 87 (FILTER_TYPE_GZIP == encoding_types->front())) { | 88 (FILTER_TYPE_GZIP == encoding_types->front())) { |
| 88 if (LowerCaseEqualsASCII(mime_type, kApplicationXGzip) || | 89 if (LowerCaseEqualsASCII(mime_type, kApplicationXGzip) || |
| 89 LowerCaseEqualsASCII(mime_type, kApplicationGzip) || | 90 LowerCaseEqualsASCII(mime_type, kApplicationGzip) || |
| 90 LowerCaseEqualsASCII(mime_type, kApplicationXGunzip)) | 91 LowerCaseEqualsASCII(mime_type, kApplicationXGunzip)) |
| 91 // The server has told us that it sent us gziped content with a gzip | 92 // The server has told us that it sent us gziped content with a gzip |
| 92 // content encoding. Sadly, Apache mistakenly sets these headers for all | 93 // content encoding. Sadly, Apache mistakenly sets these headers for all |
| 93 // .gz files. We match Firefox's nsHttpChannel::ProcessNormal and ignore | 94 // .gz files. We match Firefox's nsHttpChannel::ProcessNormal and ignore |
| 94 // the Content-Encoding here. | 95 // the Content-Encoding here. |
| 95 encoding_types->clear(); | 96 encoding_types->clear(); |
| 97 |
| 98 GURL url; |
| 99 success = filter_context.GetURL(&url); |
| 100 DCHECK(success); |
| 101 FilePath filename = FilePath().AppendASCII(url.ExtractFileName()); |
| 102 FilePath::StringType extension = filename.Extension(); |
| 103 |
| 104 // Firefox does not apply the filter to the following extensions. |
| 105 // See Firefox's nsHttpChannel::nsContentEncodings::GetNext() and |
| 106 // nonDecodableExtensions in nsExternalHelperAppService.cpp |
| 107 if (0 == extension.compare(FILE_PATH_LITERAL(".gz")) || |
| 108 0 == extension.compare(FILE_PATH_LITERAL(".tgz")) || |
| 109 0 == extension.compare(FILE_PATH_LITERAL(".svgz"))) { |
| 110 encoding_types->clear(); |
| 111 } |
| 96 } | 112 } |
| 97 | 113 |
| 98 if (!filter_context.IsSdchResponse()) { | 114 if (!filter_context.IsSdchResponse()) { |
| 99 if (1 < encoding_types->size()) { | 115 if (1 < encoding_types->size()) { |
| 100 // Multiple filters were intended to only be used for SDCH (thus far!) | 116 // Multiple filters were intended to only be used for SDCH (thus far!) |
| 101 SdchManager::SdchErrorRecovery( | 117 SdchManager::SdchErrorRecovery( |
| 102 SdchManager::MULTIENCODING_FOR_NON_SDCH_REQUEST); | 118 SdchManager::MULTIENCODING_FOR_NON_SDCH_REQUEST); |
| 103 } | 119 } |
| 104 if ((1 == encoding_types->size()) && | 120 if ((1 == encoding_types->size()) && |
| 105 (FILTER_TYPE_SDCH == encoding_types->front())) { | 121 (FILTER_TYPE_SDCH == encoding_types->front())) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 354 |
| 339 DCHECK(stream_buffer()); | 355 DCHECK(stream_buffer()); |
| 340 // Bail out if there is more data in the stream buffer to be filtered. | 356 // Bail out if there is more data in the stream buffer to be filtered. |
| 341 if (!stream_buffer() || stream_data_len_) | 357 if (!stream_buffer() || stream_data_len_) |
| 342 return false; | 358 return false; |
| 343 | 359 |
| 344 next_stream_data_ = stream_buffer()->data(); | 360 next_stream_data_ = stream_buffer()->data(); |
| 345 stream_data_len_ = stream_data_len; | 361 stream_data_len_ = stream_data_len; |
| 346 return true; | 362 return true; |
| 347 } | 363 } |
| OLD | NEW |