| 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/http/http_auth_handler.h" | 5 #include "net/http/http_auth_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "net/http/http_auth_challenge_tokenizer.h" | 12 #include "net/http/http_auth_challenge_tokenizer.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 | 15 |
| 15 HttpAuthHandler::HttpAuthHandler() | 16 HttpAuthHandler::HttpAuthHandler() : target_(HttpAuth::AUTH_NONE) {} |
| 16 : auth_scheme_(HttpAuth::AUTH_SCHEME_MAX), | |
| 17 score_(-1), | |
| 18 target_(HttpAuth::AUTH_NONE), | |
| 19 properties_(-1) { | |
| 20 } | |
| 21 | 17 |
| 22 HttpAuthHandler::~HttpAuthHandler() { | 18 HttpAuthHandler::~HttpAuthHandler() { |
| 23 } | 19 } |
| 24 | 20 |
| 25 bool HttpAuthHandler::InitFromChallenge( | 21 bool HttpAuthHandler::InitFromChallenge( |
| 26 HttpAuthChallengeTokenizer* challenge, | 22 HttpAuthChallengeTokenizer* challenge, |
| 27 HttpAuth::Target target, | 23 HttpAuth::Target target, |
| 28 const GURL& origin, | 24 const GURL& origin, |
| 29 const BoundNetLog& net_log) { | 25 const BoundNetLog& net_log) { |
| 30 origin_ = origin; | 26 origin_ = origin; |
| 31 target_ = target; | 27 target_ = target; |
| 32 score_ = -1; | |
| 33 properties_ = -1; | |
| 34 net_log_ = net_log; | 28 net_log_ = net_log; |
| 35 | 29 |
| 36 auth_challenge_ = challenge->challenge_text(); | 30 auth_challenge_ = challenge->challenge_text(); |
| 37 bool ok = Init(challenge); | 31 bool ok = Init(challenge); |
| 38 | 32 |
| 39 // Init() is expected to set the scheme, realm, score, and properties. The | 33 // Init() is expected to set the scheme, realm, and properties. The realm may |
| 40 // realm may be empty. | 34 // be empty. |
| 41 DCHECK(!ok || score_ != -1); | 35 DCHECK_IMPLIES(ok, |
| 42 DCHECK(!ok || properties_ != -1); | 36 HttpUtil::IsToken(auth_scheme_.begin(), auth_scheme_.end()) && |
| 43 DCHECK(!ok || auth_scheme_ != HttpAuth::AUTH_SCHEME_MAX); | 37 base::ToLowerASCII(auth_scheme_) == auth_scheme_); |
| 44 | |
| 45 return ok; | 38 return ok; |
| 46 } | 39 } |
| 47 | 40 |
| 48 namespace { | 41 namespace { |
| 49 | 42 |
| 50 NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { | 43 NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { |
| 51 switch (target) { | 44 switch (target) { |
| 52 case HttpAuth::AUTH_PROXY: | 45 case HttpAuth::AUTH_PROXY: |
| 53 return NetLog::TYPE_AUTH_PROXY; | 46 return NetLog::TYPE_AUTH_PROXY; |
| 54 case HttpAuth::AUTH_SERVER: | 47 case HttpAuth::AUTH_SERVER: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 callback.Run(rv); | 93 callback.Run(rv); |
| 101 } | 94 } |
| 102 | 95 |
| 103 void HttpAuthHandler::FinishGenerateAuthToken() { | 96 void HttpAuthHandler::FinishGenerateAuthToken() { |
| 104 // TOOD(cbentzel): Should this be done in OK case only? | 97 // TOOD(cbentzel): Should this be done in OK case only? |
| 105 net_log_.EndEvent(EventTypeFromAuthTarget(target_)); | 98 net_log_.EndEvent(EventTypeFromAuthTarget(target_)); |
| 106 callback_.Reset(); | 99 callback_.Reset(); |
| 107 } | 100 } |
| 108 | 101 |
| 109 } // namespace net | 102 } // namespace net |
| OLD | NEW |