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

Unified Diff: net/http/http_auth_handler_digest.cc

Issue 1393693002: [net/http auth] Split HttpAuthHandler creation from initialization. Base URL: https://chromium.googlesource.com/chromium/src.git@rename-auth-handler-methods
Patch Set: Created 5 years, 2 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_handler_digest.h ('k') | net/http/http_auth_handler_digest_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_auth_handler_digest.cc
diff --git a/net/http/http_auth_handler_digest.cc b/net/http/http_auth_handler_digest.cc
index c74b3da58c43905d1b600a5816fc96bf51854e08..8c8787f6500502a868c8514754cdd062c90e8cb3 100644
--- a/net/http/http_auth_handler_digest.cc
+++ b/net/http/http_auth_handler_digest.cc
@@ -23,7 +23,7 @@
namespace net {
-static const char* const kDigestSchemeName = "digest";
+static const char kDigestSchemeName[] = "digest";
// Digest authentication is specified in RFC 2617.
// The expanded derivations are listed in the tables below.
@@ -79,37 +79,6 @@ std::string HttpAuthHandlerDigest::FixedNonceGenerator::GenerateNonce() const {
return nonce_;
}
-HttpAuthHandlerDigest::Factory::Factory()
- : nonce_generator_(new DynamicNonceGenerator()) {
-}
-
-HttpAuthHandlerDigest::Factory::~Factory() {
-}
-
-void HttpAuthHandlerDigest::Factory::set_nonce_generator(
- const NonceGenerator* nonce_generator) {
- nonce_generator_.reset(nonce_generator);
-}
-
-int HttpAuthHandlerDigest::Factory::CreateAuthHandler(
- const HttpAuthChallengeTokenizer& challenge,
- HttpAuth::Target target,
- const GURL& origin,
- CreateReason reason,
- int digest_nonce_count,
- const BoundNetLog& net_log,
- scoped_ptr<HttpAuthHandler>* handler) {
- // TODO(cbentzel): Move towards model of parsing in the factory
- // method and only constructing when valid.
- scoped_ptr<HttpAuthHandler> tmp_handler(
- new HttpAuthHandlerDigest(digest_nonce_count, nonce_generator_.get()));
- int result =
- tmp_handler->HandleInitialChallenge(challenge, target, origin, net_log);
- if (result == OK)
- handler->swap(tmp_handler);
- return result;
-}
-
HttpAuth::AuthorizationResult HttpAuthHandlerDigest::HandleAnotherChallenge(
const HttpAuthChallengeTokenizer& challenge) {
// Even though Digest is not connection based, a "second round" is parsed
@@ -161,8 +130,10 @@ int HttpAuthHandlerDigest::GenerateAuthTokenImpl(
}
HttpAuthHandlerDigest::HttpAuthHandlerDigest(
- int nonce_count, const NonceGenerator* nonce_generator)
- : stale_(false),
+ int nonce_count,
+ const NonceGenerator* nonce_generator)
+ : HttpAuthHandler(kDigestSchemeName),
+ stale_(false),
algorithm_(ALGORITHM_UNSPECIFIED),
qop_(QOP_UNSPECIFIED),
nonce_count_(nonce_count),
@@ -193,7 +164,9 @@ HttpAuthHandlerDigest::~HttpAuthHandlerDigest() {
// webserver was not sending the realm with a BASIC challenge).
bool HttpAuthHandlerDigest::ParseChallenge(
const HttpAuthChallengeTokenizer& challenge) {
- auth_scheme_ = kDigestSchemeName;
+ // FAIL -- Couldn't match auth-scheme.
+ if (!challenge.SchemeIs(kDigestSchemeName))
+ return false;
// Initialize to defaults.
stale_ = false;
@@ -201,10 +174,6 @@ bool HttpAuthHandlerDigest::ParseChallenge(
qop_ = QOP_UNSPECIFIED;
realm_ = original_realm_ = nonce_ = domain_ = opaque_ = std::string();
- // FAIL -- Couldn't match auth-scheme.
- if (!challenge.SchemeIs(kDigestSchemeName))
- return false;
-
HttpUtil::NameValuePairsIterator parameters = challenge.param_pairs();
// Loop through all the properties.
@@ -381,4 +350,40 @@ std::string HttpAuthHandlerDigest::AssembleCredentials(
return authorization;
}
+HttpAuthHandlerDigest::Factory::Factory()
+ : nonce_generator_(new DynamicNonceGenerator()) {}
+
+HttpAuthHandlerDigest::Factory::~Factory() {}
+
+void HttpAuthHandlerDigest::Factory::set_nonce_generator(
+ const NonceGenerator* nonce_generator) {
+ nonce_generator_.reset(nonce_generator);
+}
+
+scoped_ptr<HttpAuthHandler>
+HttpAuthHandlerDigest::Factory::CreateAuthHandlerForScheme(
+ const std::string& scheme) {
+ DCHECK(HttpAuth::IsValidNormalizedScheme(scheme));
+ if (scheme != kDigestSchemeName)
+ return scoped_ptr<HttpAuthHandler>();
+ return make_scoped_ptr(new HttpAuthHandlerDigest(1, nonce_generator_.get()));
+}
+
+scoped_ptr<HttpAuthHandler>
+HttpAuthHandlerDigest::Factory::CreateAndInitPreemptiveAuthHandler(
+ HttpAuthCache::Entry* cache_entry,
+ const HttpAuthChallengeTokenizer& tokenizer,
+ HttpAuth::Target target,
+ const BoundNetLog& net_log) {
+ if (cache_entry->scheme() != kDigestSchemeName)
+ return scoped_ptr<HttpAuthHandler>();
+ scoped_ptr<HttpAuthHandler> handler(new HttpAuthHandlerDigest(
+ cache_entry->IncrementNonceCount(), nonce_generator_.get()));
+ int rv = handler->HandleInitialChallenge(tokenizer, target,
+ cache_entry->origin(), net_log);
+ if (rv == OK)
+ return handler;
+ return scoped_ptr<HttpAuthHandler>();
+}
+
} // namespace net
« no previous file with comments | « net/http/http_auth_handler_digest.h ('k') | net/http/http_auth_handler_digest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698