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/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/http/http_auth_challenge_tokenizer.h" | 13 #include "net/http/http_auth_challenge_tokenizer.h" |
14 #include "net/http/http_auth_handler.h" | 14 #include "net/http/http_auth_handler.h" |
15 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
16 #include "net/http/http_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
18 #include "net/http/http_util.h" | 18 #include "net/http/http_util.h" |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 HttpAuth::Identity::Identity() : source(IDENT_SRC_NONE), invalid(true) {} | 22 HttpAuth::Identity::Identity() : source(IDENT_SRC_NONE), invalid(true) { |
| 23 } |
23 | 24 |
24 // static | 25 // static |
25 void HttpAuth::ChooseBestChallenge( | 26 void HttpAuth::ChooseBestChallenge( |
26 HttpAuthHandlerFactory* http_auth_handler_factory, | 27 HttpAuthHandlerFactory* http_auth_handler_factory, |
27 const HttpResponseHeaders* headers, | 28 const HttpResponseHeaders* headers, |
28 Target target, | 29 Target target, |
29 const GURL& origin, | 30 const GURL& origin, |
30 const std::set<Scheme>& disabled_schemes, | 31 const std::set<Scheme>& disabled_schemes, |
31 const BoundNetLog& net_log, | 32 const BoundNetLog& net_log, |
32 scoped_ptr<HttpAuthHandler>* handler) { | 33 scoped_ptr<HttpAuthHandler>* handler) { |
33 DCHECK(http_auth_handler_factory); | 34 DCHECK(http_auth_handler_factory); |
34 DCHECK(handler->get() == NULL); | 35 DCHECK(handler->get() == NULL); |
35 | 36 |
36 // Choose the challenge whose authentication handler gives the maximum score. | 37 // Choose the challenge whose authentication handler gives the maximum score. |
37 scoped_ptr<HttpAuthHandler> best; | 38 scoped_ptr<HttpAuthHandler> best; |
38 const std::string header_name = GetChallengeHeaderName(target); | 39 const std::string header_name = GetChallengeHeaderName(target); |
39 std::string cur_challenge; | 40 std::string cur_challenge; |
40 void* iter = NULL; | 41 void* iter = NULL; |
41 while (headers->EnumerateHeader(&iter, header_name, &cur_challenge)) { | 42 while (headers->EnumerateHeader(&iter, header_name, &cur_challenge)) { |
42 scoped_ptr<HttpAuthHandler> cur; | 43 scoped_ptr<HttpAuthHandler> cur; |
43 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( | 44 int rv = http_auth_handler_factory->CreateAuthHandlerFromString( |
44 cur_challenge, target, origin, net_log, &cur); | 45 cur_challenge, target, origin, net_log, &cur); |
45 if (rv != OK) { | 46 if (rv != OK) { |
46 VLOG(1) << "Unable to create AuthHandler. Status: " | 47 VLOG(1) << "Unable to create AuthHandler. Status: " << ErrorToString(rv) |
47 << ErrorToString(rv) << " Challenge: " << cur_challenge; | 48 << " Challenge: " << cur_challenge; |
48 continue; | 49 continue; |
49 } | 50 } |
50 if (cur.get() && (!best.get() || best->score() < cur->score()) && | 51 if (cur.get() && (!best.get() || best->score() < cur->score()) && |
51 (disabled_schemes.find(cur->auth_scheme()) == disabled_schemes.end())) | 52 (disabled_schemes.find(cur->auth_scheme()) == disabled_schemes.end())) |
52 best.swap(cur); | 53 best.swap(cur); |
53 } | 54 } |
54 handler->swap(best); | 55 handler->swap(best); |
55 } | 56 } |
56 | 57 |
57 // static | 58 // static |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return "server"; | 124 return "server"; |
124 default: | 125 default: |
125 NOTREACHED(); | 126 NOTREACHED(); |
126 return std::string(); | 127 return std::string(); |
127 } | 128 } |
128 } | 129 } |
129 | 130 |
130 // static | 131 // static |
131 const char* HttpAuth::SchemeToString(Scheme scheme) { | 132 const char* HttpAuth::SchemeToString(Scheme scheme) { |
132 static const char* const kSchemeNames[] = { | 133 static const char* const kSchemeNames[] = { |
133 "basic", | 134 "basic", "digest", "ntlm", "negotiate", "spdyproxy", "mock", |
134 "digest", | |
135 "ntlm", | |
136 "negotiate", | |
137 "spdyproxy", | |
138 "mock", | |
139 }; | 135 }; |
140 COMPILE_ASSERT(arraysize(kSchemeNames) == AUTH_SCHEME_MAX, | 136 COMPILE_ASSERT(arraysize(kSchemeNames) == AUTH_SCHEME_MAX, |
141 http_auth_scheme_names_incorrect_size); | 137 http_auth_scheme_names_incorrect_size); |
142 if (scheme < AUTH_SCHEME_BASIC || scheme >= AUTH_SCHEME_MAX) { | 138 if (scheme < AUTH_SCHEME_BASIC || scheme >= AUTH_SCHEME_MAX) { |
143 NOTREACHED(); | 139 NOTREACHED(); |
144 return "invalid_scheme"; | 140 return "invalid_scheme"; |
145 } | 141 } |
146 return kSchemeNames[scheme]; | 142 return kSchemeNames[scheme]; |
147 } | 143 } |
148 | 144 |
149 } // namespace net | 145 } // namespace net |
OLD | NEW |