Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: net/http/http_auth.cc

Issue 6191001: Cleanup: Use AUTH_SCHEME enum instead of a string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Merge with trunk Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_auth.h ('k') | net/http/http_auth_cache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_auth.cc
===================================================================
--- net/http/http_auth.cc (revision 71164)
+++ net/http/http_auth.cc (working copy)
@@ -26,7 +26,7 @@
const HttpResponseHeaders* headers,
Target target,
const GURL& origin,
- const std::set<std::string>& disabled_schemes,
+ const std::set<Scheme>& disabled_schemes,
const BoundNetLog& net_log,
scoped_ptr<HttpAuthHandler>* handler) {
DCHECK(http_auth_handler_factory);
@@ -47,7 +47,7 @@
continue;
}
if (cur.get() && (!best.get() || best->score() < cur->score()) &&
- (disabled_schemes.find(cur->scheme()) == disabled_schemes.end()))
+ (disabled_schemes.find(cur->auth_scheme()) == disabled_schemes.end()))
best.swap(cur);
}
handler->swap(best);
@@ -58,15 +58,16 @@
HttpAuthHandler* handler,
const HttpResponseHeaders* headers,
Target target,
- const std::set<std::string>& disabled_schemes,
+ const std::set<Scheme>& disabled_schemes,
std::string* challenge_used) {
DCHECK(handler);
DCHECK(headers);
DCHECK(challenge_used);
challenge_used->clear();
- const std::string& current_scheme = handler->scheme();
+ HttpAuth::Scheme current_scheme = handler->auth_scheme();
if (disabled_schemes.find(current_scheme) != disabled_schemes.end())
return HttpAuth::AUTHORIZATION_RESULT_REJECT;
+ std::string current_scheme_name = SchemeToString(current_scheme);
const std::string header_name = GetChallengeHeaderName(target);
void* iter = NULL;
std::string challenge;
@@ -74,7 +75,7 @@
HttpAuth::AUTHORIZATION_RESULT_INVALID;
while (headers->EnumerateHeader(&iter, header_name, &challenge)) {
HttpAuth::ChallengeTokenizer props(challenge.begin(), challenge.end());
- if (!LowerCaseEqualsASCII(props.scheme(), current_scheme.c_str()))
+ if (!LowerCaseEqualsASCII(props.scheme(), current_scheme_name.c_str()))
continue;
authorization_result = handler->HandleAnotherChallenge(&props);
if (authorization_result != HttpAuth::AUTHORIZATION_RESULT_INVALID) {
@@ -151,9 +152,34 @@
}
// static
-std::string HttpAuth::GetAuthTargetString(
- HttpAuth::Target target) {
- return target == HttpAuth::AUTH_PROXY ? "proxy" : "server";
+std::string HttpAuth::GetAuthTargetString(Target target) {
+ switch (target) {
+ case AUTH_PROXY:
+ return "proxy";
+ case AUTH_SERVER:
+ return "server";
+ default:
+ NOTREACHED();
+ return "";
+ }
}
+// static
+const char* HttpAuth::SchemeToString(Scheme scheme) {
+ static const char* const kSchemeNames[] = {
+ "basic",
+ "digest",
+ "ntlm",
+ "negotiate",
+ "mock",
+ };
+ COMPILE_ASSERT(arraysize(kSchemeNames) == AUTH_SCHEME_MAX,
+ http_auth_scheme_names_incorrect_size);
+ if (scheme < AUTH_SCHEME_BASIC || scheme >= AUTH_SCHEME_MAX) {
+ NOTREACHED();
+ return "invalid_scheme";
+ }
+ return kSchemeNames[scheme];
+}
+
} // namespace net
« no previous file with comments | « net/http/http_auth.h ('k') | net/http/http_auth_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698