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_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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // The over-the-wire realm is encoded as ISO-8859-1 (aka Latin-1). | 33 // The over-the-wire realm is encoded as ISO-8859-1 (aka Latin-1). |
34 // | 34 // |
35 // TODO(cbentzel): Realm may need to be decoded using RFC 2047 rules as | 35 // TODO(cbentzel): Realm may need to be decoded using RFC 2047 rules as |
36 // well, see http://crbug.com/25790. | 36 // well, see http://crbug.com/25790. |
37 bool ParseRealm(const HttpAuthChallengeTokenizer& tokenizer, | 37 bool ParseRealm(const HttpAuthChallengeTokenizer& tokenizer, |
38 std::string* realm) { | 38 std::string* realm) { |
39 CHECK(realm); | 39 CHECK(realm); |
40 realm->clear(); | 40 realm->clear(); |
41 HttpUtil::NameValuePairsIterator parameters = tokenizer.param_pairs(); | 41 HttpUtil::NameValuePairsIterator parameters = tokenizer.param_pairs(); |
42 while (parameters.GetNext()) { | 42 while (parameters.GetNext()) { |
43 if (!base::LowerCaseEqualsASCII(parameters.name(), "realm")) | 43 if (!LowerCaseEqualsASCII(parameters.name(), "realm")) |
44 continue; | 44 continue; |
45 | 45 |
46 if (!net::ConvertToUtf8AndNormalize(parameters.value(), kCharsetLatin1, | 46 if (!net::ConvertToUtf8AndNormalize(parameters.value(), kCharsetLatin1, |
47 realm)) { | 47 realm)) { |
48 return false; | 48 return false; |
49 } | 49 } |
50 } | 50 } |
51 return parameters.valid(); | 51 return parameters.valid(); |
52 } | 52 } |
53 | 53 |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 bool HttpAuthHandlerBasic::Init(HttpAuthChallengeTokenizer* challenge) { | 56 bool HttpAuthHandlerBasic::Init(HttpAuthChallengeTokenizer* challenge) { |
57 auth_scheme_ = HttpAuth::AUTH_SCHEME_BASIC; | 57 auth_scheme_ = HttpAuth::AUTH_SCHEME_BASIC; |
58 score_ = 1; | 58 score_ = 1; |
59 properties_ = 0; | 59 properties_ = 0; |
60 return ParseChallenge(challenge); | 60 return ParseChallenge(challenge); |
61 } | 61 } |
62 | 62 |
63 bool HttpAuthHandlerBasic::ParseChallenge( | 63 bool HttpAuthHandlerBasic::ParseChallenge( |
64 HttpAuthChallengeTokenizer* challenge) { | 64 HttpAuthChallengeTokenizer* challenge) { |
65 // Verify the challenge's auth-scheme. | 65 // Verify the challenge's auth-scheme. |
66 if (!base::LowerCaseEqualsASCII(challenge->scheme(), "basic")) | 66 if (!LowerCaseEqualsASCII(challenge->scheme(), "basic")) |
67 return false; | 67 return false; |
68 | 68 |
69 std::string realm; | 69 std::string realm; |
70 if (!ParseRealm(*challenge, &realm)) | 70 if (!ParseRealm(*challenge, &realm)) |
71 return false; | 71 return false; |
72 | 72 |
73 realm_ = realm; | 73 realm_ = realm; |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // TODO(cbentzel): Move towards model of parsing in the factory | 117 // TODO(cbentzel): Move towards model of parsing in the factory |
118 // method and only constructing when valid. | 118 // method and only constructing when valid. |
119 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic()); | 119 scoped_ptr<HttpAuthHandler> tmp_handler(new HttpAuthHandlerBasic()); |
120 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) | 120 if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log)) |
121 return ERR_INVALID_RESPONSE; | 121 return ERR_INVALID_RESPONSE; |
122 handler->swap(tmp_handler); | 122 handler->swap(tmp_handler); |
123 return OK; | 123 return OK; |
124 } | 124 } |
125 | 125 |
126 } // namespace net | 126 } // namespace net |
OLD | NEW |