[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 5 | #include "net/url_request/url_request_http_job.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 6 | |
[email protected] | 4ed2755f | 2008-12-15 09:01:33 | [diff] [blame] | 7 | #include "base/base_switches.h" |
[email protected] | 4f9e5c8 | 2011-11-17 16:04:56 | [diff] [blame] | 8 | #include "base/bind.h" |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 9 | #include "base/bind_helpers.h" |
[email protected] | 4ed2755f | 2008-12-15 09:01:33 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | 39ce5c0 | 2008-08-22 04:03:44 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
[email protected] | 6088942 | 2008-09-23 01:18:16 | [diff] [blame] | 12 | #include "base/file_version_info.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 13 | #include "base/location.h" |
[email protected] | 8684a881 | 2011-03-22 13:59:38 | [diff] [blame] | 14 | #include "base/metrics/field_trial.h" |
asvitkine | c3c9372 | 2015-06-17 14:48:37 | [diff] [blame] | 15 | #include "base/metrics/histogram_macros.h" |
vadimt | 29494d8 | 2014-11-04 20:06:26 | [diff] [blame] | 16 | #include "base/profiler/scoped_tracker.h" |
[email protected] | 5b90b5d | 2009-04-30 23:06:01 | [diff] [blame] | 17 | #include "base/rand_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 18 | #include "base/single_thread_task_runner.h" |
[email protected] | 4dc3ad4f | 2013-06-11 07:15:50 | [diff] [blame] | 19 | #include "base/strings/string_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 20 | #include "base/thread_task_runner_handle.h" |
[email protected] | f002abb | 2013-06-28 02:30:21 | [diff] [blame] | 21 | #include "base/time/time.h" |
estade | 5e5529d | 2015-05-21 20:59:11 | [diff] [blame] | 22 | #include "base/values.h" |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 23 | #include "net/base/host_port_pair.h" |
[email protected] | b843072 | 2008-09-17 20:05:44 | [diff] [blame] | 24 | #include "net/base/load_flags.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 25 | #include "net/base/net_errors.h" |
| 26 | #include "net/base/net_util.h" |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 27 | #include "net/base/network_delegate.h" |
tbansal | 79ed5cd | 2015-08-10 18:53:56 | [diff] [blame] | 28 | #include "net/base/network_quality_estimator.h" |
[email protected] | 6088942 | 2008-09-23 01:18:16 | [diff] [blame] | 29 | #include "net/base/sdch_manager.h" |
baranovich | c5e3865 | 2014-11-14 03:08:15 | [diff] [blame] | 30 | #include "net/base/sdch_net_log_params.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 31 | #include "net/cert/cert_status_flags.h" |
[email protected] | dc8313a | 2014-03-24 21:38:14 | [diff] [blame] | 32 | #include "net/cookies/cookie_store.h" |
[email protected] | 26219171 | 2014-03-22 00:46:57 | [diff] [blame] | 33 | #include "net/http/http_content_disposition.h" |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 34 | #include "net/http/http_network_session.h" |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 35 | #include "net/http/http_request_headers.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 36 | #include "net/http/http_response_headers.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 37 | #include "net/http/http_response_info.h" |
[email protected] | 9094b60 | 2012-02-27 21:44:58 | [diff] [blame] | 38 | #include "net/http/http_status_code.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 39 | #include "net/http/http_transaction.h" |
| 40 | #include "net/http/http_transaction_factory.h" |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 41 | #include "net/http/http_util.h" |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 42 | #include "net/proxy/proxy_info.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 43 | #include "net/ssl/ssl_cert_request_info.h" |
| 44 | #include "net/ssl/ssl_config_service.h" |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 45 | #include "net/url_request/http_user_agent_settings.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 46 | #include "net/url_request/url_request.h" |
xunjieli | 3bb781a | 2015-07-22 22:40:34 | [diff] [blame] | 47 | #include "net/url_request/url_request_backoff_manager.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 48 | #include "net/url_request/url_request_context.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/url_request/url_request_error_job.h" |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 50 | #include "net/url_request/url_request_job_factory.h" |
[email protected] | 06965e0 | 2009-09-04 21:36:42 | [diff] [blame] | 51 | #include "net/url_request/url_request_redirect_job.h" |
[email protected] | 6b3f964 | 2010-11-25 02:29:06 | [diff] [blame] | 52 | #include "net/url_request/url_request_throttler_manager.h" |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 53 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 54 | |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 55 | static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; |
| 56 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 57 | namespace net { |
| 58 | |
[email protected] | 2e92354c | 2011-03-25 20:49:53 | [diff] [blame] | 59 | class URLRequestHttpJob::HttpFilterContext : public FilterContext { |
| 60 | public: |
| 61 | explicit HttpFilterContext(URLRequestHttpJob* job); |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 62 | ~HttpFilterContext() override; |
[email protected] | 2e92354c | 2011-03-25 20:49:53 | [diff] [blame] | 63 | |
| 64 | // FilterContext implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 65 | bool GetMimeType(std::string* mime_type) const override; |
| 66 | bool GetURL(GURL* gurl) const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 67 | base::Time GetRequestTime() const override; |
| 68 | bool IsCachedContent() const override; |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 69 | SdchManager::DictionarySet* SdchDictionariesAdvertised() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 70 | int64 GetByteReadCount() const override; |
| 71 | int GetResponseCode() const override; |
| 72 | const URLRequestContext* GetURLRequestContext() const override; |
| 73 | void RecordPacketStats(StatisticSelector statistic) const override; |
baranovich | c5e3865 | 2014-11-14 03:08:15 | [diff] [blame] | 74 | const BoundNetLog& GetNetLog() const override; |
[email protected] | 2e92354c | 2011-03-25 20:49:53 | [diff] [blame] | 75 | |
| 76 | private: |
| 77 | URLRequestHttpJob* job_; |
| 78 | |
baranovich | c5e3865 | 2014-11-14 03:08:15 | [diff] [blame] | 79 | // URLRequestHttpJob may be detached from URLRequest, but we still need to |
| 80 | // return something. |
| 81 | BoundNetLog dummy_log_; |
| 82 | |
[email protected] | 2e92354c | 2011-03-25 20:49:53 | [diff] [blame] | 83 | DISALLOW_COPY_AND_ASSIGN(HttpFilterContext); |
| 84 | }; |
| 85 | |
[email protected] | fc01f23 | 2011-03-17 19:06:01 | [diff] [blame] | 86 | URLRequestHttpJob::HttpFilterContext::HttpFilterContext(URLRequestHttpJob* job) |
| 87 | : job_(job) { |
| 88 | DCHECK(job_); |
| 89 | } |
| 90 | |
| 91 | URLRequestHttpJob::HttpFilterContext::~HttpFilterContext() { |
| 92 | } |
| 93 | |
| 94 | bool URLRequestHttpJob::HttpFilterContext::GetMimeType( |
| 95 | std::string* mime_type) const { |
| 96 | return job_->GetMimeType(mime_type); |
| 97 | } |
| 98 | |
| 99 | bool URLRequestHttpJob::HttpFilterContext::GetURL(GURL* gurl) const { |
| 100 | if (!job_->request()) |
| 101 | return false; |
| 102 | *gurl = job_->request()->url(); |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | base::Time URLRequestHttpJob::HttpFilterContext::GetRequestTime() const { |
| 107 | return job_->request() ? job_->request()->request_time() : base::Time(); |
| 108 | } |
| 109 | |
| 110 | bool URLRequestHttpJob::HttpFilterContext::IsCachedContent() const { |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 111 | return job_->is_cached_content_; |
[email protected] | fc01f23 | 2011-03-17 19:06:01 | [diff] [blame] | 112 | } |
| 113 | |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 114 | SdchManager::DictionarySet* |
| 115 | URLRequestHttpJob::HttpFilterContext::SdchDictionariesAdvertised() const { |
| 116 | return job_->dictionaries_advertised_.get(); |
[email protected] | fc01f23 | 2011-03-17 19:06:01 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | int64 URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const { |
mmenke | bbf19be2 | 2015-04-11 02:44:48 | [diff] [blame] | 120 | return job_->prefilter_bytes_read(); |
[email protected] | fc01f23 | 2011-03-17 19:06:01 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const { |
| 124 | return job_->GetResponseCode(); |
| 125 | } |
| 126 | |
[email protected] | 6a58676 | 2014-06-15 16:02:22 | [diff] [blame] | 127 | const URLRequestContext* |
| 128 | URLRequestHttpJob::HttpFilterContext::GetURLRequestContext() const { |
| 129 | return job_->request() ? job_->request()->context() : NULL; |
| 130 | } |
| 131 | |
[email protected] | fc01f23 | 2011-03-17 19:06:01 | [diff] [blame] | 132 | void URLRequestHttpJob::HttpFilterContext::RecordPacketStats( |
| 133 | StatisticSelector statistic) const { |
| 134 | job_->RecordPacketStats(statistic); |
| 135 | } |
| 136 | |
baranovich | c5e3865 | 2014-11-14 03:08:15 | [diff] [blame] | 137 | const BoundNetLog& URLRequestHttpJob::HttpFilterContext::GetNetLog() const { |
| 138 | return job_->request() ? job_->request()->net_log() : dummy_log_; |
| 139 | } |
| 140 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 141 | // TODO(darin): make sure the port blocking code is not lost |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 142 | // static |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 143 | URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 144 | NetworkDelegate* network_delegate, |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 145 | const std::string& scheme) { |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 146 | DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || |
| 147 | scheme == "wss"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 148 | |
[email protected] | 81293f48 | 2012-08-13 19:35:45 | [diff] [blame] | 149 | if (!request->context()->http_transaction_factory()) { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 150 | NOTREACHED() << "requires a valid context"; |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 151 | return new URLRequestErrorJob( |
| 152 | request, network_delegate, ERR_INVALID_ARGUMENT); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 153 | } |
| 154 | |
[email protected] | ce572df | 2012-05-04 19:47:17 | [diff] [blame] | 155 | GURL redirect_url; |
[email protected] | 8ccc69f | 2012-11-28 19:52:14 | [diff] [blame] | 156 | if (request->GetHSTSRedirect(&redirect_url)) { |
| 157 | return new URLRequestRedirectJob( |
| 158 | request, network_delegate, redirect_url, |
| 159 | // Use status code 307 to preserve the method, so POST requests work. |
[email protected] | 7983c4a | 2014-03-12 01:47:09 | [diff] [blame] | 160 | URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS"); |
[email protected] | 8ccc69f | 2012-11-28 19:52:14 | [diff] [blame] | 161 | } |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 162 | return new URLRequestHttpJob(request, |
| 163 | network_delegate, |
| 164 | request->context()->http_user_agent_settings()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 167 | URLRequestHttpJob::URLRequestHttpJob( |
| 168 | URLRequest* request, |
| 169 | NetworkDelegate* network_delegate, |
| 170 | const HttpUserAgentSettings* http_user_agent_settings) |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 171 | : URLRequestJob(request, network_delegate), |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 172 | priority_(DEFAULT_PRIORITY), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 173 | response_info_(NULL), |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 174 | response_cookies_save_index_(0), |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 175 | proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 176 | server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
[email protected] | dd946bb | 2013-06-12 22:53:01 | [diff] [blame] | 177 | start_callback_(base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 178 | base::Unretained(this))), |
| 179 | notify_before_headers_sent_callback_( |
| 180 | base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, |
| 181 | base::Unretained(this))), |
[email protected] | 3589e55 | 2008-08-20 23:11:34 | [diff] [blame] | 182 | read_in_progress_(false), |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 183 | throttling_entry_(NULL), |
[email protected] | 5b90b5d | 2009-04-30 23:06:01 | [diff] [blame] | 184 | sdch_test_activated_(false), |
[email protected] | d8fd513 | 2009-05-15 01:06:53 | [diff] [blame] | 185 | sdch_test_control_(false), |
[email protected] | 00e48bf | 2010-12-03 06:15:42 | [diff] [blame] | 186 | is_cached_content_(false), |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 187 | request_creation_time_(), |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 188 | packet_timing_enabled_(false), |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 189 | done_(false), |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 190 | bytes_observed_in_packets_(0), |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 191 | request_time_snapshot_(), |
| 192 | final_packet_time_(), |
[email protected] | aa249b5 | 2013-04-30 01:04:32 | [diff] [blame] | 193 | filter_context_(new HttpFilterContext(this)), |
[email protected] | dd946bb | 2013-06-12 22:53:01 | [diff] [blame] | 194 | on_headers_received_callback_( |
| 195 | base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, |
| 196 | base::Unretained(this))), |
[email protected] | 5a07c19 | 2012-07-30 20:18:22 | [diff] [blame] | 197 | awaiting_callback_(false), |
[email protected] | 0981210 | 2014-05-24 00:04:11 | [diff] [blame] | 198 | http_user_agent_settings_(http_user_agent_settings), |
xunjieli | 3bb781a | 2015-07-22 22:40:34 | [diff] [blame] | 199 | backoff_manager_(request->context()->backoff_manager()), |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 200 | total_received_bytes_from_previous_transactions_(0), |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 201 | total_sent_bytes_from_previous_transactions_(0), |
[email protected] | 0981210 | 2014-05-24 00:04:11 | [diff] [blame] | 202 | weak_factory_(this) { |
[email protected] | a73a280 | 2012-05-02 19:20:15 | [diff] [blame] | 203 | URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 204 | if (manager) |
| 205 | throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 206 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 207 | ResetTimer(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 210 | URLRequestHttpJob::~URLRequestHttpJob() { |
| 211 | CHECK(!awaiting_callback_); |
| 212 | |
| 213 | DCHECK(!sdch_test_control_ || !sdch_test_activated_); |
| 214 | if (!is_cached_content_) { |
| 215 | if (sdch_test_control_) |
| 216 | RecordPacketStats(FilterContext::SDCH_EXPERIMENT_HOLDBACK); |
| 217 | if (sdch_test_activated_) |
| 218 | RecordPacketStats(FilterContext::SDCH_EXPERIMENT_DECODE); |
| 219 | } |
| 220 | // Make sure SDCH filters are told to emit histogram data while |
| 221 | // filter_context_ is still alive. |
| 222 | DestroyFilters(); |
| 223 | |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 224 | DoneWithRequest(ABORTED); |
| 225 | } |
| 226 | |
| 227 | void URLRequestHttpJob::SetPriority(RequestPriority priority) { |
| 228 | priority_ = priority; |
| 229 | if (transaction_) |
| 230 | transaction_->SetPriority(priority_); |
| 231 | } |
| 232 | |
| 233 | void URLRequestHttpJob::Start() { |
mmenke | 833437d | 2015-04-23 20:56:54 | [diff] [blame] | 234 | // TODO(mmenke): Remove ScopedTracker below once crbug.com/456327 is fixed. |
| 235 | tracked_objects::ScopedTracker tracking_profile( |
| 236 | FROM_HERE_WITH_EXPLICIT_FUNCTION("456327 URLRequestHttpJob::Start")); |
| 237 | |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 238 | DCHECK(!transaction_.get()); |
| 239 | |
[email protected] | 99ecf6e | 2013-04-10 22:46:13 | [diff] [blame] | 240 | // URLRequest::SetReferrer ensures that we do not send username and password |
| 241 | // fields in the referrer. |
| 242 | GURL referrer(request_->referrer()); |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 243 | |
| 244 | request_info_.url = request_->url(); |
| 245 | request_info_.method = request_->method(); |
| 246 | request_info_.load_flags = request_->load_flags(); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 247 | // Enable privacy mode if cookie settings or flags tell us not send or |
| 248 | // save cookies. |
| 249 | bool enable_privacy_mode = |
| 250 | (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) || |
| 251 | (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) || |
| 252 | CanEnablePrivacyMode(); |
| 253 | // Privacy mode could still be disabled in OnCookiesLoaded if we are going |
| 254 | // to send previously saved cookies. |
| 255 | request_info_.privacy_mode = enable_privacy_mode ? |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 256 | PRIVACY_MODE_ENABLED : PRIVACY_MODE_DISABLED; |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 257 | |
| 258 | // Strip Referer from request_info_.extra_headers to prevent, e.g., plugins |
| 259 | // from overriding headers that are controlled using other means. Otherwise a |
| 260 | // plugin could set a referrer although sending the referrer is inhibited. |
| 261 | request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kReferer); |
| 262 | |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 263 | // Our consumer should have made sure that this is a safe referrer. See for |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 264 | // instance WebCore::FrameLoader::HideReferrer. |
| 265 | if (referrer.is_valid()) { |
| 266 | request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 267 | referrer.spec()); |
| 268 | } |
| 269 | |
| 270 | request_info_.extra_headers.SetHeaderIfMissing( |
| 271 | HttpRequestHeaders::kUserAgent, |
| 272 | http_user_agent_settings_ ? |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 273 | http_user_agent_settings_->GetUserAgent() : std::string()); |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 274 | |
| 275 | AddExtraHeaders(); |
| 276 | AddCookieHeaderAndStart(); |
| 277 | } |
| 278 | |
| 279 | void URLRequestHttpJob::Kill() { |
[email protected] | 5033ab8 | 2013-03-22 20:17:46 | [diff] [blame] | 280 | if (!transaction_.get()) |
| 281 | return; |
| 282 | |
| 283 | weak_factory_.InvalidateWeakPtrs(); |
| 284 | DestroyTransaction(); |
| 285 | URLRequestJob::Kill(); |
| 286 | } |
| 287 | |
ttuttle | 3ae0692 | 2015-05-11 23:41:52 | [diff] [blame] | 288 | void URLRequestHttpJob::GetConnectionAttempts(ConnectionAttempts* out) const { |
| 289 | if (transaction_) |
| 290 | transaction_->GetConnectionAttempts(out); |
| 291 | else |
| 292 | out->clear(); |
| 293 | } |
| 294 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 295 | void URLRequestHttpJob::NotifyBeforeSendProxyHeadersCallback( |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 296 | const ProxyInfo& proxy_info, |
| 297 | HttpRequestHeaders* request_headers) { |
| 298 | DCHECK(request_headers); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 299 | DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 300 | if (network_delegate()) { |
| 301 | network_delegate()->NotifyBeforeSendProxyHeaders( |
| 302 | request_, |
| 303 | proxy_info, |
[email protected] | 1252d42f | 2014-07-01 21:20:20 | [diff] [blame] | 304 | request_headers); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
xunjieli | 3bb781a | 2015-07-22 22:40:34 | [diff] [blame] | 308 | void URLRequestHttpJob::NotifyBeforeNetworkStart(bool* defer) { |
| 309 | if (!request_) |
| 310 | return; |
| 311 | if (backoff_manager_) { |
xunjieli | 33550b84 | 2015-09-24 22:26:58 | [diff] [blame] | 312 | if ((request_->load_flags() & LOAD_MAYBE_USER_GESTURE) == 0 && |
| 313 | backoff_manager_->ShouldRejectRequest(request()->url(), |
xunjieli | 3bb781a | 2015-07-22 22:40:34 | [diff] [blame] | 314 | request()->request_time())) { |
| 315 | *defer = true; |
| 316 | base::MessageLoop::current()->PostTask( |
| 317 | FROM_HERE, |
| 318 | base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 319 | weak_factory_.GetWeakPtr(), ERR_TEMPORARY_BACKOFF)); |
| 320 | return; |
| 321 | } |
| 322 | } |
| 323 | URLRequestJob::NotifyBeforeNetworkStart(defer); |
| 324 | } |
| 325 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 326 | void URLRequestHttpJob::NotifyHeadersComplete() { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 327 | DCHECK(!response_info_); |
| 328 | |
| 329 | response_info_ = transaction_->GetResponseInfo(); |
| 330 | |
[email protected] | d8fd513 | 2009-05-15 01:06:53 | [diff] [blame] | 331 | // Save boolean, as we'll need this info at destruction time, and filters may |
| 332 | // also need this info. |
| 333 | is_cached_content_ = response_info_->was_cached; |
| 334 | |
xunjieli | 041e939 | 2015-05-19 21:51:33 | [diff] [blame] | 335 | if (!is_cached_content_ && throttling_entry_.get()) |
| 336 | throttling_entry_->UpdateWithResponse(GetResponseCode()); |
[email protected] | 6b3f964 | 2010-11-25 02:29:06 | [diff] [blame] | 337 | |
xunjieli | 3bb781a | 2015-07-22 22:40:34 | [diff] [blame] | 338 | if (!is_cached_content_) |
| 339 | ProcessBackoffHeader(); |
| 340 | |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 341 | // The ordering of these calls is not important. |
[email protected] | 77f6fb43 | 2009-09-05 14:21:09 | [diff] [blame] | 342 | ProcessStrictTransportSecurityHeader(); |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 343 | ProcessPublicKeyPinsHeader(); |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 344 | |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 345 | // Handle the server notification of a new SDCH dictionary. |
[email protected] | 6a58676 | 2014-06-15 16:02:22 | [diff] [blame] | 346 | SdchManager* sdch_manager(request()->context()->sdch_manager()); |
baranovich | c5e3865 | 2014-11-14 03:08:15 | [diff] [blame] | 347 | if (sdch_manager) { |
| 348 | SdchProblemCode rv = sdch_manager->IsInSupportedDomain(request()->url()); |
| 349 | if (rv != SDCH_OK) { |
ellyjones | 085ac46 | 2015-08-18 12:02:53 | [diff] [blame] | 350 | SdchManager::SdchErrorRecovery(rv); |
| 351 | request()->net_log().AddEvent( |
| 352 | NetLog::TYPE_SDCH_DECODING_ERROR, |
| 353 | base::Bind(&NetLogSdchResourceProblemCallback, rv)); |
baranovich | c5e3865 | 2014-11-14 03:08:15 | [diff] [blame] | 354 | } else { |
| 355 | const std::string name = "Get-Dictionary"; |
| 356 | std::string url_text; |
| 357 | void* iter = NULL; |
| 358 | // TODO(jar): We need to not fetch dictionaries the first time they are |
| 359 | // seen, but rather wait until we can justify their usefulness. |
| 360 | // For now, we will only fetch the first dictionary, which will at least |
| 361 | // require multiple suggestions before we get additional ones for this |
| 362 | // site. Eventually we should wait until a dictionary is requested |
| 363 | // several times |
| 364 | // before we even download it (so that we don't waste memory or |
| 365 | // bandwidth). |
| 366 | if (GetResponseHeaders()->EnumerateHeader(&iter, name, &url_text)) { |
| 367 | // Resolve suggested URL relative to request url. |
| 368 | GURL sdch_dictionary_url = request_->url().Resolve(url_text); |
| 369 | if (sdch_dictionary_url.is_valid()) { |
| 370 | rv = sdch_manager->OnGetDictionary(request_->url(), |
| 371 | sdch_dictionary_url); |
| 372 | if (rv != SDCH_OK) { |
| 373 | SdchManager::SdchErrorRecovery(rv); |
| 374 | request_->net_log().AddEvent( |
| 375 | NetLog::TYPE_SDCH_DICTIONARY_ERROR, |
| 376 | base::Bind(&NetLogSdchDictionaryFetchProblemCallback, rv, |
| 377 | sdch_dictionary_url, false)); |
| 378 | } |
| 379 | } |
[email protected] | 6a58676 | 2014-06-15 16:02:22 | [diff] [blame] | 380 | } |
[email protected] | 6088942 | 2008-09-23 01:18:16 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 384 | // Handle the server signalling no SDCH encoding. |
| 385 | if (dictionaries_advertised_) { |
| 386 | // We are wary of proxies that discard or damage SDCH encoding. If a server |
| 387 | // explicitly states that this is not SDCH content, then we can correct our |
| 388 | // assumption that this is an SDCH response, and avoid the need to recover |
| 389 | // as though the content is corrupted (when we discover it is not SDCH |
| 390 | // encoded). |
| 391 | std::string sdch_response_status; |
| 392 | void* iter = NULL; |
| 393 | while (GetResponseHeaders()->EnumerateHeader(&iter, "X-Sdch-Encode", |
| 394 | &sdch_response_status)) { |
| 395 | if (sdch_response_status == "0") { |
| 396 | dictionaries_advertised_.reset(); |
| 397 | break; |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 402 | // The HTTP transaction may be restarted several times for the purposes |
| 403 | // of sending authorization information. Each time it restarts, we get |
| 404 | // notified of the headers completion so that we can update the cookie store. |
| 405 | if (transaction_->IsReadyToRestartForAuth()) { |
| 406 | DCHECK(!response_info_->auth_challenge.get()); |
[email protected] | 87a09a9 | 2011-07-14 15:50:50 | [diff] [blame] | 407 | // TODO(battre): This breaks the webrequest API for |
| 408 | // URLRequestTestHTTP.BasicAuthWithCookies |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 409 | // where OnBeforeSendHeaders -> OnSendHeaders -> OnBeforeSendHeaders |
[email protected] | 87a09a9 | 2011-07-14 15:50:50 | [diff] [blame] | 410 | // occurs. |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 411 | RestartTransactionWithAuth(AuthCredentials()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 412 | return; |
| 413 | } |
| 414 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 415 | URLRequestJob::NotifyHeadersComplete(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | 85c1dce | 2011-07-06 12:01:29 | [diff] [blame] | 418 | void URLRequestHttpJob::NotifyDone(const URLRequestStatus& status) { |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 419 | DoneWithRequest(FINISHED); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 420 | URLRequestJob::NotifyDone(status); |
| 421 | } |
| 422 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 423 | void URLRequestHttpJob::DestroyTransaction() { |
[email protected] | c6a4eb9 | 2010-03-03 23:51:19 | [diff] [blame] | 424 | DCHECK(transaction_.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 425 | |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 426 | DoneWithRequest(ABORTED); |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 427 | |
| 428 | total_received_bytes_from_previous_transactions_ += |
| 429 | transaction_->GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 430 | total_sent_bytes_from_previous_transactions_ += |
| 431 | transaction_->GetTotalSentBytes(); |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 432 | transaction_.reset(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 433 | response_info_ = NULL; |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 434 | receive_headers_end_ = base::TimeTicks(); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 435 | } |
| 436 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 437 | void URLRequestHttpJob::StartTransaction() { |
mmenke | 833437d | 2015-04-23 20:56:54 | [diff] [blame] | 438 | // TODO(mmenke): Remove ScopedTracker below once crbug.com/456327 is fixed. |
| 439 | tracked_objects::ScopedTracker tracking_profile( |
| 440 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 441 | "456327 URLRequestHttpJob::StartTransaction")); |
| 442 | |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 443 | if (network_delegate()) { |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 444 | OnCallToDelegate(); |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 445 | int rv = network_delegate()->NotifyBeforeSendHeaders( |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 446 | request_, notify_before_headers_sent_callback_, |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 447 | &request_info_.extra_headers); |
| 448 | // If an extension blocks the request, we rely on the callback to |
[email protected] | b4438d3 | 2012-09-27 06:15:30 | [diff] [blame] | 449 | // MaybeStartTransactionInternal(). |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 450 | if (rv == ERR_IO_PENDING) |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 451 | return; |
[email protected] | b4438d3 | 2012-09-27 06:15:30 | [diff] [blame] | 452 | MaybeStartTransactionInternal(rv); |
| 453 | return; |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 454 | } |
| 455 | StartTransactionInternal(); |
| 456 | } |
| 457 | |
| 458 | void URLRequestHttpJob::NotifyBeforeSendHeadersCallback(int result) { |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 459 | // Check that there are no callbacks to already canceled requests. |
| 460 | DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 461 | |
[email protected] | b4438d3 | 2012-09-27 06:15:30 | [diff] [blame] | 462 | MaybeStartTransactionInternal(result); |
| 463 | } |
| 464 | |
| 465 | void URLRequestHttpJob::MaybeStartTransactionInternal(int result) { |
mmenke | 833437d | 2015-04-23 20:56:54 | [diff] [blame] | 466 | // TODO(mmenke): Remove ScopedTracker below once crbug.com/456327 is fixed. |
| 467 | tracked_objects::ScopedTracker tracking_profile( |
| 468 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 469 | "456327 URLRequestHttpJob::MaybeStartTransactionInternal")); |
| 470 | |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 471 | OnCallToDelegateComplete(); |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 472 | if (result == OK) { |
| 473 | StartTransactionInternal(); |
| 474 | } else { |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 475 | std::string source("delegate"); |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 476 | request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 477 | NetLog::StringCallback("source", &source)); |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 478 | NotifyCanceled(); |
[email protected] | b4438d3 | 2012-09-27 06:15:30 | [diff] [blame] | 479 | NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
| 483 | void URLRequestHttpJob::StartTransactionInternal() { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 484 | // NOTE: This method assumes that request_info_ is already setup properly. |
| 485 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 486 | // If we already have a transaction, then we should restart the transaction |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 487 | // with auth provided by auth_credentials_. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 488 | |
[email protected] | 99c0790 | 2010-08-17 18:59:52 | [diff] [blame] | 489 | int rv; |
[email protected] | 6b3f964 | 2010-11-25 02:29:06 | [diff] [blame] | 490 | |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 491 | if (network_delegate()) { |
| 492 | network_delegate()->NotifySendHeaders( |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 493 | request_, request_info_.extra_headers); |
| 494 | } |
| 495 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 496 | if (transaction_.get()) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 497 | rv = transaction_->RestartWithAuth(auth_credentials_, start_callback_); |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 498 | auth_credentials_ = AuthCredentials(); |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 499 | } else { |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 500 | DCHECK(request_->context()->http_transaction_factory()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 501 | |
[email protected] | 99c0790 | 2010-08-17 18:59:52 | [diff] [blame] | 502 | rv = request_->context()->http_transaction_factory()->CreateTransaction( |
[email protected] | 027bd85a | 2013-12-27 22:39:10 | [diff] [blame] | 503 | priority_, &transaction_); |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 504 | |
| 505 | if (rv == OK && request_info_.url.SchemeIsWSOrWSS()) { |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 506 | base::SupportsUserData::Data* data = request_->GetUserData( |
| 507 | WebSocketHandshakeStreamBase::CreateHelper::DataKey()); |
| 508 | if (data) { |
| 509 | transaction_->SetWebSocketHandshakeStreamCreateHelper( |
| 510 | static_cast<WebSocketHandshakeStreamBase::CreateHelper*>(data)); |
| 511 | } else { |
| 512 | rv = ERR_DISALLOWED_URL_SCHEME; |
| 513 | } |
| 514 | } |
| 515 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 516 | if (rv == OK) { |
[email protected] | a45840b | 2014-01-10 15:40:22 | [diff] [blame] | 517 | transaction_->SetBeforeNetworkStartCallback( |
| 518 | base::Bind(&URLRequestHttpJob::NotifyBeforeNetworkStart, |
| 519 | base::Unretained(this))); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 520 | transaction_->SetBeforeProxyHeadersSentCallback( |
| 521 | base::Bind(&URLRequestHttpJob::NotifyBeforeSendProxyHeadersCallback, |
| 522 | base::Unretained(this))); |
[email protected] | a45840b | 2014-01-10 15:40:22 | [diff] [blame] | 523 | |
dcheng | c2e01e8 | 2014-08-27 00:24:42 | [diff] [blame] | 524 | if (!throttling_entry_.get() || |
xunjieli | 41edcdd | 2015-06-24 14:26:40 | [diff] [blame] | 525 | !throttling_entry_->ShouldRejectRequest(*request_)) { |
[email protected] | 227b0e8 | 2011-03-25 21:11:53 | [diff] [blame] | 526 | rv = transaction_->Start( |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 527 | &request_info_, start_callback_, request_->net_log()); |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 528 | start_time_ = base::TimeTicks::Now(); |
[email protected] | 227b0e8 | 2011-03-25 21:11:53 | [diff] [blame] | 529 | } else { |
| 530 | // Special error code for the exponential back-off module. |
| 531 | rv = ERR_TEMPORARILY_THROTTLED; |
| 532 | } |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 533 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 534 | } |
| 535 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 536 | if (rv == ERR_IO_PENDING) |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 537 | return; |
| 538 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 539 | // The transaction started synchronously, but we need to notify the |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 540 | // URLRequest delegate via the message loop. |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 541 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 542 | FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 543 | weak_factory_.GetWeakPtr(), rv)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 544 | } |
| 545 | |
[email protected] | 175adac | 2008-07-30 17:28:04 | [diff] [blame] | 546 | void URLRequestHttpJob::AddExtraHeaders() { |
[email protected] | 6a58676 | 2014-06-15 16:02:22 | [diff] [blame] | 547 | SdchManager* sdch_manager = request()->context()->sdch_manager(); |
| 548 | |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 549 | // Supply Accept-Encoding field only if it is not already provided. |
| 550 | // It should be provided IF the content is known to have restrictions on |
| 551 | // potential encoding, such as streaming multi-media. |
| 552 | // For details see bug 47381. |
| 553 | // TODO(jar, enal): jpeg files etc. should set up a request header if |
| 554 | // possible. Right now it is done only by buffered_resource_loader and |
| 555 | // simple_data_source. |
| 556 | if (!request_info_.extra_headers.HasHeader( |
| 557 | HttpRequestHeaders::kAcceptEncoding)) { |
baranovich | c5e3865 | 2014-11-14 03:08:15 | [diff] [blame] | 558 | // We don't support SDCH responses to POST as there is a possibility |
| 559 | // of having SDCH encoded responses returned (e.g. by the cache) |
| 560 | // which we cannot decode, and in those situations, we will need |
| 561 | // to retransmit the request without SDCH, which is illegal for a POST. |
| 562 | bool advertise_sdch = sdch_manager != NULL && request()->method() != "POST"; |
| 563 | if (advertise_sdch) { |
| 564 | SdchProblemCode rv = sdch_manager->IsInSupportedDomain(request()->url()); |
| 565 | if (rv != SDCH_OK) { |
| 566 | advertise_sdch = false; |
ellyjones | 085ac46 | 2015-08-18 12:02:53 | [diff] [blame] | 567 | SdchManager::SdchErrorRecovery(rv); |
| 568 | request()->net_log().AddEvent( |
| 569 | NetLog::TYPE_SDCH_DECODING_ERROR, |
| 570 | base::Bind(&NetLogSdchResourceProblemCallback, rv)); |
baranovich | c5e3865 | 2014-11-14 03:08:15 | [diff] [blame] | 571 | } |
| 572 | } |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 573 | if (advertise_sdch) { |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 574 | dictionaries_advertised_ = |
| 575 | sdch_manager->GetDictionarySet(request_->url()); |
| 576 | } |
[email protected] | 5b90b5d | 2009-04-30 23:06:01 | [diff] [blame] | 577 | |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 578 | // The AllowLatencyExperiment() is only true if we've successfully done a |
| 579 | // full SDCH compression recently in this browser session for this host. |
| 580 | // Note that for this path, there might be no applicable dictionaries, |
| 581 | // and hence we can't participate in the experiment. |
| 582 | if (dictionaries_advertised_ && |
| 583 | sdch_manager->AllowLatencyExperiment(request_->url())) { |
| 584 | // We are participating in the test (or control), and hence we'll |
| 585 | // eventually record statistics via either SDCH_EXPERIMENT_DECODE or |
| 586 | // SDCH_EXPERIMENT_HOLDBACK, and we'll need some packet timing data. |
| 587 | packet_timing_enabled_ = true; |
| 588 | if (base::RandDouble() < .01) { |
| 589 | sdch_test_control_ = true; // 1% probability. |
| 590 | dictionaries_advertised_.reset(); |
| 591 | advertise_sdch = false; |
| 592 | } else { |
| 593 | sdch_test_activated_ = true; |
[email protected] | 5b90b5d | 2009-04-30 23:06:01 | [diff] [blame] | 594 | } |
| 595 | } |
[email protected] | 5b90b5d | 2009-04-30 23:06:01 | [diff] [blame] | 596 | |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 597 | // Supply Accept-Encoding headers first so that it is more likely that they |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 598 | // will be in the first transmitted packet. This can sometimes make it |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 599 | // easier to filter and analyze the streams to assure that a proxy has not |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 600 | // damaged these headers. Some proxies deliberately corrupt Accept-Encoding |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 601 | // headers. |
| 602 | if (!advertise_sdch) { |
| 603 | // Tell the server what compression formats we support (other than SDCH). |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 604 | request_info_.extra_headers.SetHeader( |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 605 | HttpRequestHeaders::kAcceptEncoding, "gzip, deflate"); |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 606 | } else { |
| 607 | // Include SDCH in acceptable list. |
| 608 | request_info_.extra_headers.SetHeader( |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 609 | HttpRequestHeaders::kAcceptEncoding, "gzip, deflate, sdch"); |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 610 | if (dictionaries_advertised_) { |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 611 | request_info_.extra_headers.SetHeader( |
| 612 | kAvailDictionaryHeader, |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 613 | dictionaries_advertised_->GetDictionaryClientHashList()); |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 614 | // Since we're tagging this transaction as advertising a dictionary, |
| 615 | // we'll definitely employ an SDCH filter (or tentative sdch filter) |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 616 | // when we get a response. When done, we'll record histograms via |
| 617 | // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet |
[email protected] | c7bef94c | 2011-06-21 18:05:51 | [diff] [blame] | 618 | // arrival times. |
| 619 | packet_timing_enabled_ = true; |
| 620 | } |
[email protected] | 423041b | 2008-10-27 17:39:28 | [diff] [blame] | 621 | } |
[email protected] | 423041b | 2008-10-27 17:39:28 | [diff] [blame] | 622 | } |
| 623 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 624 | if (http_user_agent_settings_) { |
[email protected] | 84f0543 | 2013-03-15 01:00:12 | [diff] [blame] | 625 | // Only add default Accept-Language if the request didn't have it |
| 626 | // specified. |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 627 | std::string accept_language = |
| 628 | http_user_agent_settings_->GetAcceptLanguage(); |
| 629 | if (!accept_language.empty()) { |
| 630 | request_info_.extra_headers.SetHeaderIfMissing( |
| 631 | HttpRequestHeaders::kAcceptLanguage, |
| 632 | accept_language); |
| 633 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 634 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 635 | } |
| 636 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 637 | void URLRequestHttpJob::AddCookieHeaderAndStart() { |
| 638 | // No matter what, we want to report our status as IO pending since we will |
| 639 | // be notifying our consumer asynchronously via OnStartCompleted. |
| 640 | SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 641 | |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 642 | // If the request was destroyed, then there is no more work to do. |
| 643 | if (!request_) |
| 644 | return; |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 645 | |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 646 | CookieStore* cookie_store = request_->context()->cookie_store(); |
[email protected] | 1a6fff5 | 2011-10-20 21:00:16 | [diff] [blame] | 647 | if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { |
[email protected] | dc8313a | 2014-03-24 21:38:14 | [diff] [blame] | 648 | cookie_store->GetAllCookiesForURLAsync( |
| 649 | request_->url(), |
| 650 | base::Bind(&URLRequestHttpJob::CheckCookiePolicyAndLoad, |
| 651 | weak_factory_.GetWeakPtr())); |
[email protected] | 03d845f | 2011-07-29 19:06:26 | [diff] [blame] | 652 | } else { |
| 653 | DoStartTransaction(); |
| 654 | } |
| 655 | } |
| 656 | |
[email protected] | 1a6fff5 | 2011-10-20 21:00:16 | [diff] [blame] | 657 | void URLRequestHttpJob::DoLoadCookies() { |
| 658 | CookieOptions options; |
| 659 | options.set_include_httponly(); |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 660 | |
| 661 | // TODO(mkwst): Drop this `if` once we decide whether or not to ship |
| 662 | // first-party cookies: https://crbug.com/459154 |
| 663 | if (network_delegate() && |
| 664 | network_delegate()->FirstPartyOnlyCookieExperimentEnabled()) |
| 665 | options.set_first_party_url(request_->first_party_for_cookies()); |
| 666 | else |
| 667 | options.set_include_first_party_only(); |
mkwst | ae819bb | 2015-02-23 05:10:31 | [diff] [blame] | 668 | |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 669 | request_->context()->cookie_store()->GetCookiesWithOptionsAsync( |
| 670 | request_->url(), options, base::Bind(&URLRequestHttpJob::OnCookiesLoaded, |
| 671 | weak_factory_.GetWeakPtr())); |
[email protected] | 1a6fff5 | 2011-10-20 21:00:16 | [diff] [blame] | 672 | } |
| 673 | |
[email protected] | 03d845f | 2011-07-29 19:06:26 | [diff] [blame] | 674 | void URLRequestHttpJob::CheckCookiePolicyAndLoad( |
| 675 | const CookieList& cookie_list) { |
[email protected] | 1a6fff5 | 2011-10-20 21:00:16 | [diff] [blame] | 676 | if (CanGetCookies(cookie_list)) |
| 677 | DoLoadCookies(); |
| 678 | else |
[email protected] | 54f4c936 | 2011-07-25 21:54:46 | [diff] [blame] | 679 | DoStartTransaction(); |
[email protected] | 54f4c936 | 2011-07-25 21:54:46 | [diff] [blame] | 680 | } |
| 681 | |
[email protected] | dedec0b | 2013-02-28 04:50:10 | [diff] [blame] | 682 | void URLRequestHttpJob::OnCookiesLoaded(const std::string& cookie_line) { |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 683 | if (!cookie_line.empty()) { |
[email protected] | 54f4c936 | 2011-07-25 21:54:46 | [diff] [blame] | 684 | request_info_.extra_headers.SetHeader( |
[email protected] | 218aa6a1 | 2011-09-13 17:38:38 | [diff] [blame] | 685 | HttpRequestHeaders::kCookie, cookie_line); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 686 | // Disable privacy mode as we are sending cookies anyway. |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 687 | request_info_.privacy_mode = PRIVACY_MODE_DISABLED; |
[email protected] | 54f4c936 | 2011-07-25 21:54:46 | [diff] [blame] | 688 | } |
[email protected] | 54f4c936 | 2011-07-25 21:54:46 | [diff] [blame] | 689 | DoStartTransaction(); |
| 690 | } |
| 691 | |
| 692 | void URLRequestHttpJob::DoStartTransaction() { |
[email protected] | 03d845f | 2011-07-29 19:06:26 | [diff] [blame] | 693 | // We may have been canceled while retrieving cookies. |
[email protected] | 9025016c | 2011-05-12 15:51:23 | [diff] [blame] | 694 | if (GetStatus().is_success()) { |
| 695 | StartTransaction(); |
| 696 | } else { |
| 697 | NotifyCanceled(); |
| 698 | } |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 699 | } |
| 700 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 701 | void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete(int result) { |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 702 | // End of the call started in OnStartCompleted. |
| 703 | OnCallToDelegateComplete(); |
| 704 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 705 | if (result != OK) { |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 706 | std::string source("delegate"); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 707 | request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 708 | NetLog::StringCallback("source", &source)); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 709 | NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 710 | return; |
| 711 | } |
| 712 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 713 | DCHECK(transaction_.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 714 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 715 | const HttpResponseInfo* response_info = transaction_->GetResponseInfo(); |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 716 | DCHECK(response_info); |
| 717 | |
| 718 | response_cookies_.clear(); |
| 719 | response_cookies_save_index_ = 0; |
| 720 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 721 | FetchResponseCookies(&response_cookies_); |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 722 | |
[email protected] | 5095cd7 | 2012-11-01 10:29:16 | [diff] [blame] | 723 | if (!GetResponseHeaders()->GetDateValue(&response_date_)) |
| 724 | response_date_ = base::Time(); |
| 725 | |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 726 | // Now, loop over the response cookies, and attempt to persist each. |
| 727 | SaveNextCookie(); |
| 728 | } |
| 729 | |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 730 | // If the save occurs synchronously, SaveNextCookie will loop and save the next |
| 731 | // cookie. If the save is deferred, the callback is responsible for continuing |
| 732 | // to iterate through the cookies. |
| 733 | // TODO(erikwright): Modify the CookieStore API to indicate via return value |
| 734 | // whether it completed synchronously or asynchronously. |
| 735 | // See http://crbug.com/131066. |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 736 | void URLRequestHttpJob::SaveNextCookie() { |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 737 | // No matter what, we want to report our status as IO pending since we will |
| 738 | // be notifying our consumer asynchronously via OnStartCompleted. |
| 739 | SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 740 | |
| 741 | // Used to communicate with the callback. See the implementation of |
| 742 | // OnCookieSaved. |
| 743 | scoped_refptr<SharedBoolean> callback_pending = new SharedBoolean(false); |
| 744 | scoped_refptr<SharedBoolean> save_next_cookie_running = |
| 745 | new SharedBoolean(true); |
| 746 | |
| 747 | if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 748 | request_->context()->cookie_store() && response_cookies_.size() > 0) { |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 749 | CookieOptions options; |
| 750 | options.set_include_httponly(); |
[email protected] | 5095cd7 | 2012-11-01 10:29:16 | [diff] [blame] | 751 | options.set_server_time(response_date_); |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 752 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 753 | CookieStore::SetCookiesCallback callback(base::Bind( |
| 754 | &URLRequestHttpJob::OnCookieSaved, weak_factory_.GetWeakPtr(), |
| 755 | save_next_cookie_running, callback_pending)); |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 756 | |
| 757 | // Loop through the cookies as long as SetCookieWithOptionsAsync completes |
| 758 | // synchronously. |
| 759 | while (!callback_pending->data && |
| 760 | response_cookies_save_index_ < response_cookies_.size()) { |
| 761 | if (CanSetCookie( |
| 762 | response_cookies_[response_cookies_save_index_], &options)) { |
| 763 | callback_pending->data = true; |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 764 | request_->context()->cookie_store()->SetCookieWithOptionsAsync( |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 765 | request_->url(), response_cookies_[response_cookies_save_index_], |
| 766 | options, callback); |
| 767 | } |
| 768 | ++response_cookies_save_index_; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | save_next_cookie_running->data = false; |
| 773 | |
| 774 | if (!callback_pending->data) { |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 775 | response_cookies_.clear(); |
| 776 | response_cookies_save_index_ = 0; |
| 777 | SetStatus(URLRequestStatus()); // Clear the IO_PENDING status |
| 778 | NotifyHeadersComplete(); |
| 779 | return; |
| 780 | } |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 781 | } |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 782 | |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 783 | // |save_next_cookie_running| is true when the callback is bound and set to |
| 784 | // false when SaveNextCookie exits, allowing the callback to determine if the |
| 785 | // save occurred synchronously or asynchronously. |
| 786 | // |callback_pending| is false when the callback is invoked and will be set to |
| 787 | // true by the callback, allowing SaveNextCookie to detect whether the save |
| 788 | // occurred synchronously. |
| 789 | // See SaveNextCookie() for more information. |
| 790 | void URLRequestHttpJob::OnCookieSaved( |
| 791 | scoped_refptr<SharedBoolean> save_next_cookie_running, |
| 792 | scoped_refptr<SharedBoolean> callback_pending, |
| 793 | bool cookie_status) { |
| 794 | callback_pending->data = false; |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 795 | |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 796 | // If we were called synchronously, return. |
| 797 | if (save_next_cookie_running->data) { |
| 798 | return; |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 799 | } |
| 800 | |
[email protected] | 263163f | 2012-06-14 22:40:34 | [diff] [blame] | 801 | // We were called asynchronously, so trigger the next save. |
[email protected] | 9025016c | 2011-05-12 15:51:23 | [diff] [blame] | 802 | // We may have been canceled within OnSetCookie. |
| 803 | if (GetStatus().is_success()) { |
| 804 | SaveNextCookie(); |
| 805 | } else { |
| 806 | NotifyCanceled(); |
| 807 | } |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | void URLRequestHttpJob::FetchResponseCookies( |
[email protected] | 3460228 | 2010-02-03 22:14:15 | [diff] [blame] | 811 | std::vector<std::string>* cookies) { |
[email protected] | 26430024 | 2011-11-07 06:03:30 | [diff] [blame] | 812 | const std::string name = "Set-Cookie"; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 813 | std::string value; |
| 814 | |
| 815 | void* iter = NULL; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 816 | HttpResponseHeaders* headers = GetResponseHeaders(); |
| 817 | while (headers->EnumerateHeader(&iter, name, &value)) { |
[email protected] | 2adf288 | 2010-09-27 08:30:37 | [diff] [blame] | 818 | if (!value.empty()) |
| 819 | cookies->push_back(value); |
| 820 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 821 | } |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 822 | |
xunjieli | 3bb781a | 2015-07-22 22:40:34 | [diff] [blame] | 823 | void URLRequestHttpJob::ProcessBackoffHeader() { |
| 824 | DCHECK(response_info_); |
| 825 | |
| 826 | if (!backoff_manager_) |
| 827 | return; |
| 828 | |
| 829 | TransportSecurityState* security_state = |
| 830 | request_->context()->transport_security_state(); |
| 831 | const SSLInfo& ssl_info = response_info_->ssl_info; |
| 832 | |
| 833 | // Only accept Backoff headers on HTTPS connections that have no |
| 834 | // certificate errors. |
| 835 | if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
| 836 | !security_state) |
| 837 | return; |
| 838 | |
| 839 | backoff_manager_->UpdateWithResponse(request()->url(), GetResponseHeaders(), |
| 840 | base::Time::Now()); |
| 841 | } |
| 842 | |
[email protected] | 000d9df0 | 2012-01-18 20:01:46 | [diff] [blame] | 843 | // NOTE: |ProcessStrictTransportSecurityHeader| and |
| 844 | // |ProcessPublicKeyPinsHeader| have very similar structures, by design. |
[email protected] | 77f6fb43 | 2009-09-05 14:21:09 | [diff] [blame] | 845 | void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 846 | DCHECK(response_info_); |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 847 | TransportSecurityState* security_state = |
| 848 | request_->context()->transport_security_state(); |
[email protected] | e88006f | 2012-01-11 06:15:07 | [diff] [blame] | 849 | const SSLInfo& ssl_info = response_info_->ssl_info; |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 850 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 851 | // Only accept HSTS headers on HTTPS connections that have no |
| 852 | // certificate errors. |
[email protected] | e88006f | 2012-01-11 06:15:07 | [diff] [blame] | 853 | if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 854 | !security_state) |
[email protected] | e88006f | 2012-01-11 06:15:07 | [diff] [blame] | 855 | return; |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 856 | |
estark | a5da7670 | 2015-04-09 04:00:16 | [diff] [blame] | 857 | // Don't accept HSTS headers when the hostname is an IP address. |
| 858 | if (request_info_.url.HostIsIPAddress()) |
| 859 | return; |
| 860 | |
[email protected] | 242d856 | 2012-10-30 21:20:46 | [diff] [blame] | 861 | // http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec: |
| 862 | // |
| 863 | // If a UA receives more than one STS header field in a HTTP response |
| 864 | // message over secure transport, then the UA MUST process only the |
| 865 | // first such header field. |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 866 | HttpResponseHeaders* headers = GetResponseHeaders(); |
| 867 | std::string value; |
| 868 | if (headers->EnumerateHeader(NULL, "Strict-Transport-Security", &value)) |
| 869 | security_state->AddHSTSHeader(request_info_.url.host(), value); |
[email protected] | a9cea754 | 2009-05-20 04:30:23 | [diff] [blame] | 870 | } |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 871 | |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 872 | void URLRequestHttpJob::ProcessPublicKeyPinsHeader() { |
| 873 | DCHECK(response_info_); |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 874 | TransportSecurityState* security_state = |
| 875 | request_->context()->transport_security_state(); |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 876 | const SSLInfo& ssl_info = response_info_->ssl_info; |
| 877 | |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 878 | // Only accept HPKP headers on HTTPS connections that have no |
[email protected] | e88006f | 2012-01-11 06:15:07 | [diff] [blame] | 879 | // certificate errors. |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 880 | if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 881 | !security_state) |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 882 | return; |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 883 | |
estark | a5da7670 | 2015-04-09 04:00:16 | [diff] [blame] | 884 | // Don't accept HSTS headers when the hostname is an IP address. |
| 885 | if (request_info_.url.HostIsIPAddress()) |
| 886 | return; |
| 887 | |
estark | 53fee7c | 2015-08-03 18:31:51 | [diff] [blame] | 888 | // http://tools.ietf.org/html/rfc7469: |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 889 | // |
| 890 | // If a UA receives more than one PKP header field in an HTTP |
| 891 | // response message over secure transport, then the UA MUST process |
| 892 | // only the first such header field. |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 893 | HttpResponseHeaders* headers = GetResponseHeaders(); |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 894 | std::string value; |
estark | 53fee7c | 2015-08-03 18:31:51 | [diff] [blame] | 895 | if (headers->EnumerateHeader(nullptr, "Public-Key-Pins", &value)) |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 896 | security_state->AddHPKPHeader(request_info_.url.host(), value, ssl_info); |
estark | 53fee7c | 2015-08-03 18:31:51 | [diff] [blame] | 897 | if (headers->EnumerateHeader(nullptr, "Public-Key-Pins-Report-Only", |
| 898 | &value)) { |
| 899 | security_state->ProcessHPKPReportOnlyHeader( |
| 900 | value, HostPortPair::FromURL(request_info_.url), ssl_info); |
| 901 | } |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 902 | } |
| 903 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 904 | void URLRequestHttpJob::OnStartCompleted(int result) { |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 905 | RecordTimer(); |
| 906 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 907 | // If the request was destroyed, then there is no more work to do. |
[email protected] | a83dd33 | 2011-07-13 10:41:01 | [diff] [blame] | 908 | if (!request_) |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 909 | return; |
| 910 | |
[email protected] | 80abdad | 2014-03-15 00:20:54 | [diff] [blame] | 911 | // If the job is done (due to cancellation), can just ignore this |
| 912 | // notification. |
| 913 | if (done_) |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 914 | return; |
| 915 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 916 | receive_headers_end_ = base::TimeTicks::Now(); |
| 917 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 918 | // Clear the IO_PENDING status |
| 919 | SetStatus(URLRequestStatus()); |
| 920 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 921 | const URLRequestContext* context = request_->context(); |
| 922 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 923 | if (result == OK) { |
[email protected] | d8fc472 | 2014-06-13 13:17:15 | [diff] [blame] | 924 | if (transaction_ && transaction_->GetResponseInfo()) { |
| 925 | SetProxyServer(transaction_->GetResponseInfo()->proxy_server); |
| 926 | } |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 927 | scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 928 | if (network_delegate()) { |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 929 | // Note that |this| may not be deleted until |
| 930 | // |on_headers_received_callback_| or |
| 931 | // |NetworkDelegate::URLRequestDestroyed()| has been called. |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 932 | OnCallToDelegate(); |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 933 | allowed_unsafe_redirect_url_ = GURL(); |
[email protected] | cc05edc | 2013-03-08 18:04:41 | [diff] [blame] | 934 | int error = network_delegate()->NotifyHeadersReceived( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 935 | request_, |
| 936 | on_headers_received_callback_, |
| 937 | headers.get(), |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 938 | &override_response_headers_, |
| 939 | &allowed_unsafe_redirect_url_); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 940 | if (error != OK) { |
| 941 | if (error == ERR_IO_PENDING) { |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 942 | awaiting_callback_ = true; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 943 | } else { |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 944 | std::string source("delegate"); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 945 | request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, |
[email protected] | 55b8a6c1 | 2012-06-13 22:03:42 | [diff] [blame] | 946 | NetLog::StringCallback("source", |
| 947 | &source)); |
[email protected] | abe1c4a | 2013-10-25 19:28:51 | [diff] [blame] | 948 | OnCallToDelegateComplete(); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 949 | NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, error)); |
| 950 | } |
| 951 | return; |
| 952 | } |
| 953 | } |
| 954 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 955 | SaveCookiesAndNotifyHeadersComplete(OK); |
[email protected] | e5624f0 | 2011-09-27 19:43:53 | [diff] [blame] | 956 | } else if (IsCertificateError(result)) { |
[email protected] | 6061c14 | 2013-10-21 15:13:34 | [diff] [blame] | 957 | // We encountered an SSL certificate error. |
| 958 | if (result == ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY || |
| 959 | result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN) { |
| 960 | // These are hard failures. They're handled separately and don't have |
| 961 | // the correct cert status, so set it here. |
| 962 | SSLInfo info(transaction_->GetResponseInfo()->ssl_info); |
| 963 | info.cert_status = MapNetErrorToCertStatus(result); |
| 964 | NotifySSLCertificateError(info, true); |
| 965 | } else { |
| 966 | // Maybe overridable, maybe not. Ask the delegate to decide. |
[email protected] | 9e6968d | 2014-05-07 21:46:26 | [diff] [blame] | 967 | TransportSecurityState* state = context->transport_security_state(); |
| 968 | const bool fatal = |
Adam Langley | 5cbb7d7a | 2014-09-25 23:14:12 | [diff] [blame] | 969 | state && state->ShouldSSLErrorsBeFatal(request_info_.url.host()); |
[email protected] | 6061c14 | 2013-10-21 15:13:34 | [diff] [blame] | 970 | NotifySSLCertificateError( |
| 971 | transaction_->GetResponseInfo()->ssl_info, fatal); |
| 972 | } |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 973 | } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
[email protected] | a83dd33 | 2011-07-13 10:41:01 | [diff] [blame] | 974 | NotifyCertificateRequested( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 975 | transaction_->GetResponseInfo()->cert_request_info.get()); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 976 | } else { |
[email protected] | 419704c | 2014-01-14 11:18:06 | [diff] [blame] | 977 | // Even on an error, there may be useful information in the response |
| 978 | // info (e.g. whether there's a cached copy). |
| 979 | if (transaction_.get()) |
| 980 | response_info_ = transaction_->GetResponseInfo(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 981 | NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 982 | } |
| 983 | } |
| 984 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 985 | void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 986 | awaiting_callback_ = false; |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 987 | |
| 988 | // Check that there are no callbacks to already canceled requests. |
| 989 | DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); |
| 990 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 991 | SaveCookiesAndNotifyHeadersComplete(result); |
| 992 | } |
| 993 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 994 | void URLRequestHttpJob::OnReadCompleted(int result) { |
| 995 | read_in_progress_ = false; |
| 996 | |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 997 | if (ShouldFixMismatchedContentLength(result)) |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 998 | result = OK; |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 999 | |
[email protected] | 5543cbb | 2012-04-20 16:35:23 | [diff] [blame] | 1000 | if (result == OK) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1001 | NotifyDone(URLRequestStatus()); |
| 1002 | } else if (result < 0) { |
| 1003 | NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 1004 | } else { |
| 1005 | // Clear the IO_PENDING status |
| 1006 | SetStatus(URLRequestStatus()); |
| 1007 | } |
| 1008 | |
| 1009 | NotifyReadComplete(result); |
| 1010 | } |
| 1011 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1012 | void URLRequestHttpJob::RestartTransactionWithAuth( |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 1013 | const AuthCredentials& credentials) { |
| 1014 | auth_credentials_ = credentials; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1015 | |
| 1016 | // These will be reset in OnStartCompleted. |
| 1017 | response_info_ = NULL; |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1018 | receive_headers_end_ = base::TimeTicks(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1019 | response_cookies_.clear(); |
| 1020 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1021 | ResetTimer(); |
| 1022 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1023 | // Update the cookies, since the cookie store may have been updated from the |
| 1024 | // headers in the 401/407. Since cookies were already appended to |
| 1025 | // extra_headers, we need to strip them out before adding them again. |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1026 | request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kCookie); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1027 | |
| 1028 | AddCookieHeaderAndStart(); |
| 1029 | } |
| 1030 | |
[email protected] | 0736d9e | 2012-11-28 19:50:40 | [diff] [blame] | 1031 | void URLRequestHttpJob::SetUpload(UploadDataStream* upload) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1032 | DCHECK(!transaction_.get()) << "cannot change once started"; |
[email protected] | 0736d9e | 2012-11-28 19:50:40 | [diff] [blame] | 1033 | request_info_.upload_data_stream = upload; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | void URLRequestHttpJob::SetExtraRequestHeaders( |
| 1037 | const HttpRequestHeaders& headers) { |
| 1038 | DCHECK(!transaction_.get()) << "cannot change once started"; |
| 1039 | request_info_.extra_headers.CopyFrom(headers); |
| 1040 | } |
| 1041 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1042 | LoadState URLRequestHttpJob::GetLoadState() const { |
| 1043 | return transaction_.get() ? |
| 1044 | transaction_->GetLoadState() : LOAD_STATE_IDLE; |
| 1045 | } |
| 1046 | |
[email protected] | 7335ab0 | 2012-08-30 22:30:42 | [diff] [blame] | 1047 | UploadProgress URLRequestHttpJob::GetUploadProgress() const { |
| 1048 | return transaction_.get() ? |
| 1049 | transaction_->GetUploadProgress() : UploadProgress(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | bool URLRequestHttpJob::GetMimeType(std::string* mime_type) const { |
| 1053 | DCHECK(transaction_.get()); |
| 1054 | |
| 1055 | if (!response_info_) |
| 1056 | return false; |
| 1057 | |
ellyjones | 0e9d5e8 | 2015-02-17 23:06:28 | [diff] [blame] | 1058 | HttpResponseHeaders* headers = GetResponseHeaders(); |
| 1059 | if (!headers) |
| 1060 | return false; |
| 1061 | return headers->GetMimeType(mime_type); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | bool URLRequestHttpJob::GetCharset(std::string* charset) { |
| 1065 | DCHECK(transaction_.get()); |
| 1066 | |
| 1067 | if (!response_info_) |
| 1068 | return false; |
| 1069 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1070 | return GetResponseHeaders()->GetCharset(charset); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | void URLRequestHttpJob::GetResponseInfo(HttpResponseInfo* info) { |
| 1074 | DCHECK(request_); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1075 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1076 | if (response_info_) { |
[email protected] | 419704c | 2014-01-14 11:18:06 | [diff] [blame] | 1077 | DCHECK(transaction_.get()); |
| 1078 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1079 | *info = *response_info_; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1080 | if (override_response_headers_.get()) |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1081 | info->headers = override_response_headers_; |
| 1082 | } |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1083 | } |
| 1084 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1085 | void URLRequestHttpJob::GetLoadTimingInfo( |
| 1086 | LoadTimingInfo* load_timing_info) const { |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1087 | // If haven't made it far enough to receive any headers, don't return |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 1088 | // anything. This makes for more consistent behavior in the case of errors. |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1089 | if (!transaction_ || receive_headers_end_.is_null()) |
| 1090 | return; |
| 1091 | if (transaction_->GetLoadTimingInfo(load_timing_info)) |
| 1092 | load_timing_info->receive_headers_end = receive_headers_end_; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1093 | } |
| 1094 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame^] | 1095 | bool URLRequestHttpJob::GetRemoteEndpoint(IPEndPoint* endpoint) const { |
| 1096 | if (!transaction_) |
| 1097 | return false; |
| 1098 | |
| 1099 | return transaction_->GetRemoteEndpoint(endpoint); |
| 1100 | } |
| 1101 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1102 | bool URLRequestHttpJob::GetResponseCookies(std::vector<std::string>* cookies) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1103 | DCHECK(transaction_.get()); |
| 1104 | |
| 1105 | if (!response_info_) |
| 1106 | return false; |
| 1107 | |
| 1108 | // TODO(darin): Why are we extracting response cookies again? Perhaps we |
| 1109 | // should just leverage response_cookies_. |
| 1110 | |
| 1111 | cookies->clear(); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1112 | FetchResponseCookies(cookies); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1113 | return true; |
| 1114 | } |
| 1115 | |
| 1116 | int URLRequestHttpJob::GetResponseCode() const { |
| 1117 | DCHECK(transaction_.get()); |
| 1118 | |
| 1119 | if (!response_info_) |
| 1120 | return -1; |
| 1121 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1122 | return GetResponseHeaders()->response_code(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1123 | } |
| 1124 | |
[email protected] | 5a3b4d3 | 2011-03-17 01:24:05 | [diff] [blame] | 1125 | Filter* URLRequestHttpJob::SetupFilter() const { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1126 | DCHECK(transaction_.get()); |
| 1127 | if (!response_info_) |
[email protected] | 5a3b4d3 | 2011-03-17 01:24:05 | [diff] [blame] | 1128 | return NULL; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1129 | |
[email protected] | 5a3b4d3 | 2011-03-17 01:24:05 | [diff] [blame] | 1130 | std::vector<Filter::FilterType> encoding_types; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1131 | std::string encoding_type; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1132 | HttpResponseHeaders* headers = GetResponseHeaders(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1133 | void* iter = NULL; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1134 | while (headers->EnumerateHeader(&iter, "Content-Encoding", &encoding_type)) { |
[email protected] | 5a3b4d3 | 2011-03-17 01:24:05 | [diff] [blame] | 1135 | encoding_types.push_back(Filter::ConvertEncodingToType(encoding_type)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | // Even if encoding types are empty, there is a chance that we need to add |
| 1139 | // some decoding, as some proxies strip encoding completely. In such cases, |
| 1140 | // we may need to add (for example) SDCH filtering (when the context suggests |
| 1141 | // it is appropriate). |
[email protected] | 2e92354c | 2011-03-25 20:49:53 | [diff] [blame] | 1142 | Filter::FixupEncodingTypes(*filter_context_, &encoding_types); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1143 | |
[email protected] | 5a3b4d3 | 2011-03-17 01:24:05 | [diff] [blame] | 1144 | return !encoding_types.empty() |
[email protected] | 2e92354c | 2011-03-25 20:49:53 | [diff] [blame] | 1145 | ? Filter::Factory(encoding_types, *filter_context_) : NULL; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1146 | } |
| 1147 | |
[email protected] | f878230e | 2014-04-03 15:36:14 | [diff] [blame] | 1148 | bool URLRequestHttpJob::CopyFragmentOnRedirect(const GURL& location) const { |
| 1149 | // Allow modification of reference fragments by default, unless |
| 1150 | // |allowed_unsafe_redirect_url_| is set and equal to the redirect URL. |
| 1151 | // When this is the case, we assume that the network delegate has set the |
| 1152 | // desired redirect URL (with or without fragment), so it must not be changed |
| 1153 | // any more. |
| 1154 | return !allowed_unsafe_redirect_url_.is_valid() || |
| 1155 | allowed_unsafe_redirect_url_ != location; |
| 1156 | } |
| 1157 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1158 | bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) { |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 1159 | // HTTP is always safe. |
| 1160 | // TODO(pauljensen): Remove once crbug.com/146591 is fixed. |
| 1161 | if (location.is_valid() && |
| 1162 | (location.scheme() == "http" || location.scheme() == "https")) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1163 | return true; |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1164 | } |
[email protected] | f878230e | 2014-04-03 15:36:14 | [diff] [blame] | 1165 | // Delegates may mark a URL as safe for redirection. |
| 1166 | if (allowed_unsafe_redirect_url_.is_valid() && |
| 1167 | allowed_unsafe_redirect_url_ == location) { |
| 1168 | return true; |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 1169 | } |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 1170 | // Query URLRequestJobFactory as to whether |location| would be safe to |
| 1171 | // redirect to. |
| 1172 | return request_->context()->job_factory() && |
| 1173 | request_->context()->job_factory()->IsSafeRedirectTarget(location); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | bool URLRequestHttpJob::NeedsAuth() { |
| 1177 | int code = GetResponseCode(); |
| 1178 | if (code == -1) |
| 1179 | return false; |
| 1180 | |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 1181 | // Check if we need either Proxy or WWW Authentication. This could happen |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1182 | // because we either provided no auth info, or provided incorrect info. |
| 1183 | switch (code) { |
| 1184 | case 407: |
| 1185 | if (proxy_auth_state_ == AUTH_STATE_CANCELED) |
| 1186 | return false; |
| 1187 | proxy_auth_state_ = AUTH_STATE_NEED_AUTH; |
| 1188 | return true; |
| 1189 | case 401: |
| 1190 | if (server_auth_state_ == AUTH_STATE_CANCELED) |
| 1191 | return false; |
| 1192 | server_auth_state_ = AUTH_STATE_NEED_AUTH; |
| 1193 | return true; |
| 1194 | } |
| 1195 | return false; |
| 1196 | } |
| 1197 | |
| 1198 | void URLRequestHttpJob::GetAuthChallengeInfo( |
| 1199 | scoped_refptr<AuthChallengeInfo>* result) { |
| 1200 | DCHECK(transaction_.get()); |
| 1201 | DCHECK(response_info_); |
| 1202 | |
| 1203 | // sanity checks: |
| 1204 | DCHECK(proxy_auth_state_ == AUTH_STATE_NEED_AUTH || |
| 1205 | server_auth_state_ == AUTH_STATE_NEED_AUTH); |
[email protected] | 9094b60 | 2012-02-27 21:44:58 | [diff] [blame] | 1206 | DCHECK((GetResponseHeaders()->response_code() == HTTP_UNAUTHORIZED) || |
| 1207 | (GetResponseHeaders()->response_code() == |
| 1208 | HTTP_PROXY_AUTHENTICATION_REQUIRED)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1209 | |
| 1210 | *result = response_info_->auth_challenge; |
| 1211 | } |
| 1212 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 1213 | void URLRequestHttpJob::SetAuth(const AuthCredentials& credentials) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1214 | DCHECK(transaction_.get()); |
| 1215 | |
| 1216 | // Proxy gets set first, then WWW. |
| 1217 | if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { |
| 1218 | proxy_auth_state_ = AUTH_STATE_HAVE_AUTH; |
| 1219 | } else { |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1220 | DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1221 | server_auth_state_ = AUTH_STATE_HAVE_AUTH; |
| 1222 | } |
| 1223 | |
[email protected] | f3cf980 | 2011-10-28 18:44:58 | [diff] [blame] | 1224 | RestartTransactionWithAuth(credentials); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | void URLRequestHttpJob::CancelAuth() { |
| 1228 | // Proxy gets set first, then WWW. |
| 1229 | if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { |
| 1230 | proxy_auth_state_ = AUTH_STATE_CANCELED; |
| 1231 | } else { |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1232 | DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1233 | server_auth_state_ = AUTH_STATE_CANCELED; |
| 1234 | } |
| 1235 | |
| 1236 | // These will be reset in OnStartCompleted. |
| 1237 | response_info_ = NULL; |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1238 | receive_headers_end_ = base::TimeTicks::Now(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1239 | response_cookies_.clear(); |
| 1240 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1241 | ResetTimer(); |
| 1242 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1243 | // OK, let the consumer read the error page... |
| 1244 | // |
| 1245 | // Because we set the AUTH_STATE_CANCELED flag, NeedsAuth will return false, |
| 1246 | // which will cause the consumer to receive OnResponseStarted instead of |
| 1247 | // OnAuthRequired. |
| 1248 | // |
| 1249 | // We have to do this via InvokeLater to avoid "recursing" the consumer. |
| 1250 | // |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 1251 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1252 | FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 1253 | weak_factory_.GetWeakPtr(), OK)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | void URLRequestHttpJob::ContinueWithCertificate( |
| 1257 | X509Certificate* client_cert) { |
| 1258 | DCHECK(transaction_.get()); |
| 1259 | |
| 1260 | DCHECK(!response_info_) << "should not have a response yet"; |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1261 | receive_headers_end_ = base::TimeTicks(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1262 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1263 | ResetTimer(); |
| 1264 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1265 | // No matter what, we want to report our status as IO pending since we will |
| 1266 | // be notifying our consumer asynchronously via OnStartCompleted. |
| 1267 | SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 1268 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1269 | int rv = transaction_->RestartWithCertificate(client_cert, start_callback_); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1270 | if (rv == ERR_IO_PENDING) |
| 1271 | return; |
| 1272 | |
| 1273 | // The transaction started synchronously, but we need to notify the |
| 1274 | // URLRequest delegate via the message loop. |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 1275 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1276 | FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 1277 | weak_factory_.GetWeakPtr(), rv)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | void URLRequestHttpJob::ContinueDespiteLastError() { |
| 1281 | // If the transaction was destroyed, then the job was cancelled. |
| 1282 | if (!transaction_.get()) |
| 1283 | return; |
| 1284 | |
| 1285 | DCHECK(!response_info_) << "should not have a response yet"; |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 1286 | receive_headers_end_ = base::TimeTicks(); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1287 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1288 | ResetTimer(); |
| 1289 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1290 | // No matter what, we want to report our status as IO pending since we will |
| 1291 | // be notifying our consumer asynchronously via OnStartCompleted. |
| 1292 | SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 1293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1294 | int rv = transaction_->RestartIgnoringLastError(start_callback_); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1295 | if (rv == ERR_IO_PENDING) |
| 1296 | return; |
| 1297 | |
| 1298 | // The transaction started synchronously, but we need to notify the |
| 1299 | // URLRequest delegate via the message loop. |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 1300 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1301 | FROM_HERE, base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 1302 | weak_factory_.GetWeakPtr(), rv)); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1303 | } |
| 1304 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1305 | void URLRequestHttpJob::ResumeNetworkStart() { |
| 1306 | DCHECK(transaction_.get()); |
| 1307 | transaction_->ResumeNetworkStart(); |
| 1308 | } |
| 1309 | |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1310 | bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const { |
| 1311 | // Some servers send the body compressed, but specify the content length as |
rdsmith | 81f60756 | 2014-11-21 18:35:16 | [diff] [blame] | 1312 | // the uncompressed size. Although this violates the HTTP spec we want to |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1313 | // support it (as IE and FireFox do), but *only* for an exact match. |
| 1314 | // See http://crbug.com/79694. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 1315 | if (rv == ERR_CONTENT_LENGTH_MISMATCH || |
| 1316 | rv == ERR_INCOMPLETE_CHUNKED_ENCODING) { |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1317 | if (request_ && request_->response_headers()) { |
| 1318 | int64 expected_length = request_->response_headers()->GetContentLength(); |
| 1319 | VLOG(1) << __FUNCTION__ << "() " |
| 1320 | << "\"" << request_->url().spec() << "\"" |
| 1321 | << " content-length = " << expected_length |
| 1322 | << " pre total = " << prefilter_bytes_read() |
| 1323 | << " post total = " << postfilter_bytes_read(); |
| 1324 | if (postfilter_bytes_read() == expected_length) { |
| 1325 | // Clear the error. |
| 1326 | return true; |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | return false; |
| 1331 | } |
| 1332 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1333 | bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size, |
[email protected] | b799645 | 2011-10-31 19:30:56 | [diff] [blame] | 1334 | int* bytes_read) { |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1335 | DCHECK_NE(buf_size, 0); |
| 1336 | DCHECK(bytes_read); |
| 1337 | DCHECK(!read_in_progress_); |
| 1338 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1339 | int rv = transaction_->Read( |
| 1340 | buf, buf_size, |
| 1341 | base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); |
[email protected] | 85c1dce | 2011-07-06 12:01:29 | [diff] [blame] | 1342 | |
[email protected] | f001bd6a | 2011-12-08 04:31:37 | [diff] [blame] | 1343 | if (ShouldFixMismatchedContentLength(rv)) |
| 1344 | rv = 0; |
| 1345 | |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1346 | if (rv >= 0) { |
| 1347 | *bytes_read = rv; |
pkasting | 941842c | 2015-04-11 01:51:30 | [diff] [blame] | 1348 | if (!rv) |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1349 | DoneWithRequest(FINISHED); |
[email protected] | 5394e42 | 2011-01-20 22:07:43 | [diff] [blame] | 1350 | return true; |
| 1351 | } |
| 1352 | |
| 1353 | if (rv == ERR_IO_PENDING) { |
| 1354 | read_in_progress_ = true; |
| 1355 | SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 1356 | } else { |
| 1357 | NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 1358 | } |
| 1359 | |
| 1360 | return false; |
| 1361 | } |
| 1362 | |
| 1363 | void URLRequestHttpJob::StopCaching() { |
| 1364 | if (transaction_.get()) |
| 1365 | transaction_->StopCaching(); |
| 1366 | } |
| 1367 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 1368 | bool URLRequestHttpJob::GetFullRequestHeaders( |
| 1369 | HttpRequestHeaders* headers) const { |
| 1370 | if (!transaction_) |
| 1371 | return false; |
| 1372 | |
| 1373 | return transaction_->GetFullRequestHeaders(headers); |
| 1374 | } |
| 1375 | |
[email protected] | 71e5ff8f | 2014-01-13 09:44:04 | [diff] [blame] | 1376 | int64 URLRequestHttpJob::GetTotalReceivedBytes() const { |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 1377 | int64_t total_received_bytes = |
| 1378 | total_received_bytes_from_previous_transactions_; |
| 1379 | if (transaction_) |
| 1380 | total_received_bytes += transaction_->GetTotalReceivedBytes(); |
| 1381 | return total_received_bytes; |
[email protected] | 71e5ff8f | 2014-01-13 09:44:04 | [diff] [blame] | 1382 | } |
| 1383 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1384 | int64_t URLRequestHttpJob::GetTotalSentBytes() const { |
| 1385 | int64_t total_sent_bytes = total_sent_bytes_from_previous_transactions_; |
| 1386 | if (transaction_) |
| 1387 | total_sent_bytes += transaction_->GetTotalSentBytes(); |
| 1388 | return total_sent_bytes; |
| 1389 | } |
| 1390 | |
[email protected] | 5c04f72 | 2011-08-12 17:52:47 | [diff] [blame] | 1391 | void URLRequestHttpJob::DoneReading() { |
[email protected] | e50efea | 2014-03-24 18:41:00 | [diff] [blame] | 1392 | if (transaction_) { |
[email protected] | 5c04f72 | 2011-08-12 17:52:47 | [diff] [blame] | 1393 | transaction_->DoneReading(); |
[email protected] | e50efea | 2014-03-24 18:41:00 | [diff] [blame] | 1394 | } |
| 1395 | DoneWithRequest(FINISHED); |
| 1396 | } |
| 1397 | |
| 1398 | void URLRequestHttpJob::DoneReadingRedirectResponse() { |
| 1399 | if (transaction_) { |
| 1400 | if (transaction_->GetResponseInfo()->headers->IsRedirect(NULL)) { |
| 1401 | // If the original headers indicate a redirect, go ahead and cache the |
| 1402 | // response, even if the |override_response_headers_| are a redirect to |
| 1403 | // another location. |
| 1404 | transaction_->DoneReading(); |
| 1405 | } else { |
| 1406 | // Otherwise, |override_response_headers_| must be non-NULL and contain |
| 1407 | // bogus headers indicating a redirect. |
dcheng | c2e01e8 | 2014-08-27 00:24:42 | [diff] [blame] | 1408 | DCHECK(override_response_headers_.get()); |
[email protected] | e50efea | 2014-03-24 18:41:00 | [diff] [blame] | 1409 | DCHECK(override_response_headers_->IsRedirect(NULL)); |
| 1410 | transaction_->StopCaching(); |
| 1411 | } |
| 1412 | } |
[email protected] | 5c04f72 | 2011-08-12 17:52:47 | [diff] [blame] | 1413 | DoneWithRequest(FINISHED); |
| 1414 | } |
| 1415 | |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 1416 | HostPortPair URLRequestHttpJob::GetSocketAddress() const { |
| 1417 | return response_info_ ? response_info_->socket_address : HostPortPair(); |
| 1418 | } |
| 1419 | |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1420 | void URLRequestHttpJob::RecordTimer() { |
| 1421 | if (request_creation_time_.is_null()) { |
| 1422 | NOTREACHED() |
| 1423 | << "The same transaction shouldn't start twice without new timing."; |
| 1424 | return; |
| 1425 | } |
| 1426 | |
[email protected] | 320a29f1 | 2011-03-21 14:47:41 | [diff] [blame] | 1427 | base::TimeDelta to_start = base::Time::Now() - request_creation_time_; |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1428 | request_creation_time_ = base::Time(); |
[email protected] | 8684a881 | 2011-03-22 13:59:38 | [diff] [blame] | 1429 | |
[email protected] | 5c68d69 | 2011-08-24 04:59:41 | [diff] [blame] | 1430 | UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpTimeToFirstByte", to_start); |
[email protected] | ec23f52 | 2011-02-22 21:01:38 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | void URLRequestHttpJob::ResetTimer() { |
| 1434 | if (!request_creation_time_.is_null()) { |
| 1435 | NOTREACHED() |
| 1436 | << "The timer was reset before it was recorded."; |
| 1437 | return; |
| 1438 | } |
| 1439 | request_creation_time_ = base::Time::Now(); |
| 1440 | } |
| 1441 | |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1442 | void URLRequestHttpJob::UpdatePacketReadTimes() { |
| 1443 | if (!packet_timing_enabled_) |
| 1444 | return; |
| 1445 | |
mmenke | bbf19be2 | 2015-04-11 02:44:48 | [diff] [blame] | 1446 | DCHECK_GT(prefilter_bytes_read(), bytes_observed_in_packets_); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1447 | |
[email protected] | 006ce1a | 2014-07-30 14:41:23 | [diff] [blame] | 1448 | base::Time now(base::Time::Now()); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1449 | if (!bytes_observed_in_packets_) |
[email protected] | 006ce1a | 2014-07-30 14:41:23 | [diff] [blame] | 1450 | request_time_snapshot_ = now; |
| 1451 | final_packet_time_ = now; |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1452 | |
mmenke | bbf19be2 | 2015-04-11 02:44:48 | [diff] [blame] | 1453 | bytes_observed_in_packets_ = prefilter_bytes_read(); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | void URLRequestHttpJob::RecordPacketStats( |
| 1457 | FilterContext::StatisticSelector statistic) const { |
| 1458 | if (!packet_timing_enabled_ || (final_packet_time_ == base::Time())) |
| 1459 | return; |
| 1460 | |
| 1461 | base::TimeDelta duration = final_packet_time_ - request_time_snapshot_; |
| 1462 | switch (statistic) { |
| 1463 | case FilterContext::SDCH_DECODE: { |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1464 | UMA_HISTOGRAM_CUSTOM_COUNTS("Sdch3.Network_Decode_Bytes_Processed_b", |
| 1465 | static_cast<int>(bytes_observed_in_packets_), 500, 100000, 100); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1466 | return; |
| 1467 | } |
| 1468 | case FilterContext::SDCH_PASSTHROUGH: { |
| 1469 | // Despite advertising a dictionary, we handled non-sdch compressed |
| 1470 | // content. |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1471 | return; |
| 1472 | } |
| 1473 | |
| 1474 | case FilterContext::SDCH_EXPERIMENT_DECODE: { |
[email protected] | 006ce1a | 2014-07-30 14:41:23 | [diff] [blame] | 1475 | UMA_HISTOGRAM_CUSTOM_TIMES("Sdch3.Experiment3_Decode", |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1476 | duration, |
| 1477 | base::TimeDelta::FromMilliseconds(20), |
| 1478 | base::TimeDelta::FromMinutes(10), 100); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1479 | return; |
| 1480 | } |
| 1481 | case FilterContext::SDCH_EXPERIMENT_HOLDBACK: { |
[email protected] | 006ce1a | 2014-07-30 14:41:23 | [diff] [blame] | 1482 | UMA_HISTOGRAM_CUSTOM_TIMES("Sdch3.Experiment3_Holdback", |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1483 | duration, |
| 1484 | base::TimeDelta::FromMilliseconds(20), |
| 1485 | base::TimeDelta::FromMinutes(10), 100); |
[email protected] | dd29bcd7 | 2011-03-24 00:03:44 | [diff] [blame] | 1486 | return; |
| 1487 | } |
| 1488 | default: |
| 1489 | NOTREACHED(); |
| 1490 | return; |
| 1491 | } |
| 1492 | } |
| 1493 | |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1494 | void URLRequestHttpJob::RecordPerfHistograms(CompletionCause reason) { |
| 1495 | if (start_time_.is_null()) |
| 1496 | return; |
| 1497 | |
| 1498 | base::TimeDelta total_time = base::TimeTicks::Now() - start_time_; |
| 1499 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTime", total_time); |
| 1500 | |
| 1501 | if (reason == FINISHED) { |
| 1502 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTimeSuccess", total_time); |
| 1503 | } else { |
| 1504 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTimeCancel", total_time); |
| 1505 | } |
| 1506 | |
[email protected] | 4b4d2024 | 2012-02-23 18:27:46 | [diff] [blame] | 1507 | if (response_info_) { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1508 | // QUIC (by default) supports https scheme only, thus track https URLs only |
| 1509 | // for QUIC. |
| 1510 | bool is_https_google = request() && request()->url().SchemeIs("https") && |
| 1511 | HasGoogleHost(request()->url()); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1512 | bool used_quic = response_info_->DidUseQuic(); |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1513 | if (is_https_google) { |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1514 | if (used_quic) { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1515 | UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpJob.TotalTime.Secure.Quic", |
| 1516 | total_time); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1517 | } else { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1518 | UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpJob.TotalTime.Secure.NotQuic", |
| 1519 | total_time); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1520 | } |
| 1521 | } |
[email protected] | 4b4d2024 | 2012-02-23 18:27:46 | [diff] [blame] | 1522 | if (response_info_->was_cached) { |
| 1523 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTimeCached", total_time); |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1524 | if (is_https_google) { |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1525 | if (used_quic) { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1526 | UMA_HISTOGRAM_MEDIUM_TIMES("Net.HttpJob.TotalTimeCached.Secure.Quic", |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1527 | total_time); |
| 1528 | } else { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1529 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 1530 | "Net.HttpJob.TotalTimeCached.Secure.NotQuic", total_time); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1531 | } |
| 1532 | } |
[email protected] | 4b4d2024 | 2012-02-23 18:27:46 | [diff] [blame] | 1533 | } else { |
| 1534 | UMA_HISTOGRAM_TIMES("Net.HttpJob.TotalTimeNotCached", total_time); |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1535 | if (is_https_google) { |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1536 | if (used_quic) { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1537 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 1538 | "Net.HttpJob.TotalTimeNotCached.Secure.Quic", total_time); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1539 | } else { |
rtenneti | e55c4b7 | 2015-08-03 21:48:35 | [diff] [blame] | 1540 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 1541 | "Net.HttpJob.TotalTimeNotCached.Secure.NotQuic", total_time); |
rtenneti | 72928bb | 2015-04-28 18:28:13 | [diff] [blame] | 1542 | } |
| 1543 | } |
[email protected] | b73656ca | 2011-07-22 17:42:17 | [diff] [blame] | 1544 | } |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1545 | } |
| 1546 | |
[email protected] | 3ed8472 | 2013-11-01 17:17:07 | [diff] [blame] | 1547 | if (request_info_.load_flags & LOAD_PREFETCH && !request_->was_cached()) |
| 1548 | UMA_HISTOGRAM_COUNTS("Net.Prefetch.PrefilterBytesReadFromNetwork", |
| 1549 | prefilter_bytes_read()); |
| 1550 | |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1551 | start_time_ = base::TimeTicks(); |
| 1552 | } |
| 1553 | |
| 1554 | void URLRequestHttpJob::DoneWithRequest(CompletionCause reason) { |
| 1555 | if (done_) |
| 1556 | return; |
| 1557 | done_ = true; |
tbansal | 79ed5cd | 2015-08-10 18:53:56 | [diff] [blame] | 1558 | |
| 1559 | // Notify NetworkQualityEstimator. |
| 1560 | if (request() && (reason == FINISHED || reason == ABORTED)) { |
| 1561 | NetworkQualityEstimator* network_quality_estimator = |
| 1562 | request()->context()->network_quality_estimator(); |
| 1563 | if (network_quality_estimator) |
| 1564 | network_quality_estimator->NotifyRequestCompleted(*request()); |
| 1565 | } |
| 1566 | |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1567 | RecordPerfHistograms(reason); |
kundaji | b8c0d10 | 2015-07-27 21:47:41 | [diff] [blame] | 1568 | if (request_) |
[email protected] | 7a299a9 | 2012-10-24 23:54:50 | [diff] [blame] | 1569 | request_->set_received_response_content_length(prefilter_bytes_read()); |
[email protected] | bbaea8f | 2011-06-24 00:11:01 | [diff] [blame] | 1570 | } |
| 1571 | |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1572 | HttpResponseHeaders* URLRequestHttpJob::GetResponseHeaders() const { |
| 1573 | DCHECK(transaction_.get()); |
| 1574 | DCHECK(transaction_->GetResponseInfo()); |
| 1575 | return override_response_headers_.get() ? |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1576 | override_response_headers_.get() : |
| 1577 | transaction_->GetResponseInfo()->headers.get(); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1581 | awaiting_callback_ = false; |
| 1582 | } |
| 1583 | |
[email protected] | 4f5656c6 | 2010-12-13 10:47:09 | [diff] [blame] | 1584 | } // namespace net |