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

Side by Side Diff: net/http/http_auth_handler_basic.cc

Issue 1157333005: [net/http auth] Use strings to identify authentication schemes. Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 unified diff | Download patch
« no previous file with comments | « net/http/http_auth_handler.cc ('k') | net/http/http_auth_handler_digest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_handler_basic.h" 5 #include "net/http/http_auth_handler_basic.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/net_string_util.h" 13 #include "net/base/net_string_util.h"
14 #include "net/http/http_auth.h" 14 #include "net/http/http_auth.h"
15 #include "net/http/http_auth_challenge_tokenizer.h" 15 #include "net/http/http_auth_challenge_tokenizer.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 namespace { 19 namespace {
20 20
21 const char* const kBasicSchemeName = "basic";
22
21 // Parses a realm from an auth challenge, and converts to UTF8-encoding. 23 // Parses a realm from an auth challenge, and converts to UTF8-encoding.
22 // Returns whether the realm is invalid or the parameters are invalid. 24 // Returns whether the realm is invalid or the parameters are invalid.
23 // 25 //
24 // Note that if a realm was not specified, we will default it to ""; 26 // Note that if a realm was not specified, we will default it to "";
25 // so specifying 'Basic realm=""' is equivalent to 'Basic'. 27 // so specifying 'Basic realm=""' is equivalent to 'Basic'.
26 // 28 //
27 // This is more generous than RFC 2617, which is pretty clear in the 29 // This is more generous than RFC 2617, which is pretty clear in the
28 // production of challenge that realm is required. 30 // production of challenge that realm is required.
29 // 31 //
30 // We allow it to be compatibility with certain embedded webservers that don't 32 // We allow it to be compatibility with certain embedded webservers that don't
(...skipping 15 matching lines...) Expand all
46 if (!ConvertToUtf8AndNormalize(parameters.value(), kCharsetLatin1, realm)) { 48 if (!ConvertToUtf8AndNormalize(parameters.value(), kCharsetLatin1, realm)) {
47 return false; 49 return false;
48 } 50 }
49 } 51 }
50 return parameters.valid(); 52 return parameters.valid();
51 } 53 }
52 54
53 } // namespace 55 } // namespace
54 56
55 bool HttpAuthHandlerBasic::Init(HttpAuthChallengeTokenizer* challenge) { 57 bool HttpAuthHandlerBasic::Init(HttpAuthChallengeTokenizer* challenge) {
56 auth_scheme_ = HttpAuth::AUTH_SCHEME_BASIC; 58 auth_scheme_ = kBasicSchemeName;
57 score_ = 1;
58 properties_ = 0;
59 return ParseChallenge(challenge); 59 return ParseChallenge(challenge);
60 } 60 }
61 61
62 bool HttpAuthHandlerBasic::ParseChallenge( 62 bool HttpAuthHandlerBasic::ParseChallenge(
63 HttpAuthChallengeTokenizer* challenge) { 63 HttpAuthChallengeTokenizer* challenge) {
64 // Verify the challenge's auth-scheme. 64 // Verify the challenge's auth-scheme.
65 if (!base::LowerCaseEqualsASCII(challenge->scheme(), "basic")) 65 if (!challenge->SchemeIs(kBasicSchemeName))
66 return false; 66 return false;
67 67
68 std::string realm; 68 std::string realm;
69 if (!ParseRealm(*challenge, &realm)) 69 if (!ParseRealm(*challenge, &realm))
70 return false; 70 return false;
71 71
72 realm_ = realm; 72 realm_ = realm;
73 return true; 73 return true;
74 } 74 }
75 75
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // TODO(cbentzel): Move towards model of parsing in the factory 116 // TODO(cbentzel): Move towards model of parsing in the factory
117 // method and only constructing when valid. 117 // method and only constructing when valid.
118 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic()); 118 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic());
119 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) 119 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
120 return ERR_INVALID_RESPONSE; 120 return ERR_INVALID_RESPONSE;
121 handler->swap(tmp_handler); 121 handler->swap(tmp_handler);
122 return OK; 122 return OK;
123 } 123 }
124 124
125 } // namespace net 125 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler.cc ('k') | net/http/http_auth_handler_digest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698