diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-08 06:46:23 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-08 06:46:23 +0000 |
commit | f9ee6b5a5925d8496f05309963c42bfdd3ec1a8b (patch) | |
tree | 7867cc64559bf86408da5a744e918d2861bf3889 /net/url_request | |
parent | f6028ee8661996ba41763a6601469ebd599480f5 (diff) | |
download | chromium_src-f9ee6b5a5925d8496f05309963c42bfdd3ec1a8b.zip chromium_src-f9ee6b5a5925d8496f05309963c42bfdd3ec1a8b.tar.gz chromium_src-f9ee6b5a5925d8496f05309963c42bfdd3ec1a8b.tar.bz2 |
- Add preemptive authorization (new http stack only)
- Check for auth identity in URL (new http stack only)
- Move auth cache logic out of url request job, and hide it in the url request ftp job and http transaction classes.
Note: Somehow the original codereview thread got corrupted so it was recreated.
The real review comments should be under (http://codereview.chromium.org/6481)
Review URL: http://codereview.chromium.org/8231
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5064 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r-- | net/url_request/url_request_ftp_job.cc | 32 | ||||
-rw-r--r-- | net/url_request/url_request_ftp_job.h | 2 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.cc | 14 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.h | 2 | ||||
-rw-r--r-- | net/url_request/url_request_job.cc | 6 | ||||
-rw-r--r-- | net/url_request/url_request_job.h | 8 |
6 files changed, 19 insertions, 45 deletions
diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc index fab4ff3..9cd7ca9 100644 --- a/net/url_request/url_request_ftp_job.cc +++ b/net/url_request/url_request_ftp_job.cc @@ -167,19 +167,32 @@ void URLRequestFtpJob::OnIOComplete(const AsyncResult& result) { // fall through case ERROR_INTERNET_INCORRECT_USER_NAME: // fall through - case ERROR_INTERNET_INCORRECT_PASSWORD: + case ERROR_INTERNET_INCORRECT_PASSWORD: { + // TODO(eroman): shouldn't the port be part of the key? + std::string cache_key = request_->url().host(); if (server_auth_ != NULL && server_auth_->state == net::AUTH_STATE_HAVE_AUTH) { - request_->context()->ftp_auth_cache()->Remove(request_->url().host()); + request_->context()->ftp_auth_cache()->Remove(cache_key); } else { server_auth_ = new net::AuthData(); } - // Try again, prompting for authentication. server_auth_->state = net::AUTH_STATE_NEED_AUTH; - // The io completed fine, the error was due to invalid auth. - SetStatus(URLRequestStatus()); - NotifyHeadersComplete(); + + scoped_refptr<net::AuthData> cached_auth = + request_->context()->ftp_auth_cache()->Lookup(cache_key); + + if (cached_auth) { + // Retry using cached auth data. + SetAuth(cached_auth->username, cached_auth->password); + } else { + // The io completed fine, the error was due to invalid auth. + SetStatus(URLRequestStatus()); + + // Prompt for a username/password. + NotifyHeadersComplete(); + } return; + } case ERROR_SUCCESS: connection_handle_ = (HINTERNET)result.dwResult; OnConnect(); @@ -261,13 +274,6 @@ void URLRequestFtpJob::GetAuthChallengeInfo( result->swap(auth_info); } -void URLRequestFtpJob::GetCachedAuthData( - const net::AuthChallengeInfo& auth_info, - scoped_refptr<net::AuthData>* auth_data) { - *auth_data = request_->context()->ftp_auth_cache()-> - Lookup(WideToUTF8(auth_info.host)); -} - void URLRequestFtpJob::OnConnect() { DCHECK_EQ(state_, CONNECTING); diff --git a/net/url_request/url_request_ftp_job.h b/net/url_request/url_request_ftp_job.h index 3b766b4..44e845c 100644 --- a/net/url_request/url_request_ftp_job.h +++ b/net/url_request/url_request_ftp_job.h @@ -33,8 +33,6 @@ class URLRequestFtpJob : public URLRequestInetJob { virtual void OnSetAuth(); virtual bool NeedsAuth(); virtual void GetAuthChallengeInfo(scoped_refptr<net::AuthChallengeInfo>*); - virtual void GetCachedAuthData(const net::AuthChallengeInfo& auth_info, - scoped_refptr<net::AuthData>* auth_data); virtual bool IsRedirectResponse(GURL* location, int* http_status_code); private: diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 49a8925..69f7bb5 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -261,20 +261,6 @@ void URLRequestHttpJob::GetAuthChallengeInfo( *result = response_info_->auth_challenge; } -void URLRequestHttpJob::GetCachedAuthData( - const net::AuthChallengeInfo& auth_info, - scoped_refptr<net::AuthData>* auth_data) { - net::AuthCache* auth_cache = - request_->context()->http_transaction_factory()->GetAuthCache(); - if (!auth_cache) { - *auth_data = NULL; - return; - } - std::string auth_cache_key = - net::AuthCache::HttpKey(request_->url(), auth_info); - *auth_data = auth_cache->Lookup(auth_cache_key); -} - void URLRequestHttpJob::SetAuth(const std::wstring& username, const std::wstring& password) { DCHECK(transaction_.get()); diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h index f36a072..eda4b4b 100644 --- a/net/url_request/url_request_http_job.h +++ b/net/url_request/url_request_http_job.h @@ -48,8 +48,6 @@ class URLRequestHttpJob : public URLRequestJob { virtual bool IsSafeRedirect(const GURL& location); virtual bool NeedsAuth(); virtual void GetAuthChallengeInfo(scoped_refptr<net::AuthChallengeInfo>*); - virtual void GetCachedAuthData(const net::AuthChallengeInfo& auth_info, - scoped_refptr<net::AuthData>* auth_data); virtual void SetAuth(const std::wstring& username, const std::wstring& password); virtual void CancelAuth(); diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index ea5ccb9..6e969b2 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -314,12 +314,6 @@ void URLRequestJob::NotifyHeadersComplete() { // Need to check for a NULL auth_info because the server may have failed // to send a challenge with the 401 response. if (auth_info) { - scoped_refptr<net::AuthData> auth_data; - GetCachedAuthData(*auth_info, &auth_data); - if (auth_data) { - SetAuth(auth_data->username, auth_data->password); - return; - } request_->delegate()->OnAuthRequired(request_, auth_info); // Wait for SetAuth or CancelAuth to be called. return; diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h index 6b309be..43fa866 100644 --- a/net/url_request/url_request_job.h +++ b/net/url_request/url_request_job.h @@ -164,14 +164,6 @@ class URLRequestJob : public base::RefCountedThreadSafe<URLRequestJob> { virtual void GetAuthChallengeInfo( scoped_refptr<net::AuthChallengeInfo>* auth_info); - // Returns cached auth data for the auth challenge. Returns NULL if there - // is no auth cache or if the auth cache doesn't have the auth data for - // the auth challenge. - virtual void GetCachedAuthData(const net::AuthChallengeInfo& auth_info, - scoped_refptr<net::AuthData>* auth_data) { - *auth_data = NULL; - } - // Resend the request with authentication credentials. virtual void SetAuth(const std::wstring& username, const std::wstring& password); |