OLD | NEW |
---|---|
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 | |
Randy Smith (Not in Mondays)
2014/09/18 20:55:51
I don't particularly care, but was there a reason
baranovich
2014/09/19 12:42:44
I wanted to avoid writing net:: prefixes in LogSdc
| |
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 SdchManager::ProblemCodes problem) { | |
42 SdchManager::SdchErrorRecovery(problem); | |
43 filter_context.GetNetLog().AddEvent( | |
44 NetLog::TYPE_SDCH_RESOURCE_ERROR, | |
45 base::Bind(&NetLogSdchResourceProblemCallback, problem, true)); | |
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 Loading... | |
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, |
214 SdchManager::MULTIENCODING_FOR_NON_SDCH_REQUEST); | 223 SdchManager::MULTIENCODING_FOR_NON_SDCH_REQUEST); |
215 } | 224 } |
216 if ((1 == encoding_types->size()) && | 225 if ((1 == encoding_types->size()) && |
217 (FILTER_TYPE_SDCH == encoding_types->front())) { | 226 (FILTER_TYPE_SDCH == encoding_types->front())) { |
218 SdchManager::SdchErrorRecovery( | 227 LogSdchProblem(filter_context, |
219 SdchManager::SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST); | 228 SdchManager::SDCH_CONTENT_ENCODE_FOR_NON_SDCH_REQUEST); |
220 } | 229 } |
221 return; | 230 return; |
222 } | 231 } |
223 | 232 |
224 // The request was tagged as an SDCH request, which means the server supplied | 233 // 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 | 234 // 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 | 235 // very strange things to the request, or the response, so we have to handle |
227 // them gracefully. | 236 // them gracefully. |
228 | 237 |
229 // If content encoding included SDCH, then everything is "relatively" fine. | 238 // If content encoding included SDCH, then everything is "relatively" fine. |
230 if (!encoding_types->empty() && | 239 if (!encoding_types->empty() && |
231 (FILTER_TYPE_SDCH == encoding_types->front())) { | 240 (FILTER_TYPE_SDCH == encoding_types->front())) { |
232 // Some proxies (found currently in Argentina) strip the Content-Encoding | 241 // Some proxies (found currently in Argentina) strip the Content-Encoding |
233 // text from "sdch,gzip" to a mere "sdch" without modifying the compressed | 242 // text from "sdch,gzip" to a mere "sdch" without modifying the compressed |
234 // payload. To handle this gracefully, we simulate the "probably" deleted | 243 // payload. To handle this gracefully, we simulate the "probably" deleted |
235 // ",gzip" by appending a tentative gzip decode, which will default to a | 244 // ",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. | 245 // no-op pass through filter if it doesn't get gzip headers where expected. |
237 if (1 == encoding_types->size()) { | 246 if (1 == encoding_types->size()) { |
238 encoding_types->push_back(FILTER_TYPE_GZIP_HELPING_SDCH); | 247 encoding_types->push_back(FILTER_TYPE_GZIP_HELPING_SDCH); |
239 SdchManager::SdchErrorRecovery( | 248 LogSdchProblem(filter_context, |
240 SdchManager::OPTIONAL_GUNZIP_ENCODING_ADDED); | 249 SdchManager::OPTIONAL_GUNZIP_ENCODING_ADDED); |
241 } | 250 } |
242 return; | 251 return; |
243 } | 252 } |
244 | 253 |
245 // There are now several cases to handle for an SDCH request. Foremost, if | 254 // 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 | 255 // 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) | 256 // 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 | 257 // 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 | 258 // 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 | 259 // add any, as those filters sniff the content, and act as pass-through |
(...skipping 13 matching lines...) Expand all Loading... | |
264 // The one unresolved failure mode comes when we advertise a dictionary, and | 273 // 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 | 274 // 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) | 275 // 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 | 276 // supported server side on paths that only send HTML content, this mode has |
268 // never surfaced in the wild (and is unlikely to). | 277 // never surfaced in the wild (and is unlikely to). |
269 // We will gather a lot of stats as we perform the fixups | 278 // We will gather a lot of stats as we perform the fixups |
270 if (StartsWithASCII(mime_type, kTextHtml, false)) { | 279 if (StartsWithASCII(mime_type, kTextHtml, false)) { |
271 // Suspicious case: Advertised dictionary, but server didn't use sdch, and | 280 // Suspicious case: Advertised dictionary, but server didn't use sdch, and |
272 // we're HTML tagged. | 281 // we're HTML tagged. |
273 if (encoding_types->empty()) { | 282 if (encoding_types->empty()) { |
274 SdchManager::SdchErrorRecovery( | 283 LogSdchProblem(filter_context, SdchManager::ADDED_CONTENT_ENCODING); |
275 SdchManager::ADDED_CONTENT_ENCODING); | |
276 } else if (1 == encoding_types->size()) { | 284 } else if (1 == encoding_types->size()) { |
277 SdchManager::SdchErrorRecovery( | 285 LogSdchProblem(filter_context, SdchManager::FIXED_CONTENT_ENCODING); |
278 SdchManager::FIXED_CONTENT_ENCODING); | |
279 } else { | 286 } else { |
280 SdchManager::SdchErrorRecovery( | 287 LogSdchProblem(filter_context, SdchManager::FIXED_CONTENT_ENCODINGS); |
281 SdchManager::FIXED_CONTENT_ENCODINGS); | |
282 } | 288 } |
283 } else { | 289 } else { |
284 // Remarkable case!?! We advertised an SDCH dictionary, content-encoding | 290 // Remarkable case!?! We advertised an SDCH dictionary, content-encoding |
285 // was not marked for SDCH processing: Why did the server suggest an SDCH | 291 // was not marked for SDCH processing: Why did the server suggest an SDCH |
286 // dictionary in the first place??. Also, the content isn't | 292 // dictionary in the first place??. Also, the content isn't |
287 // tagged as HTML, despite the fact that SDCH encoding is mostly likely for | 293 // 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 | 294 // HTML: Did some anti-virus system strip this tag (sometimes they strip |
289 // accept-encoding headers on the request)?? Does the content encoding not | 295 // 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 | 296 // 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). | 297 // fixup to a binary file, but it probably really is text/html (some how). |
292 if (encoding_types->empty()) { | 298 if (encoding_types->empty()) { |
293 SdchManager::SdchErrorRecovery( | 299 LogSdchProblem(filter_context, |
294 SdchManager::BINARY_ADDED_CONTENT_ENCODING); | 300 SdchManager::BINARY_ADDED_CONTENT_ENCODING); |
295 } else if (1 == encoding_types->size()) { | 301 } else if (1 == encoding_types->size()) { |
296 SdchManager::SdchErrorRecovery( | 302 LogSdchProblem(filter_context, |
297 SdchManager::BINARY_FIXED_CONTENT_ENCODING); | 303 SdchManager::BINARY_FIXED_CONTENT_ENCODING); |
298 } else { | 304 } else { |
299 SdchManager::SdchErrorRecovery( | 305 LogSdchProblem(filter_context, |
300 SdchManager::BINARY_FIXED_CONTENT_ENCODINGS); | 306 SdchManager::BINARY_FIXED_CONTENT_ENCODINGS); |
301 } | 307 } |
302 } | 308 } |
303 | 309 |
304 // Leave the existing encoding type to be processed first, and add our | 310 // Leave the existing encoding type to be processed first, and add our |
305 // tentative decodings to be done afterwards. Vodaphone UK reportedyl will | 311 // tentative decodings to be done afterwards. Vodaphone UK reportedyl will |
306 // perform a second layer of gzip encoding atop the server's sdch,gzip | 312 // 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 | 313 // 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 | 314 // result we'll need (in that case) to do the gunzip, plus our tentative |
309 // gunzip and tentative SDCH decoding. | 315 // gunzip and tentative SDCH decoding. |
310 // This approach nicely handles the empty() list as well, and should work with | 316 // 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 Loading... | |
400 | 406 |
401 void Filter::PushDataIntoNextFilter() { | 407 void Filter::PushDataIntoNextFilter() { |
402 IOBuffer* next_buffer = next_filter_->stream_buffer(); | 408 IOBuffer* next_buffer = next_filter_->stream_buffer(); |
403 int next_size = next_filter_->stream_buffer_size(); | 409 int next_size = next_filter_->stream_buffer_size(); |
404 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); | 410 last_status_ = ReadFilteredData(next_buffer->data(), &next_size); |
405 if (FILTER_ERROR != last_status_) | 411 if (FILTER_ERROR != last_status_) |
406 next_filter_->FlushStreamBuffer(next_size); | 412 next_filter_->FlushStreamBuffer(next_size); |
407 } | 413 } |
408 | 414 |
409 } // namespace net | 415 } // namespace net |
OLD | NEW |