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

Unified Diff: net/url_request/url_request_http_job.cc

Issue 1431723002: Add brotli content-encoding filter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add brotli reference link Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: net/url_request/url_request_http_job.cc
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index dac461d01031d3d780531e13518515a030483747..f8986f7425b863420de06be84eaf9954f4c0b862 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -73,6 +73,7 @@ class URLRequestHttpJob::HttpFilterContext : public FilterContext {
const URLRequestContext* GetURLRequestContext() const override;
void RecordPacketStats(StatisticSelector statistic) const override;
const BoundNetLog& GetNetLog() const override;
+ bool IsBrotliEnabled() const override;
private:
URLRequestHttpJob* job_;
@@ -139,6 +140,18 @@ const BoundNetLog& URLRequestHttpJob::HttpFilterContext::GetNetLog() const {
return job_->request() ? job_->request()->net_log() : dummy_log_;
}
+bool URLRequestHttpJob::HttpFilterContext::IsBrotliEnabled() const {
+ if (!job_->request())
+ return false;
+ const URLRequestContext* context = job_->request()->context();
+ if (!context)
+ return false;
+ const HttpNetworkSession::Params* params = context->GetNetworkSessionParams();
+ if (!params)
+ return false;
+ return params->enable_brotli;
+}
+
// TODO(darin): make sure the port blocking code is not lost
// static
URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
@@ -596,30 +609,42 @@ void URLRequestHttpJob::AddExtraHeaders() {
}
}
+ // Advertise "br" encoding only if transferred data is opaque to proxy.
+ bool advertise_brotli = false;
+ const HttpNetworkSession::Params* network_session_params =
+ request()->context()->GetNetworkSessionParams();
+ if (network_session_params && network_session_params->enable_brotli) {
+ advertise_brotli = !request()->url().SchemeIs(url::kHttpScheme);
+ }
+
// Supply Accept-Encoding headers first so that it is more likely that they
// will be in the first transmitted packet. This can sometimes make it
// easier to filter and analyze the streams to assure that a proxy has not
// damaged these headers. Some proxies deliberately corrupt Accept-Encoding
// headers.
- if (!advertise_sdch) {
- // Tell the server what compression formats we support (other than SDCH).
- request_info_.extra_headers.SetHeader(
- HttpRequestHeaders::kAcceptEncoding, "gzip, deflate");
- } else {
- // Include SDCH in acceptable list.
+
+ std::string advertised_encodings = "gzip, deflate";
+ if (advertise_sdch)
+ advertised_encodings += ", sdch";
+#if !defined(DISABLE_BROTLI_SUPPORT)
+ if (advertise_brotli)
+ advertised_encodings += ", br";
+#endif
+
+ // Tell the server what compression formats we support.
+ request_info_.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding,
+ advertised_encodings);
+
+ if (advertise_sdch && dictionaries_advertised_) {
request_info_.extra_headers.SetHeader(
- HttpRequestHeaders::kAcceptEncoding, "gzip, deflate, sdch");
- if (dictionaries_advertised_) {
- request_info_.extra_headers.SetHeader(
- kAvailDictionaryHeader,
- dictionaries_advertised_->GetDictionaryClientHashList());
- // Since we're tagging this transaction as advertising a dictionary,
- // we'll definitely employ an SDCH filter (or tentative sdch filter)
- // when we get a response. When done, we'll record histograms via
- // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet
- // arrival times.
- packet_timing_enabled_ = true;
- }
+ kAvailDictionaryHeader,
+ dictionaries_advertised_->GetDictionaryClientHashList());
+ // Since we're tagging this transaction as advertising a dictionary,
+ // we'll definitely employ an SDCH filter (or tentative sdch filter)
+ // when we get a response. When done, we'll record histograms via
+ // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet
+ // arrival times.
+ packet_timing_enabled_ = true;
}
}

Powered by Google App Engine
This is Rietveld 408576698