Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "net/cookies/cookie_monster.h" | 31 #include "net/cookies/cookie_monster.h" |
| 32 #include "net/http/http_request_headers.h" | 32 #include "net/http/http_request_headers.h" |
| 33 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 34 #include "net/http/http_response_info.h" | 34 #include "net/http/http_response_info.h" |
| 35 #include "net/http/http_status_code.h" | 35 #include "net/http/http_status_code.h" |
| 36 #include "net/http/http_transaction.h" | 36 #include "net/http/http_transaction.h" |
| 37 #include "net/http/http_transaction_delegate.h" | 37 #include "net/http/http_transaction_delegate.h" |
| 38 #include "net/http/http_transaction_factory.h" | 38 #include "net/http/http_transaction_factory.h" |
| 39 #include "net/http/http_util.h" | 39 #include "net/http/http_util.h" |
| 40 #include "net/url_request/fraudulent_certificate_reporter.h" | 40 #include "net/url_request/fraudulent_certificate_reporter.h" |
| 41 #include "net/url_request/http_user_agent_settings.h" | |
| 41 #include "net/url_request/url_request.h" | 42 #include "net/url_request/url_request.h" |
| 42 #include "net/url_request/url_request_context.h" | 43 #include "net/url_request/url_request_context.h" |
| 43 #include "net/url_request/url_request_error_job.h" | 44 #include "net/url_request/url_request_error_job.h" |
| 44 #include "net/url_request/url_request_redirect_job.h" | 45 #include "net/url_request/url_request_redirect_job.h" |
| 45 #include "net/url_request/url_request_throttler_header_adapter.h" | 46 #include "net/url_request/url_request_throttler_header_adapter.h" |
| 46 #include "net/url_request/url_request_throttler_manager.h" | 47 #include "net/url_request/url_request_throttler_manager.h" |
| 47 | 48 |
| 48 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; | 49 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; |
| 49 | 50 |
| 50 namespace net { | 51 namespace net { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 | 204 |
| 204 if (!request->context()->http_transaction_factory()) { | 205 if (!request->context()->http_transaction_factory()) { |
| 205 NOTREACHED() << "requires a valid context"; | 206 NOTREACHED() << "requires a valid context"; |
| 206 return new URLRequestErrorJob( | 207 return new URLRequestErrorJob( |
| 207 request, network_delegate, ERR_INVALID_ARGUMENT); | 208 request, network_delegate, ERR_INVALID_ARGUMENT); |
| 208 } | 209 } |
| 209 | 210 |
| 210 GURL redirect_url; | 211 GURL redirect_url; |
| 211 if (request->GetHSTSRedirect(&redirect_url)) | 212 if (request->GetHSTSRedirect(&redirect_url)) |
| 212 return new URLRequestRedirectJob(request, network_delegate, redirect_url); | 213 return new URLRequestRedirectJob(request, network_delegate, redirect_url); |
| 213 return new URLRequestHttpJob(request, network_delegate); | 214 return new URLRequestHttpJob(request, |
| 215 network_delegate, | |
| 216 request->context()->http_user_agent_settings()); | |
| 214 } | 217 } |
| 215 | 218 |
| 216 | 219 |
| 217 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request, | 220 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request, |
| 218 NetworkDelegate* network_delegate) | 221 NetworkDelegate* network_delegate, |
| 222 HttpUserAgentSettings* | |
| 223 http_user_agent_settings) | |
|
willchan no longer on Chromium
2012/10/24 03:40:10
we don't format like this, move all the other para
| |
| 219 : URLRequestJob(request, network_delegate), | 224 : URLRequestJob(request, network_delegate), |
| 220 response_info_(NULL), | 225 response_info_(NULL), |
| 221 response_cookies_save_index_(0), | 226 response_cookies_save_index_(0), |
| 222 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 227 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 223 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 228 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 224 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( | 229 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( |
| 225 base::Bind(&URLRequestHttpJob::OnStartCompleted, | 230 base::Bind(&URLRequestHttpJob::OnStartCompleted, |
| 226 base::Unretained(this)))), | 231 base::Unretained(this)))), |
| 227 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( | 232 ALLOW_THIS_IN_INITIALIZER_LIST(notify_before_headers_sent_callback_( |
| 228 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, | 233 base::Bind(&URLRequestHttpJob::NotifyBeforeSendHeadersCallback, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 240 bytes_observed_in_packets_(0), | 245 bytes_observed_in_packets_(0), |
| 241 request_time_snapshot_(), | 246 request_time_snapshot_(), |
| 242 final_packet_time_(), | 247 final_packet_time_(), |
| 243 ALLOW_THIS_IN_INITIALIZER_LIST( | 248 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 244 filter_context_(new HttpFilterContext(this))), | 249 filter_context_(new HttpFilterContext(this))), |
| 245 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 250 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 246 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( | 251 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( |
| 247 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, | 252 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, |
| 248 base::Unretained(this)))), | 253 base::Unretained(this)))), |
| 249 awaiting_callback_(false), | 254 awaiting_callback_(false), |
| 250 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)) { | 255 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)), |
| 256 http_user_agent_settings_(http_user_agent_settings) { | |
|
willchan no longer on Chromium
2012/10/24 03:40:10
Should we DCHECK() that it's non-NULL?
| |
| 251 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); | 257 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); |
| 252 if (manager) | 258 if (manager) |
| 253 throttling_entry_ = manager->RegisterRequestUrl(request->url()); | 259 throttling_entry_ = manager->RegisterRequestUrl(request->url()); |
| 254 | 260 |
| 255 ResetTimer(); | 261 ResetTimer(); |
| 256 } | 262 } |
| 257 | 263 |
| 258 void URLRequestHttpJob::NotifyHeadersComplete() { | 264 void URLRequestHttpJob::NotifyHeadersComplete() { |
| 259 DCHECK(!response_info_); | 265 DCHECK(!response_info_); |
| 260 | 266 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 // Since we're tagging this transaction as advertising a dictionary, | 469 // Since we're tagging this transaction as advertising a dictionary, |
| 464 // we'll definitely employ an SDCH filter (or tentative sdch filter) | 470 // we'll definitely employ an SDCH filter (or tentative sdch filter) |
| 465 // when we get a response. When done, we'll record histograms via | 471 // when we get a response. When done, we'll record histograms via |
| 466 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet | 472 // SDCH_DECODE or SDCH_PASSTHROUGH. Hence we need to record packet |
| 467 // arrival times. | 473 // arrival times. |
| 468 packet_timing_enabled_ = true; | 474 packet_timing_enabled_ = true; |
| 469 } | 475 } |
| 470 } | 476 } |
| 471 } | 477 } |
| 472 | 478 |
| 473 const URLRequestContext* context = request_->context(); | |
| 474 // Only add default Accept-Language and Accept-Charset if the request | 479 // Only add default Accept-Language and Accept-Charset if the request |
| 475 // didn't have them specified. | 480 // didn't have them specified. |
| 476 if (!context->accept_language().empty()) { | 481 std::string accept_language = http_user_agent_settings_->GetAcceptLanguage(); |
|
erikwright (departed)
2012/10/24 13:14:33
It seems from the unit test that the settings obje
| |
| 482 if (!accept_language.empty()) { | |
| 477 request_info_.extra_headers.SetHeaderIfMissing( | 483 request_info_.extra_headers.SetHeaderIfMissing( |
| 478 HttpRequestHeaders::kAcceptLanguage, | 484 HttpRequestHeaders::kAcceptLanguage, |
| 479 context->accept_language()); | 485 accept_language); |
| 480 } | 486 } |
| 481 if (!context->accept_charset().empty()) { | 487 std::string accept_charset = http_user_agent_settings_->GetAcceptCharset(); |
| 488 if (!accept_charset.empty()) { | |
| 482 request_info_.extra_headers.SetHeaderIfMissing( | 489 request_info_.extra_headers.SetHeaderIfMissing( |
| 483 HttpRequestHeaders::kAcceptCharset, | 490 HttpRequestHeaders::kAcceptCharset, |
| 484 context->accept_charset()); | 491 accept_charset); |
| 485 } | 492 } |
| 486 } | 493 } |
| 487 | 494 |
| 488 void URLRequestHttpJob::AddCookieHeaderAndStart() { | 495 void URLRequestHttpJob::AddCookieHeaderAndStart() { |
| 489 // No matter what, we want to report our status as IO pending since we will | 496 // No matter what, we want to report our status as IO pending since we will |
| 490 // be notifying our consumer asynchronously via OnStartCompleted. | 497 // be notifying our consumer asynchronously via OnStartCompleted. |
| 491 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 498 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 492 | 499 |
| 493 // If the request was destroyed, then there is no more work to do. | 500 // If the request was destroyed, then there is no more work to do. |
| 494 if (!request_) | 501 if (!request_) |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 900 | 907 |
| 901 // Our consumer should have made sure that this is a safe referrer. See for | 908 // Our consumer should have made sure that this is a safe referrer. See for |
| 902 // instance WebCore::FrameLoader::HideReferrer. | 909 // instance WebCore::FrameLoader::HideReferrer. |
| 903 if (referrer.is_valid()) { | 910 if (referrer.is_valid()) { |
| 904 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer, | 911 request_info_.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 905 referrer.spec()); | 912 referrer.spec()); |
| 906 } | 913 } |
| 907 | 914 |
| 908 request_info_.extra_headers.SetHeaderIfMissing( | 915 request_info_.extra_headers.SetHeaderIfMissing( |
| 909 HttpRequestHeaders::kUserAgent, | 916 HttpRequestHeaders::kUserAgent, |
| 910 request_->context()->GetUserAgent(request_->url())); | 917 http_user_agent_settings_->GetUserAgent(request_->url())); |
| 911 | 918 |
| 912 AddExtraHeaders(); | 919 AddExtraHeaders(); |
| 913 AddCookieHeaderAndStart(); | 920 AddCookieHeaderAndStart(); |
| 914 } | 921 } |
| 915 | 922 |
| 916 void URLRequestHttpJob::Kill() { | 923 void URLRequestHttpJob::Kill() { |
| 917 http_transaction_delegate_->OnDetachRequest(); | 924 http_transaction_delegate_->OnDetachRequest(); |
| 918 | 925 |
| 919 if (!transaction_.get()) | 926 if (!transaction_.get()) |
| 920 return; | 927 return; |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1504 | 1511 |
| 1505 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1512 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
| 1506 awaiting_callback_ = false; | 1513 awaiting_callback_ = false; |
| 1507 } | 1514 } |
| 1508 | 1515 |
| 1509 void URLRequestHttpJob::OnDetachRequest() { | 1516 void URLRequestHttpJob::OnDetachRequest() { |
| 1510 http_transaction_delegate_->OnDetachRequest(); | 1517 http_transaction_delegate_->OnDetachRequest(); |
| 1511 } | 1518 } |
| 1512 | 1519 |
| 1513 } // namespace net | 1520 } // namespace net |
| OLD | NEW |