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

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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 context to false when there is an update due
110 // to an explicit HTTP header.
wtc 2011/05/04 18:27:00 Nit: this comment doesn't even mention SDCH.
jar (doing other things) 2011/05/04 18:31:51 Done.
111 void SetSdchResponse(bool active);
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
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::SetSdchResponse(bool active) {
152 // Currently only for use to reset the context to false, after seeing an
153 // explicit HTTP header.
154 DCHECK(job_->sdch_dictionary_advertised_);
155 DCHECK(!active);
wtc 2011/05/04 18:27:00 It's strange to assert that a function argument ca
jar (doing other things) 2011/05/04 18:31:51 Done.
156 job_->sdch_dictionary_advertised_ = active;
157 }
158
147 bool URLRequestHttpJob::HttpFilterContext::IsSdchResponse() const { 159 bool URLRequestHttpJob::HttpFilterContext::IsSdchResponse() const {
148 return job_->sdch_dictionary_advertised_; 160 return job_->sdch_dictionary_advertised_;
149 } 161 }
150 162
151 int64 URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const { 163 int64 URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const {
152 return job_->filter_input_byte_count(); 164 return job_->filter_input_byte_count();
153 } 165 }
154 166
155 int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const { 167 int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const {
156 return job_->GetResponseCode(); 168 return job_->GetResponseCode();
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } else { 392 } else {
381 // Include SDCH in acceptable list. 393 // Include SDCH in acceptable list.
382 request_info_.extra_headers.SetHeader( 394 request_info_.extra_headers.SetHeader(
383 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch"); 395 HttpRequestHeaders::kAcceptEncoding, "gzip,deflate,sdch");
384 if (!avail_dictionaries.empty()) { 396 if (!avail_dictionaries.empty()) {
385 request_info_.extra_headers.SetHeader( 397 request_info_.extra_headers.SetHeader(
386 kAvailDictionaryHeader, 398 kAvailDictionaryHeader,
387 avail_dictionaries); 399 avail_dictionaries);
388 sdch_dictionary_advertised_ = true; 400 sdch_dictionary_advertised_ = true;
389 // Since we're tagging this transaction as advertising a dictionary, we'll 401 // 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 402 // 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 403 // a response. When done, we'll record histograms via SDCH_DECODE or
392 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times. 404 // SDCH_PASSTHROUGH. Hence we need to record packet arrival times.
393 packet_timing_enabled_ = true; 405 packet_timing_enabled_ = true;
394 } 406 }
395 } 407 }
396 408
397 URLRequestContext* context = request_->context(); 409 URLRequestContext* context = request_->context();
398 if (context) { 410 if (context) {
399 // Only add default Accept-Language and Accept-Charset if the request 411 // Only add default Accept-Language and Accept-Charset if the request
400 // didn't have them specified. 412 // didn't have them specified.
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 return NULL; 871 return NULL;
860 872
861 std::vector<Filter::FilterType> encoding_types; 873 std::vector<Filter::FilterType> encoding_types;
862 std::string encoding_type; 874 std::string encoding_type;
863 void* iter = NULL; 875 void* iter = NULL;
864 while (response_info_->headers->EnumerateHeader(&iter, "Content-Encoding", 876 while (response_info_->headers->EnumerateHeader(&iter, "Content-Encoding",
865 &encoding_type)) { 877 &encoding_type)) {
866 encoding_types.push_back(Filter::ConvertEncodingToType(encoding_type)); 878 encoding_types.push_back(Filter::ConvertEncodingToType(encoding_type));
867 } 879 }
868 880
881 if (filter_context_->IsSdchResponse()) {
882 // We are wary of proxies that discard or damage SDCH encoding. If a server
883 // explicitly states that this is not SDCH content, then we can correct our
884 // assumption that this is an SDCH response, and avoid the need to recover
885 // as though the content is corrupted (when we discover it is not SDCH
886 // encoded).
887 std::string sdch_response_status;
888 iter = NULL;
889 while (response_info_->headers->EnumerateHeader(&iter, "X-Sdch-Encode",
890 &sdch_response_status)) {
891 if (sdch_response_status == "0") {
892 filter_context_->SetSdchResponse(false);
893 break;
894 }
895 }
896 }
897
869 // Even if encoding types are empty, there is a chance that we need to add 898 // 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, 899 // 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 900 // we may need to add (for example) SDCH filtering (when the context suggests
872 // it is appropriate). 901 // it is appropriate).
873 Filter::FixupEncodingTypes(*filter_context_, &encoding_types); 902 Filter::FixupEncodingTypes(*filter_context_, &encoding_types);
874 903
875 return !encoding_types.empty() 904 return !encoding_types.empty()
876 ? Filter::Factory(encoding_types, *filter_context_) : NULL; 905 ? Filter::Factory(encoding_types, *filter_context_) : NULL;
877 } 906 }
878 907
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 } 1398 }
1370 1399
1371 bool URLRequestHttpJob::IsCompressibleContent() const { 1400 bool URLRequestHttpJob::IsCompressibleContent() const {
1372 std::string mime_type; 1401 std::string mime_type;
1373 return GetMimeType(&mime_type) && 1402 return GetMimeType(&mime_type) &&
1374 (IsSupportedJavascriptMimeType(mime_type.c_str()) || 1403 (IsSupportedJavascriptMimeType(mime_type.c_str()) ||
1375 IsSupportedNonImageMimeType(mime_type.c_str())); 1404 IsSupportedNonImageMimeType(mime_type.c_str()));
1376 } 1405 }
1377 1406
1378 } // namespace net 1407 } // 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