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

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

Issue 6314010: Even more reordering the methods in headers and implementation in net/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/disk_cache_test_util.h ('k') | net/http/http_auth_cache.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/string_util.h" 10 #include "base/string_util.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 authorization_result = handler->HandleAnotherChallenge(&props); 80 authorization_result = handler->HandleAnotherChallenge(&props);
81 if (authorization_result != HttpAuth::AUTHORIZATION_RESULT_INVALID) { 81 if (authorization_result != HttpAuth::AUTHORIZATION_RESULT_INVALID) {
82 *challenge_used = challenge; 82 *challenge_used = challenge;
83 return authorization_result; 83 return authorization_result;
84 } 84 }
85 } 85 }
86 // Finding no matches is equivalent to rejection. 86 // Finding no matches is equivalent to rejection.
87 return HttpAuth::AUTHORIZATION_RESULT_REJECT; 87 return HttpAuth::AUTHORIZATION_RESULT_REJECT;
88 } 88 }
89 89
90 HttpUtil::NameValuePairsIterator HttpAuth::ChallengeTokenizer::param_pairs()
91 const {
92 return HttpUtil::NameValuePairsIterator(params_begin_, params_end_, ',');
93 }
94
95 std::string HttpAuth::ChallengeTokenizer::base64_param() const {
96 // Strip off any padding.
97 // (See https://bugzilla.mozilla.org/show_bug.cgi?id=230351.)
98 //
99 // Our base64 decoder requires that the length be a multiple of 4.
100 int encoded_length = params_end_ - params_begin_;
101 while (encoded_length > 0 && encoded_length % 4 != 0 &&
102 params_begin_[encoded_length - 1] == '=') {
103 --encoded_length;
104 }
105 return std::string(params_begin_, params_begin_ + encoded_length);
106 }
107
90 void HttpAuth::ChallengeTokenizer::Init(std::string::const_iterator begin, 108 void HttpAuth::ChallengeTokenizer::Init(std::string::const_iterator begin,
91 std::string::const_iterator end) { 109 std::string::const_iterator end) {
92 // The first space-separated token is the auth-scheme. 110 // The first space-separated token is the auth-scheme.
93 // NOTE: we are more permissive than RFC 2617 which says auth-scheme 111 // NOTE: we are more permissive than RFC 2617 which says auth-scheme
94 // is separated by 1*SP. 112 // is separated by 1*SP.
95 StringTokenizer tok(begin, end, HTTP_LWS); 113 StringTokenizer tok(begin, end, HTTP_LWS);
96 if (!tok.GetNext()) { 114 if (!tok.GetNext()) {
97 // Default param and scheme iterators provide empty strings 115 // Default param and scheme iterators provide empty strings
98 return; 116 return;
99 } 117 }
100 118
101 // Save the scheme's position. 119 // Save the scheme's position.
102 scheme_begin_ = tok.token_begin(); 120 scheme_begin_ = tok.token_begin();
103 scheme_end_ = tok.token_end(); 121 scheme_end_ = tok.token_end();
104 122
105 params_begin_ = scheme_end_; 123 params_begin_ = scheme_end_;
106 params_end_ = end; 124 params_end_ = end;
107 HttpUtil::TrimLWS(&params_begin_, &params_end_); 125 HttpUtil::TrimLWS(&params_begin_, &params_end_);
108 } 126 }
109 127
110 HttpUtil::NameValuePairsIterator HttpAuth::ChallengeTokenizer::param_pairs()
111 const {
112 return HttpUtil::NameValuePairsIterator(params_begin_, params_end_, ',');
113 }
114
115 std::string HttpAuth::ChallengeTokenizer::base64_param() const {
116 // Strip off any padding.
117 // (See https://bugzilla.mozilla.org/show_bug.cgi?id=230351.)
118 //
119 // Our base64 decoder requires that the length be a multiple of 4.
120 int encoded_length = params_end_ - params_begin_;
121 while (encoded_length > 0 && encoded_length % 4 != 0 &&
122 params_begin_[encoded_length - 1] == '=') {
123 --encoded_length;
124 }
125 return std::string(params_begin_, params_begin_ + encoded_length);
126 }
127
128 // static 128 // static
129 std::string HttpAuth::GetChallengeHeaderName(Target target) { 129 std::string HttpAuth::GetChallengeHeaderName(Target target) {
130 switch (target) { 130 switch (target) {
131 case AUTH_PROXY: 131 case AUTH_PROXY:
132 return "Proxy-Authenticate"; 132 return "Proxy-Authenticate";
133 case AUTH_SERVER: 133 case AUTH_SERVER:
134 return "WWW-Authenticate"; 134 return "WWW-Authenticate";
135 default: 135 default:
136 NOTREACHED(); 136 NOTREACHED();
137 return ""; 137 return "";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 COMPILE_ASSERT(arraysize(kSchemeNames) == AUTH_SCHEME_MAX, 176 COMPILE_ASSERT(arraysize(kSchemeNames) == AUTH_SCHEME_MAX,
177 http_auth_scheme_names_incorrect_size); 177 http_auth_scheme_names_incorrect_size);
178 if (scheme < AUTH_SCHEME_BASIC || scheme >= AUTH_SCHEME_MAX) { 178 if (scheme < AUTH_SCHEME_BASIC || scheme >= AUTH_SCHEME_MAX) {
179 NOTREACHED(); 179 NOTREACHED();
180 return "invalid_scheme"; 180 return "invalid_scheme";
181 } 181 }
182 return kSchemeNames[scheme]; 182 return kSchemeNames[scheme];
183 } 183 }
184 184
185 } // namespace net 185 } // namespace net
OLDNEW
« no previous file with comments | « net/disk_cache/disk_cache_test_util.h ('k') | net/http/http_auth_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698