| 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/http/http_auth.h" | 5 #include "net/http/http_auth.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 int cur_priority = GetSchemePriority(cur_auth_scheme); | 102 int cur_priority = GetSchemePriority(cur_auth_scheme); |
| 103 if (best.get() && best_priority >= cur_priority) | 103 if (best.get() && best_priority >= cur_priority) |
| 104 continue; | 104 continue; |
| 105 | 105 |
| 106 // Immediately trying to create a handler may be wasteful because we may see | 106 // Immediately trying to create a handler may be wasteful because we may see |
| 107 // a higher ranking challenge later on in the headers. However, this is | 107 // a higher ranking challenge later on in the headers. However, this is |
| 108 // rare. Servers typically specify higher priority schemes before lower | 108 // rare. Servers typically specify higher priority schemes before lower |
| 109 // priority schemes. | 109 // priority schemes. |
| 110 scoped_ptr<HttpAuthHandler> current_handler; | 110 scoped_ptr<HttpAuthHandler> current_handler; |
| 111 int rv = http_auth_handler_factory->CreateAuthHandler( | 111 int rv = http_auth_handler_factory->CreateAuthHandler( |
| 112 &challenge_tokenizer, target, origin, | 112 challenge_tokenizer, target, origin, |
| 113 HttpAuthHandlerFactory::CREATE_CHALLENGE, 1, net_log, ¤t_handler); | 113 HttpAuthHandlerFactory::CREATE_CHALLENGE, 1, net_log, ¤t_handler); |
| 114 if (rv != OK) { | 114 if (rv != OK) { |
| 115 net_log.AddEvent( | 115 net_log.AddEvent( |
| 116 NetLog::TYPE_AUTH_HANDLER_CREATION_FAILURE, | 116 NetLog::TYPE_AUTH_HANDLER_CREATION_FAILURE, |
| 117 base::Bind(&AuthHandlerCreationFailureParams, &cur_challenge, rv)); | 117 base::Bind(&AuthHandlerCreationFailureParams, &cur_challenge, rv)); |
| 118 continue; | 118 continue; |
| 119 } | 119 } |
| 120 DCHECK(current_handler.get()); | 120 DCHECK(current_handler.get()); |
| 121 DCHECK_EQ(cur_auth_scheme, current_handler->auth_scheme()); | 121 DCHECK_EQ(cur_auth_scheme, current_handler->auth_scheme()); |
| 122 best.swap(current_handler); | 122 best.swap(current_handler); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 141 return HttpAuth::AUTHORIZATION_RESULT_REJECT; | 141 return HttpAuth::AUTHORIZATION_RESULT_REJECT; |
| 142 const std::string header_name = GetChallengeHeaderName(target); | 142 const std::string header_name = GetChallengeHeaderName(target); |
| 143 void* iter = NULL; | 143 void* iter = NULL; |
| 144 std::string challenge; | 144 std::string challenge; |
| 145 HttpAuth::AuthorizationResult authorization_result = | 145 HttpAuth::AuthorizationResult authorization_result = |
| 146 HttpAuth::AUTHORIZATION_RESULT_INVALID; | 146 HttpAuth::AUTHORIZATION_RESULT_INVALID; |
| 147 while (headers->EnumerateHeader(&iter, header_name, &challenge)) { | 147 while (headers->EnumerateHeader(&iter, header_name, &challenge)) { |
| 148 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); | 148 HttpAuthChallengeTokenizer props(challenge.begin(), challenge.end()); |
| 149 if (!props.SchemeIs(current_scheme)) | 149 if (!props.SchemeIs(current_scheme)) |
| 150 continue; | 150 continue; |
| 151 authorization_result = handler->HandleAnotherChallenge(&props); | 151 authorization_result = handler->HandleAnotherChallenge(props); |
| 152 if (authorization_result != HttpAuth::AUTHORIZATION_RESULT_INVALID) { | 152 if (authorization_result != HttpAuth::AUTHORIZATION_RESULT_INVALID) { |
| 153 *challenge_used = challenge; | 153 *challenge_used = challenge; |
| 154 return authorization_result; | 154 return authorization_result; |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 // Finding no matches is equivalent to rejection. | 157 // Finding no matches is equivalent to rejection. |
| 158 return HttpAuth::AUTHORIZATION_RESULT_REJECT; | 158 return HttpAuth::AUTHORIZATION_RESULT_REJECT; |
| 159 } | 159 } |
| 160 | 160 |
| 161 // static | 161 // static |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 // static | 200 // static |
| 201 bool HttpAuth::IsValidNormalizedScheme(const std::string& scheme) { | 201 bool HttpAuth::IsValidNormalizedScheme(const std::string& scheme) { |
| 202 return HttpUtil::IsToken(scheme.begin(), scheme.end()) && | 202 return HttpUtil::IsToken(scheme.begin(), scheme.end()) && |
| 203 base::ToLowerASCII(scheme) == scheme; | 203 base::ToLowerASCII(scheme) == scheme; |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace net | 206 } // namespace net |
| OLD | NEW |