OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 275 |
276 // The HTTP transaction may be restarted several times for the purposes | 276 // The HTTP transaction may be restarted several times for the purposes |
277 // of sending authorization information. Each time it restarts, we get | 277 // of sending authorization information. Each time it restarts, we get |
278 // notified of the headers completion so that we can update the cookie store. | 278 // notified of the headers completion so that we can update the cookie store. |
279 if (transaction_->IsReadyToRestartForAuth()) { | 279 if (transaction_->IsReadyToRestartForAuth()) { |
280 DCHECK(!response_info_->auth_challenge.get()); | 280 DCHECK(!response_info_->auth_challenge.get()); |
281 // TODO(battre): This breaks the webrequest API for | 281 // TODO(battre): This breaks the webrequest API for |
282 // URLRequestTestHTTP.BasicAuthWithCookies | 282 // URLRequestTestHTTP.BasicAuthWithCookies |
283 // where OnBeforeSendHeaders -> OnSendHeaders -> OnBeforeSendHeaders | 283 // where OnBeforeSendHeaders -> OnSendHeaders -> OnBeforeSendHeaders |
284 // occurs. | 284 // occurs. |
285 RestartTransactionWithAuth(string16(), string16()); | 285 RestartTransactionWithAuth(AuthCredentials()); |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 URLRequestJob::NotifyHeadersComplete(); | 289 URLRequestJob::NotifyHeadersComplete(); |
290 } | 290 } |
291 | 291 |
292 void URLRequestHttpJob::NotifyDone(const URLRequestStatus& status) { | 292 void URLRequestHttpJob::NotifyDone(const URLRequestStatus& status) { |
293 DoneWithRequest(FINISHED); | 293 DoneWithRequest(FINISHED); |
294 URLRequestJob::NotifyDone(status); | 294 URLRequestJob::NotifyDone(status); |
295 } | 295 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, | 327 request_->net_log().AddEvent(NetLog::TYPE_CANCELLED, |
328 make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); | 328 make_scoped_refptr(new NetLogStringParameter("source", "delegate"))); |
329 NotifyCanceled(); | 329 NotifyCanceled(); |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 void URLRequestHttpJob::StartTransactionInternal() { | 333 void URLRequestHttpJob::StartTransactionInternal() { |
334 // NOTE: This method assumes that request_info_ is already setup properly. | 334 // NOTE: This method assumes that request_info_ is already setup properly. |
335 | 335 |
336 // If we already have a transaction, then we should restart the transaction | 336 // If we already have a transaction, then we should restart the transaction |
337 // with auth provided by username_ and password_. | 337 // with auth provided by auth_credentials_. |
338 | 338 |
339 int rv; | 339 int rv; |
340 | 340 |
341 if (request_->context() && request_->context()->network_delegate()) { | 341 if (request_->context() && request_->context()->network_delegate()) { |
342 request_->context()->network_delegate()->NotifySendHeaders( | 342 request_->context()->network_delegate()->NotifySendHeaders( |
343 request_, request_info_.extra_headers); | 343 request_, request_info_.extra_headers); |
344 } | 344 } |
345 | 345 |
346 if (transaction_.get()) { | 346 if (transaction_.get()) { |
347 rv = transaction_->RestartWithAuth(username_, password_, &start_callback_); | 347 rv = transaction_->RestartWithAuth(auth_credentials_, &start_callback_); |
348 username_.clear(); | 348 auth_credentials_ = AuthCredentials(); |
349 password_.clear(); | |
350 } else { | 349 } else { |
351 DCHECK(request_->context()); | 350 DCHECK(request_->context()); |
352 DCHECK(request_->context()->http_transaction_factory()); | 351 DCHECK(request_->context()->http_transaction_factory()); |
353 | 352 |
354 rv = request_->context()->http_transaction_factory()->CreateTransaction( | 353 rv = request_->context()->http_transaction_factory()->CreateTransaction( |
355 &transaction_); | 354 &transaction_); |
356 if (rv == OK) { | 355 if (rv == OK) { |
357 if (!URLRequestThrottlerManager::GetInstance()->enforce_throttling() || | 356 if (!URLRequestThrottlerManager::GetInstance()->enforce_throttling() || |
358 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { | 357 !throttling_entry_->ShouldRejectRequest(request_info_.load_flags)) { |
359 rv = transaction_->Start( | 358 rv = transaction_->Start( |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 757 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
759 } else { | 758 } else { |
760 // Clear the IO_PENDING status | 759 // Clear the IO_PENDING status |
761 SetStatus(URLRequestStatus()); | 760 SetStatus(URLRequestStatus()); |
762 } | 761 } |
763 | 762 |
764 NotifyReadComplete(result); | 763 NotifyReadComplete(result); |
765 } | 764 } |
766 | 765 |
767 void URLRequestHttpJob::RestartTransactionWithAuth( | 766 void URLRequestHttpJob::RestartTransactionWithAuth( |
768 const string16& username, | 767 const AuthCredentials& credentials) { |
769 const string16& password) { | 768 auth_credentials_ = credentials; |
770 username_ = username; | |
771 password_ = password; | |
772 | 769 |
773 // These will be reset in OnStartCompleted. | 770 // These will be reset in OnStartCompleted. |
774 response_info_ = NULL; | 771 response_info_ = NULL; |
775 response_cookies_.clear(); | 772 response_cookies_.clear(); |
776 | 773 |
777 ResetTimer(); | 774 ResetTimer(); |
778 | 775 |
779 // Update the cookies, since the cookie store may have been updated from the | 776 // Update the cookies, since the cookie store may have been updated from the |
780 // headers in the 401/407. Since cookies were already appended to | 777 // headers in the 401/407. Since cookies were already appended to |
781 // extra_headers, we need to strip them out before adding them again. | 778 // extra_headers, we need to strip them out before adding them again. |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 | 987 |
991 // sanity checks: | 988 // sanity checks: |
992 DCHECK(proxy_auth_state_ == AUTH_STATE_NEED_AUTH || | 989 DCHECK(proxy_auth_state_ == AUTH_STATE_NEED_AUTH || |
993 server_auth_state_ == AUTH_STATE_NEED_AUTH); | 990 server_auth_state_ == AUTH_STATE_NEED_AUTH); |
994 DCHECK(GetResponseHeaders()->response_code() == 401 || | 991 DCHECK(GetResponseHeaders()->response_code() == 401 || |
995 GetResponseHeaders()->response_code() == 407); | 992 GetResponseHeaders()->response_code() == 407); |
996 | 993 |
997 *result = response_info_->auth_challenge; | 994 *result = response_info_->auth_challenge; |
998 } | 995 } |
999 | 996 |
1000 void URLRequestHttpJob::SetAuth(const string16& username, | 997 void URLRequestHttpJob::SetAuth(const AuthCredentials& credentials) { |
1001 const string16& password) { | |
1002 DCHECK(transaction_.get()); | 998 DCHECK(transaction_.get()); |
1003 | 999 |
1004 // Proxy gets set first, then WWW. | 1000 // Proxy gets set first, then WWW. |
1005 if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { | 1001 if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { |
1006 proxy_auth_state_ = AUTH_STATE_HAVE_AUTH; | 1002 proxy_auth_state_ = AUTH_STATE_HAVE_AUTH; |
1007 } else { | 1003 } else { |
1008 DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); | 1004 DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); |
1009 server_auth_state_ = AUTH_STATE_HAVE_AUTH; | 1005 server_auth_state_ = AUTH_STATE_HAVE_AUTH; |
1010 } | 1006 } |
1011 | 1007 |
1012 RestartTransactionWithAuth(username, password); | 1008 RestartTransactionWithAuth(credentials); |
1013 } | 1009 } |
1014 | 1010 |
1015 void URLRequestHttpJob::CancelAuth() { | 1011 void URLRequestHttpJob::CancelAuth() { |
1016 // Proxy gets set first, then WWW. | 1012 // Proxy gets set first, then WWW. |
1017 if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { | 1013 if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { |
1018 proxy_auth_state_ = AUTH_STATE_CANCELED; | 1014 proxy_auth_state_ = AUTH_STATE_CANCELED; |
1019 } else { | 1015 } else { |
1020 DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); | 1016 DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); |
1021 server_auth_state_ = AUTH_STATE_CANCELED; | 1017 server_auth_state_ = AUTH_STATE_CANCELED; |
1022 } | 1018 } |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 return override_response_headers_.get() ? | 1423 return override_response_headers_.get() ? |
1428 override_response_headers_ : | 1424 override_response_headers_ : |
1429 transaction_->GetResponseInfo()->headers; | 1425 transaction_->GetResponseInfo()->headers; |
1430 } | 1426 } |
1431 | 1427 |
1432 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1428 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1433 awaiting_callback_ = false; | 1429 awaiting_callback_ = false; |
1434 } | 1430 } |
1435 | 1431 |
1436 } // namespace net | 1432 } // namespace net |
OLD | NEW |