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

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 6909033: Allow server to indicate a non-SDCH encoding (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 public: 94 public:
95 explicit HttpFilterContext(URLRequestHttpJob* job); 95 explicit HttpFilterContext(URLRequestHttpJob* job);
96 virtual ~HttpFilterContext(); 96 virtual ~HttpFilterContext();
97 97
98 // FilterContext implementation. 98 // FilterContext implementation.
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 void SetSdchResponse(bool active);
wtc 2011/05/04 17:22:36 This method should not be listed in this group bec
jar (doing other things) 2011/05/04 17:24:50 Done.
104 virtual bool IsSdchResponse() const; 105 virtual bool IsSdchResponse() const;
105 virtual int64 GetByteReadCount() const; 106 virtual int64 GetByteReadCount() const;
106 virtual int GetResponseCode() const; 107 virtual int GetResponseCode() const;
107 virtual void RecordPacketStats(StatisticSelector statistic) const; 108 virtual void RecordPacketStats(StatisticSelector statistic) const;
108 109
109 private: 110 private:
110 URLRequestHttpJob* job_; 111 URLRequestHttpJob* job_;
111 112
112 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); 113 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext);
113 }; 114 };
(...skipping 23 matching lines...) Expand all
137 } 138 }
138 139
139 bool URLRequestHttpJob::HttpFilterContext::IsCachedContent() const { 140 bool URLRequestHttpJob::HttpFilterContext::IsCachedContent() const {
140 return job_->is_cached_content_; 141 return job_->is_cached_content_;
141 } 142 }
142 143
143 bool URLRequestHttpJob::HttpFilterContext::IsDownload() const { 144 bool URLRequestHttpJob::HttpFilterContext::IsDownload() const {
144 return (job_->request_info_.load_flags & LOAD_IS_DOWNLOAD) != 0; 145 return (job_->request_info_.load_flags & LOAD_IS_DOWNLOAD) != 0;
145 } 146 }
146 147
148 void URLRequestHttpJob::HttpFilterContext::SetSdchResponse(bool active) {
149 job_->sdch_dictionary_advertised_ = false;
wtc 2011/05/04 17:22:36 Typo: false => active Or perhaps you just need a
jar (doing other things) 2011/05/04 17:24:50 Done.
150 }
151
147 bool URLRequestHttpJob::HttpFilterContext::IsSdchResponse() const { 152 bool URLRequestHttpJob::HttpFilterContext::IsSdchResponse() const {
148 return job_->sdch_dictionary_advertised_; 153 return job_->sdch_dictionary_advertised_;
149 } 154 }
150 155
151 int64 URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const { 156 int64 URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const {
152 return job_->filter_input_byte_count(); 157 return job_->filter_input_byte_count();
153 } 158 }
154 159
155 int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const { 160 int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const {
156 return job_->GetResponseCode(); 161 return job_->GetResponseCode();
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } else { 385 } else {
381 // Include SDCH in acceptable list. 386 // Include SDCH in acceptable list.
382 request_info_.extra_headers.SetHeader( 387 request_info_.extra_headers.SetHeader(
383 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); 388 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch");
384 if (!avail_dictionaries.empty()) { 389 if (!avail_dictionaries.empty()) {
385 request_info_.extra_headers.SetHeader( 390 request_info_.extra_headers.SetHeader(
386 kAvailDictionaryHeader, 391 kAvailDictionaryHeader,
387 avail_dictionaries); 392 avail_dictionaries);
388 sdch_dictionary_advertised_ = true; 393 sdch_dictionary_advertised_ = true;
389 // Since we're tagging this transaction as advertising a dictionary, we'll 394 // 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 395 // definately employ an SDCH filter (or tentative sdch filter) when we get
kmixter1 2011/05/04 17:01:05 s/definately/definitely/. Maybe want to update th
jar (doing other things) 2011/05/04 17:24:50 Done.
391 // a response. When done, we'll record histograms via SDCH_DECODE or 396 // a response. When done, we'll record histograms via SDCH_DECODE or
392 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times. 397 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times.
393 packet_timing_enabled_ = true; 398 packet_timing_enabled_ = true;
394 } 399 }
395 } 400 }
396 401
397 URLRequestContext* context = request_->context(); 402 URLRequestContext* context = request_->context();
398 if (context) { 403 if (context) {
399 // Only add default Accept-Language and Accept-Charset if the request 404 // Only add default Accept-Language and Accept-Charset if the request
400 // didn't have them specified. 405 // didn't have them specified.
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 return NULL; 864 return NULL;
860 865
861 std::vector<Filter::FilterType> encoding_types; 866 std::vector<Filter::FilterType> encoding_types;
862 std::string encoding_type; 867 std::string encoding_type;
863 void* iter = NULL; 868 void* iter = NULL;
864 while (response_info_->headers->EnumerateHeader(&iter, "Content-Encoding", 869 while (response_info_->headers->EnumerateHeader(&iter, "Content-Encoding",
865 &encoding_type)) { 870 &encoding_type)) {
866 encoding_types.push_back(Filter::ConvertEncodingToType(encoding_type)); 871 encoding_types.push_back(Filter::ConvertEncodingToType(encoding_type));
867 } 872 }
868 873
874 if (filter_context_->IsSdchResponse()) {
875 // We are wary of proxies that discard or damage SDCH encoding. If a server
876 // explicitly states that this is not SDCH content, then we can correct our
877 // assumption that this is an SDCH response, and avoid the need to recover
878 // as though the content is corrupted (when we discover it is not SDCH
879 // encoded).
880 std::string sdch_response_status;
881 iter = NULL;
882 while (response_info_->headers->EnumerateHeader(&iter, "X-Sdch-Encode",
883 &sdch_response_status)) {
884 if (sdch_response_status == "0") {
885 filter_context_->SetSdchResponse(false);
886 break;
887 }
888 }
889 }
890
869 // Even if encoding types are empty, there is a chance that we need to add 891 // 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, 892 // 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 893 // we may need to add (for example) SDCH filtering (when the context suggests
872 // it is appropriate). 894 // it is appropriate).
873 Filter::FixupEncodingTypes(*filter_context_, &encoding_types); 895 Filter::FixupEncodingTypes(*filter_context_, &encoding_types);
874 896
875 return !encoding_types.empty() 897 return !encoding_types.empty()
876 ? Filter::Factory(encoding_types, *filter_context_) : NULL; 898 ? Filter::Factory(encoding_types, *filter_context_) : NULL;
877 } 899 }
878 900
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 } 1391 }
1370 1392
1371 bool URLRequestHttpJob::IsCompressibleContent() const { 1393 bool URLRequestHttpJob::IsCompressibleContent() const {
1372 std::string mime_type; 1394 std::string mime_type;
1373 return GetMimeType(&mime_type) && 1395 return GetMimeType(&mime_type) &&
1374 (IsSupportedJavascriptMimeType(mime_type.c_str()) || 1396 (IsSupportedJavascriptMimeType(mime_type.c_str()) ||
1375 IsSupportedNonImageMimeType(mime_type.c_str())); 1397 IsSupportedNonImageMimeType(mime_type.c_str()));
1376 } 1398 }
1377 1399
1378 } // namespace net 1400 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698