OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 bool GetMimeType(std::string* mime_type) const override; | 66 bool GetMimeType(std::string* mime_type) const override; |
67 bool GetURL(GURL* gurl) const override; | 67 bool GetURL(GURL* gurl) const override; |
68 base::Time GetRequestTime() const override; | 68 base::Time GetRequestTime() const override; |
69 bool IsCachedContent() const override; | 69 bool IsCachedContent() const override; |
70 SdchManager::DictionarySet* SdchDictionariesAdvertised() const override; | 70 SdchManager::DictionarySet* SdchDictionariesAdvertised() const override; |
71 int64 GetByteReadCount() const override; | 71 int64 GetByteReadCount() const override; |
72 int GetResponseCode() const override; | 72 int GetResponseCode() const override; |
73 const URLRequestContext* GetURLRequestContext() const override; | 73 const URLRequestContext* GetURLRequestContext() const override; |
74 void RecordPacketStats(StatisticSelector statistic) const override; | 74 void RecordPacketStats(StatisticSelector statistic) const override; |
75 const BoundNetLog& GetNetLog() const override; | 75 const BoundNetLog& GetNetLog() const override; |
| 76 bool IsBrotliEnabled() const override; |
76 | 77 |
77 private: | 78 private: |
78 URLRequestHttpJob* job_; | 79 URLRequestHttpJob* job_; |
79 | 80 |
80 // URLRequestHttpJob may be detached from URLRequest, but we still need to | 81 // URLRequestHttpJob may be detached from URLRequest, but we still need to |
81 // return something. | 82 // return something. |
82 BoundNetLog dummy_log_; | 83 BoundNetLog dummy_log_; |
83 | 84 |
84 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); | 85 DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); |
85 }; | 86 }; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 133 |
133 void URLRequestHttpJob::HttpFilterContext::RecordPacketStats( | 134 void URLRequestHttpJob::HttpFilterContext::RecordPacketStats( |
134 StatisticSelector statistic) const { | 135 StatisticSelector statistic) const { |
135 job_->RecordPacketStats(statistic); | 136 job_->RecordPacketStats(statistic); |
136 } | 137 } |
137 | 138 |
138 const BoundNetLog& URLRequestHttpJob::HttpFilterContext::GetNetLog() const { | 139 const BoundNetLog& URLRequestHttpJob::HttpFilterContext::GetNetLog() const { |
139 return job_->request() ? job_->request()->net_log() : dummy_log_; | 140 return job_->request() ? job_->request()->net_log() : dummy_log_; |
140 } | 141 } |
141 | 142 |
| 143 bool URLRequestHttpJob::HttpFilterContext::IsBrotliEnabled() const { |
| 144 if (!job_->request()) |
| 145 return false; |
| 146 const URLRequestContext* context = job_->request()->context(); |
| 147 if (!context) |
| 148 return false; |
| 149 const HttpNetworkSession::Params* params = context->GetNetworkSessionParams(); |
| 150 if (!params) |
| 151 return false; |
| 152 return params->enable_brotli; |
| 153 } |
| 154 |
142 // TODO(darin): make sure the port blocking code is not lost | 155 // TODO(darin): make sure the port blocking code is not lost |
143 // static | 156 // static |
144 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, | 157 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, |
145 NetworkDelegate* network_delegate, | 158 NetworkDelegate* network_delegate, |
146 const std::string& scheme) { | 159 const std::string& scheme) { |
147 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || | 160 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || |
148 scheme == "wss"); | 161 scheme == "wss"); |
149 | 162 |
150 if (!request->context()->http_transaction_factory()) { | 163 if (!request->context()->http_transaction_factory()) { |
151 NOTREACHED() << "requires a valid context"; | 164 NOTREACHED() << "requires a valid context"; |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 packet_timing_enabled_ = true; | 602 packet_timing_enabled_ = true; |
590 if (base::RandDouble() < .01) { | 603 if (base::RandDouble() < .01) { |
591 sdch_test_control_ = true; // 1% probability. | 604 sdch_test_control_ = true; // 1% probability. |
592 dictionaries_advertised_.reset(); | 605 dictionaries_advertised_.reset(); |
593 advertise_sdch = false; | 606 advertise_sdch = false; |
594 } else { | 607 } else { |
595 sdch_test_activated_ = true; | 608 sdch_test_activated_ = true; |
596 } | 609 } |
597 } | 610 } |
598 | 611 |
| 612 // Advertise "br" encoding only if transferred data is opaque to proxy. |
| 613 bool advertise_brotli = false; |
| 614 const HttpNetworkSession::Params* network_session_params = |
| 615 request()->context()->GetNetworkSessionParams(); |
| 616 if (network_session_params && network_session_params->enable_brotli) { |
| 617 advertise_brotli = !request()->url().SchemeIs(url::kHttpScheme); |
| 618 } |
| 619 |
599 // Supply Accept-Encoding headers first so that it is more likely that they | 620 // Supply Accept-Encoding headers first so that it is more likely that they |
600 // will be in the first transmitted packet. This can sometimes make it | 621 // will be in the first transmitted packet. This can sometimes make it |
601 // easier to filter and analyze the streams to assure that a proxy has not | 622 // easier to filter and analyze the streams to assure that a proxy has not |
602 // damaged these headers. Some proxies deliberately corrupt Accept-Encoding | 623 // damaged these headers. Some proxies deliberately corrupt Accept-Encoding |
603 // headers. | 624 // headers. |
604 if (!advertise_sdch) { | 625 |
605 // Tell the server what compression formats we support (other than SDCH). | 626 std::string advertised_encodings = "gzip, deflate"; |
| 627 if (advertise_sdch) |
| 628 advertised_encodings += ", sdch"; |
| 629 #if !defined(DISABLE_BROTLI_SUPPORT) |
| 630 if (advertise_brotli) |
| 631 advertised_encodings += ", br"; |
| 632 #endif |
| 633 |
| 634 // Tell the server what compression formats we support. |
| 635 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 636 advertised_encodings); |
| 637 |
| 638 if (advertise_sdch && dictionaries_advertised_) { |
606 request_info_.extra_headers.SetHeader( | 639 request_info_.extra_headers.SetHeader( |
607 HttpRequestHeaders::kAcceptEncoding, "gzip, deflate"); | 640 kAvailDictionaryHeader, |
608 } else { | 641 dictionaries_advertised_->GetDictionaryClientHashList()); |
609 // Include SDCH in acceptable list. | 642 // Since we're tagging this transaction as advertising a dictionary, |
610 request_info_.extra_headers.SetHeader( | 643 // we'll definitely employ an SDCH filter (or tentative sdch filter) |
611 HttpRequestHeaders::kAcceptEncoding, "gzip, deflate, sdch"); | 644 // when we get a response. When done, we'll record histograms via |
612 if (dictionaries_advertised_) { | 645 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet |
613 request_info_.extra_headers.SetHeader( | 646 // arrival times. |
614 kAvailDictionaryHeader, | 647 packet_timing_enabled_ = true; |
615 dictionaries_advertised_->GetDictionaryClientHashList()); | |
616 // Since we're tagging this transaction as advertising a dictionary, | |
617 // we'll definitely employ an SDCH filter (or tentative sdch filter) | |
618 // when we get a response. When done, we'll record histograms via | |
619 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet | |
620 // arrival times. | |
621 packet_timing_enabled_ = true; | |
622 } | |
623 } | 648 } |
624 } | 649 } |
625 | 650 |
626 if (http_user_agent_settings_) { | 651 if (http_user_agent_settings_) { |
627 // Only add default Accept-Language if the request didn't have it | 652 // Only add default Accept-Language if the request didn't have it |
628 // specified. | 653 // specified. |
629 std::string accept_language = | 654 std::string accept_language = |
630 http_user_agent_settings_->GetAcceptLanguage(); | 655 http_user_agent_settings_->GetAcceptLanguage(); |
631 if (!accept_language.empty()) { | 656 if (!accept_language.empty()) { |
632 request_info_.extra_headers.SetHeaderIfMissing( | 657 request_info_.extra_headers.SetHeaderIfMissing( |
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 return override_response_headers_.get() ? | 1605 return override_response_headers_.get() ? |
1581 override_response_headers_.get() : | 1606 override_response_headers_.get() : |
1582 transaction_->GetResponseInfo()->headers.get(); | 1607 transaction_->GetResponseInfo()->headers.get(); |
1583 } | 1608 } |
1584 | 1609 |
1585 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1610 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1586 awaiting_callback_ = false; | 1611 awaiting_callback_ = false; |
1587 } | 1612 } |
1588 | 1613 |
1589 } // namespace net | 1614 } // namespace net |
OLD | NEW |