OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 const HttpResponseHeaders* headers, | 24 const HttpResponseHeaders* headers, |
25 Target target, | 25 Target target, |
26 const GURL& origin, | 26 const GURL& origin, |
27 const std::set<std::string>& disabled_schemes, | 27 const std::set<std::string>& disabled_schemes, |
28 const BoundNetLog& net_log, | 28 const BoundNetLog& net_log, |
29 scoped_ptr<HttpAuthHandler>* handler) { | 29 scoped_ptr<HttpAuthHandler>* handler) { |
30 DCHECK(http_auth_handler_factory); | 30 DCHECK(http_auth_handler_factory); |
31 | 31 |
32 // A connection-based authentication scheme must continue to use the | 32 // A connection-based authentication scheme must continue to use the |
33 // existing handler object in |*handler|. | 33 // existing handler object in |*handler|. |
34 if (handler->get() && (*handler)->is_connection_based()) { | 34 if (handler->get() && (*handler)->is_connection_based() && |
| 35 (disabled_schemes.find((*handler)->scheme()) == disabled_schemes.end())) { |
35 const std::string header_name = GetChallengeHeaderName(target); | 36 const std::string header_name = GetChallengeHeaderName(target); |
36 std::string challenge; | 37 std::string challenge; |
37 void* iter = NULL; | 38 void* iter = NULL; |
38 while (headers->EnumerateHeader(&iter, header_name, &challenge)) { | 39 while (headers->EnumerateHeader(&iter, header_name, &challenge)) { |
39 ChallengeTokenizer props(challenge.begin(), challenge.end()); | 40 ChallengeTokenizer props(challenge.begin(), challenge.end()); |
40 if (LowerCaseEqualsASCII(props.scheme(), (*handler)->scheme().c_str()) && | 41 if (LowerCaseEqualsASCII(props.scheme(), (*handler)->scheme().c_str()) && |
41 (*handler)->InitFromChallenge(&props, target, origin, net_log)) | 42 (*handler)->InitFromChallenge(&props, target, origin, net_log)) |
42 return; | 43 return; |
43 } | 44 } |
44 } | 45 } |
45 | 46 |
46 // Choose the challenge whose authentication handler gives the maximum score. | 47 // Choose the challenge whose authentication handler gives the maximum score. |
47 scoped_ptr<HttpAuthHandler> best; | 48 scoped_ptr<HttpAuthHandler> best; |
48 const std::string header_name = GetChallengeHeaderName(target); | 49 const std::string header_name = GetChallengeHeaderName(target); |
49 std::string cur_challenge; | 50 std::string cur_challenge; |
50 void* iter = NULL; | 51 void* iter = NULL; |
51 while (headers->EnumerateHeader(&iter, header_name, &cur_challenge)) { | 52 while (headers->EnumerateHeader(&iter, header_name, &cur_challenge)) { |
52 scoped_ptr<HttpAuthHandler> cur; | 53 scoped_ptr<HttpAuthHandler> cur; |
53 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( | 54 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( |
54 cur_challenge, target, origin, net_log, &cur); | 55 cur_challenge, target, origin, net_log, &cur); |
55 if (rv != OK) { | 56 if (rv != OK) { |
56 LOG(WARNING) << "Unable to create AuthHandler. Status: " | 57 LOG(WARNING) << "Unable to create AuthHandler. Status: " |
57 << ErrorToString(rv) << " Challenge: " << cur_challenge; | 58 << ErrorToString(rv) << " Challenge: " << cur_challenge; |
58 continue; | 59 continue; |
59 } | 60 } |
60 if (cur.get() && (!best.get() || best->score() < cur->score())) { | 61 if (cur.get() && (!best.get() || best->score() < cur->score()) && |
61 if (disabled_schemes.find(cur->scheme()) == disabled_schemes.end()) | 62 (disabled_schemes.find(cur->scheme()) == disabled_schemes.end())) |
62 best.swap(cur); | 63 best.swap(cur); |
63 } | |
64 } | 64 } |
65 handler->swap(best); | 65 handler->swap(best); |
66 } | 66 } |
67 | 67 |
68 void HttpAuth::ChallengeTokenizer::Init(std::string::const_iterator begin, | 68 void HttpAuth::ChallengeTokenizer::Init(std::string::const_iterator begin, |
69 std::string::const_iterator end) { | 69 std::string::const_iterator end) { |
70 // The first space-separated token is the auth-scheme. | 70 // The first space-separated token is the auth-scheme. |
71 // NOTE: we are more permissive than RFC 2617 which says auth-scheme | 71 // NOTE: we are more permissive than RFC 2617 which says auth-scheme |
72 // is separated by 1*SP. | 72 // is separated by 1*SP. |
73 StringTokenizer tok(begin, end, HTTP_LWS); | 73 StringTokenizer tok(begin, end, HTTP_LWS); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 // static | 175 // static |
176 std::string HttpAuth::GetAuthTargetString( | 176 std::string HttpAuth::GetAuthTargetString( |
177 HttpAuth::Target target) { | 177 HttpAuth::Target target) { |
178 return target == HttpAuth::AUTH_PROXY ? "proxy" : "server"; | 178 return target == HttpAuth::AUTH_PROXY ? "proxy" : "server"; |
179 } | 179 } |
180 | 180 |
181 } // namespace net | 181 } // namespace net |
OLD | NEW |