| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 virtual bool GetMimeType(std::string* mime_type) const; | 99 virtual bool GetMimeType(std::string* mime_type) const; |
| 100 virtual bool GetURL(GURL* gurl) const; | 100 virtual bool GetURL(GURL* gurl) const; |
| 101 virtual base::Time GetRequestTime() const; | 101 virtual base::Time GetRequestTime() const; |
| 102 virtual bool IsCachedContent() const; | 102 virtual bool IsCachedContent() const; |
| 103 virtual bool IsDownload() const; | 103 virtual bool IsDownload() const; |
| 104 virtual bool IsSdchResponse() const; | 104 virtual bool IsSdchResponse() const; |
| 105 virtual int64 GetByteReadCount() const; | 105 virtual int64 GetByteReadCount() const; |
| 106 virtual int GetResponseCode() const; | 106 virtual int GetResponseCode() const; |
| 107 virtual void RecordPacketStats(StatisticSelector statistic) const; | 107 virtual void RecordPacketStats(StatisticSelector statistic) const; |
| 108 | 108 |
| 109 // Method to allow us to reset filter context for a response that should have |
| 110 // been SDCH encoded when there is an update due to an explicit HTTP header. |
| 111 void ResetSdchResponseToFalse(); |
| 112 |
| 109 private: | 113 private: |
| 110 URLRequestHttpJob* job_; | 114 URLRequestHttpJob* job_; |
| 111 | 115 |
| 112 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); | 116 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); |
| 113 }; | 117 }; |
| 114 | 118 |
| 115 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) | 119 URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) |
| 116 : job_(job) { | 120 : job_(job) { |
| 117 DCHECK(job_); | 121 DCHECK(job_); |
| 118 } | 122 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 137 } | 141 } |
| 138 | 142 |
| 139 bool URLRequestHttpJob::HttpFilterContext::IsCachedContent() const { | 143 bool URLRequestHttpJob::HttpFilterContext::IsCachedContent() const { |
| 140 return job_->is_cached_content_; | 144 return job_->is_cached_content_; |
| 141 } | 145 } |
| 142 | 146 |
| 143 bool URLRequestHttpJob::HttpFilterContext::IsDownload() const { | 147 bool URLRequestHttpJob::HttpFilterContext::IsDownload() const { |
| 144 return (job_->request_info_.load_flags & LOAD_IS_DOWNLOAD) != 0; | 148 return (job_->request_info_.load_flags & LOAD_IS_DOWNLOAD) != 0; |
| 145 } | 149 } |
| 146 | 150 |
| 151 void URLRequestHttpJob::HttpFilterContext::ResetSdchResponseToFalse() { |
| 152 DCHECK(job_->sdch_dictionary_advertised_); |
| 153 job_->sdch_dictionary_advertised_ = false; |
| 154 } |
| 155 |
| 147 bool URLRequestHttpJob::HttpFilterContext::IsSdchResponse() const { | 156 bool URLRequestHttpJob::HttpFilterContext::IsSdchResponse() const { |
| 148 return job_->sdch_dictionary_advertised_; | 157 return job_->sdch_dictionary_advertised_; |
| 149 } | 158 } |
| 150 | 159 |
| 151 int64 URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const { | 160 int64 URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const { |
| 152 return job_->filter_input_byte_count(); | 161 return job_->filter_input_byte_count(); |
| 153 } | 162 } |
| 154 | 163 |
| 155 int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const { | 164 int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const { |
| 156 return job_->GetResponseCode(); | 165 return job_->GetResponseCode(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 } else { | 389 } else { |
| 381 // Include SDCH in acceptable list. | 390 // Include SDCH in acceptable list. |
| 382 request_info_.extra_headers.SetHeader( | 391 request_info_.extra_headers.SetHeader( |
| 383 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); | 392 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); |
| 384 if (!avail_dictionaries.empty()) { | 393 if (!avail_dictionaries.empty()) { |
| 385 request_info_.extra_headers.SetHeader( | 394 request_info_.extra_headers.SetHeader( |
| 386 kAvailDictionaryHeader, | 395 kAvailDictionaryHeader, |
| 387 avail_dictionaries); | 396 avail_dictionaries); |
| 388 sdch_dictionary_advertised_ = true; | 397 sdch_dictionary_advertised_ = true; |
| 389 // Since we're tagging this transaction as advertising a dictionary, we'll | 398 // Since we're tagging this transaction as advertising a dictionary, we'll |
| 390 // definately employ an SDCH filter (or tentative sdch filter) when we get | 399 // definitely employ an SDCH filter (or tentative sdch filter) when we get |
| 391 // a response. When done, we'll record histograms via SDCH_DECODE or | 400 // a response. When done, we'll record histograms via SDCH_DECODE or |
| 392 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times. | 401 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times. |
| 393 packet_timing_enabled_ = true; | 402 packet_timing_enabled_ = true; |
| 394 } | 403 } |
| 395 } | 404 } |
| 396 | 405 |
| 397 URLRequestContext* context = request_->context(); | 406 URLRequestContext* context = request_->context(); |
| 398 if (context) { | 407 if (context) { |
| 399 // Only add default Accept-Language and Accept-Charset if the request | 408 // Only add default Accept-Language and Accept-Charset if the request |
| 400 // didn't have them specified. | 409 // didn't have them specified. |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 return NULL; | 868 return NULL; |
| 860 | 869 |
| 861 std::vector<Filter::FilterType> encoding_types; | 870 std::vector<Filter::FilterType> encoding_types; |
| 862 std::string encoding_type; | 871 std::string encoding_type; |
| 863 void* iter = NULL; | 872 void* iter = NULL; |
| 864 while (response_info_->headers->EnumerateHeader(&iter, "Content-Encoding", | 873 while (response_info_->headers->EnumerateHeader(&iter, "Content-Encoding", |
| 865 &encoding_type)) { | 874 &encoding_type)) { |
| 866 encoding_types.push_back(Filter::ConvertEncodingToType(encoding_type)); | 875 encoding_types.push_back(Filter::ConvertEncodingToType(encoding_type)); |
| 867 } | 876 } |
| 868 | 877 |
| 878 if (filter_context_->IsSdchResponse()) { |
| 879 // We are wary of proxies that discard or damage SDCH encoding. If a server |
| 880 // explicitly states that this is not SDCH content, then we can correct our |
| 881 // assumption that this is an SDCH response, and avoid the need to recover |
| 882 // as though the content is corrupted (when we discover it is not SDCH |
| 883 // encoded). |
| 884 std::string sdch_response_status; |
| 885 iter = NULL; |
| 886 while (response_info_->headers->EnumerateHeader(&iter, "X-Sdch-Encode", |
| 887 &sdch_response_status)) { |
| 888 if (sdch_response_status == "0") { |
| 889 filter_context_->ResetSdchResponseToFalse(); |
| 890 break; |
| 891 } |
| 892 } |
| 893 } |
| 894 |
| 869 // Even if encoding types are empty, there is a chance that we need to add | 895 // Even if encoding types are empty, there is a chance that we need to add |
| 870 // some decoding, as some proxies strip encoding completely. In such cases, | 896 // some decoding, as some proxies strip encoding completely. In such cases, |
| 871 // we may need to add (for example) SDCH filtering (when the context suggests | 897 // we may need to add (for example) SDCH filtering (when the context suggests |
| 872 // it is appropriate). | 898 // it is appropriate). |
| 873 Filter::FixupEncodingTypes(*filter_context_, &encoding_types); | 899 Filter::FixupEncodingTypes(*filter_context_, &encoding_types); |
| 874 | 900 |
| 875 return !encoding_types.empty() | 901 return !encoding_types.empty() |
| 876 ? Filter::Factory(encoding_types, *filter_context_) : NULL; | 902 ? Filter::Factory(encoding_types, *filter_context_) : NULL; |
| 877 } | 903 } |
| 878 | 904 |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 } | 1395 } |
| 1370 | 1396 |
| 1371 bool URLRequestHttpJob::IsCompressibleContent() const { | 1397 bool URLRequestHttpJob::IsCompressibleContent() const { |
| 1372 std::string mime_type; | 1398 std::string mime_type; |
| 1373 return GetMimeType(&mime_type) && | 1399 return GetMimeType(&mime_type) && |
| 1374 (IsSupportedJavascriptMimeType(mime_type.c_str()) || | 1400 (IsSupportedJavascriptMimeType(mime_type.c_str()) || |
| 1375 IsSupportedNonImageMimeType(mime_type.c_str())); | 1401 IsSupportedNonImageMimeType(mime_type.c_str())); |
| 1376 } | 1402 } |
| 1377 | 1403 |
| 1378 } // namespace net | 1404 } // namespace net |
| OLD | NEW |