| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ | 5 #ifndef NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ |
| 6 #define NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ | 6 #define NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 virtual ~HttpNetworkTransaction(); | 35 virtual ~HttpNetworkTransaction(); |
| 36 | 36 |
| 37 // HttpTransaction methods: | 37 // HttpTransaction methods: |
| 38 virtual int Start(const HttpRequestInfo* request_info, | 38 virtual int Start(const HttpRequestInfo* request_info, |
| 39 CompletionCallback* callback); | 39 CompletionCallback* callback); |
| 40 virtual int RestartIgnoringLastError(CompletionCallback* callback); | 40 virtual int RestartIgnoringLastError(CompletionCallback* callback); |
| 41 virtual int RestartWithAuth(const std::wstring& username, | 41 virtual int RestartWithAuth(const std::wstring& username, |
| 42 const std::wstring& password, | 42 const std::wstring& password, |
| 43 CompletionCallback* callback); | 43 CompletionCallback* callback); |
| 44 virtual bool IsReadyToRestartForAuth() { |
| 45 return pending_auth_target_ != HttpAuth::AUTH_NONE && |
| 46 HaveAuth(pending_auth_target_); |
| 47 } |
| 48 |
| 44 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); | 49 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); |
| 45 virtual const HttpResponseInfo* GetResponseInfo() const; | 50 virtual const HttpResponseInfo* GetResponseInfo() const; |
| 46 virtual LoadState GetLoadState() const; | 51 virtual LoadState GetLoadState() const; |
| 47 virtual uint64 GetUploadProgress() const; | 52 virtual uint64 GetUploadProgress() const; |
| 48 | 53 |
| 49 private: | 54 private: |
| 50 FRIEND_TEST(HttpNetworkTransactionTest, ResetStateForRestart); | 55 FRIEND_TEST(HttpNetworkTransactionTest, ResetStateForRestart); |
| 51 | 56 |
| 52 void BuildRequestHeaders(); | 57 void BuildRequestHeaders(); |
| 53 void BuildTunnelRequest(); | 58 void BuildTunnelRequest(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void ResetStateForRestart(); | 150 void ResetStateForRestart(); |
| 146 | 151 |
| 147 // Attach any credentials needed for the proxy server or origin server. | 152 // Attach any credentials needed for the proxy server or origin server. |
| 148 void ApplyAuth(); | 153 void ApplyAuth(); |
| 149 | 154 |
| 150 // Helper used by ApplyAuth(). Adds either the proxy auth header, or the | 155 // Helper used by ApplyAuth(). Adds either the proxy auth header, or the |
| 151 // origin server auth header, as specified by |target| | 156 // origin server auth header, as specified by |target| |
| 152 void AddAuthorizationHeader(HttpAuth::Target target); | 157 void AddAuthorizationHeader(HttpAuth::Target target); |
| 153 | 158 |
| 154 // Handles HTTP status code 401 or 407. | 159 // Handles HTTP status code 401 or 407. |
| 155 // HandleAuthChallenge() returns a network error code, or OK, or | 160 // HandleAuthChallenge() returns a network error code, or OK on success. |
| 156 // WILL_RESTART_TRANSACTION. The latter indicates that the state machine has | 161 // May update |pending_auth_target_| or |response_.auth_challenge|. |
| 157 // been updated to restart the transaction with a new auth attempt. | |
| 158 enum { WILL_RESTART_TRANSACTION = 1 }; | |
| 159 int HandleAuthChallenge(); | 162 int HandleAuthChallenge(); |
| 160 | 163 |
| 161 // Populates response_.auth_challenge with the challenge information, so that | 164 // Populates response_.auth_challenge with the challenge information, so that |
| 162 // URLRequestHttpJob can prompt for a username/password. | 165 // URLRequestHttpJob can prompt for a username/password. |
| 163 void PopulateAuthChallenge(HttpAuth::Target target); | 166 void PopulateAuthChallenge(HttpAuth::Target target); |
| 164 | 167 |
| 165 // Invalidates any auth cache entries after authentication has failed. | 168 // Invalidates any auth cache entries after authentication has failed. |
| 166 // The identity that was rejected is auth_identity_[target]. | 169 // The identity that was rejected is auth_identity_[target]. |
| 167 void InvalidateRejectedAuthFromCache(HttpAuth::Target target); | 170 void InvalidateRejectedAuthFromCache(HttpAuth::Target target); |
| 168 | 171 |
| 169 // Sets auth_identity_[target] to the next identity that the transaction | 172 // Sets auth_identity_[target] to the next identity that the transaction |
| 170 // should try. It chooses candidates by searching the auth cache | 173 // should try. It chooses candidates by searching the auth cache |
| 171 // and the URL for a username:password. Returns true if an identity | 174 // and the URL for a username:password. Returns true if an identity |
| 172 // was found. | 175 // was found. |
| 173 bool SelectNextAuthIdentityToTry(HttpAuth::Target target); | 176 bool SelectNextAuthIdentityToTry(HttpAuth::Target target); |
| 174 | 177 |
| 175 // Searches the auth cache for an entry that encompasses the request's path. | 178 // Searches the auth cache for an entry that encompasses the request's path. |
| 176 // If such an entry is found, updates auth_identity_[target] and | 179 // If such an entry is found, updates auth_identity_[target] and |
| 177 // auth_handler_[target] with the cache entry's data and returns true. | 180 // auth_handler_[target] with the cache entry's data and returns true. |
| 178 bool SelectPreemptiveAuth(HttpAuth::Target target); | 181 bool SelectPreemptiveAuth(HttpAuth::Target target); |
| 179 | 182 |
| 180 bool NeedAuth(HttpAuth::Target target) const { | |
| 181 return auth_handler_[target].get() && auth_identity_[target].invalid; | |
| 182 } | |
| 183 | |
| 184 bool HaveAuth(HttpAuth::Target target) const { | 183 bool HaveAuth(HttpAuth::Target target) const { |
| 185 return auth_handler_[target].get() && !auth_identity_[target].invalid; | 184 return auth_handler_[target].get() && !auth_identity_[target].invalid; |
| 186 } | 185 } |
| 187 | 186 |
| 188 // Get the {scheme, host, port} for the authentication target | 187 // Get the {scheme, host, port} for the authentication target |
| 189 GURL AuthOrigin(HttpAuth::Target target) const; | 188 GURL AuthOrigin(HttpAuth::Target target) const; |
| 190 | 189 |
| 191 // Get the absolute path of the resource needing authentication. | 190 // Get the absolute path of the resource needing authentication. |
| 192 // For proxy authentication the path is always empty string. | 191 // For proxy authentication the path is always empty string. |
| 193 std::string AuthPath(HttpAuth::Target target) const; | 192 std::string AuthPath(HttpAuth::Target target) const; |
| 194 | 193 |
| 195 // The following three auth members are arrays of size two -- index 0 is | 194 // The following three auth members are arrays of size two -- index 0 is |
| 196 // for the proxy server, and index 1 is for the origin server. | 195 // for the proxy server, and index 1 is for the origin server. |
| 197 // Use the enum HttpAuth::Target to index into them. | 196 // Use the enum HttpAuth::Target to index into them. |
| 198 | 197 |
| 199 // auth_handler encapsulates the logic for the particular auth-scheme. | 198 // auth_handler encapsulates the logic for the particular auth-scheme. |
| 200 // This includes the challenge's parameters. If NULL, then there is no | 199 // This includes the challenge's parameters. If NULL, then there is no |
| 201 // associated auth handler. | 200 // associated auth handler. |
| 202 scoped_refptr<HttpAuthHandler> auth_handler_[2]; | 201 scoped_refptr<HttpAuthHandler> auth_handler_[2]; |
| 203 | 202 |
| 204 // auth_identity_ holds the (username/password) that should be used by | 203 // auth_identity_ holds the (username/password) that should be used by |
| 205 // the auth_handler_ to generate credentials. This identity can come from | 204 // the auth_handler_ to generate credentials. This identity can come from |
| 206 // a number of places (url, cache, prompt). | 205 // a number of places (url, cache, prompt). |
| 207 HttpAuth::Identity auth_identity_[2]; | 206 HttpAuth::Identity auth_identity_[2]; |
| 208 | 207 |
| 208 // Whether this transaction is waiting for proxy auth, server auth, or is |
| 209 // not waiting for any auth at all. |pending_auth_target_| is read and |
| 210 // cleared by RestartWithAuth(). |
| 211 HttpAuth::Target pending_auth_target_; |
| 212 |
| 209 CompletionCallbackImpl<HttpNetworkTransaction> io_callback_; | 213 CompletionCallbackImpl<HttpNetworkTransaction> io_callback_; |
| 210 CompletionCallback* user_callback_; | 214 CompletionCallback* user_callback_; |
| 211 | 215 |
| 212 scoped_refptr<HttpNetworkSession> session_; | 216 scoped_refptr<HttpNetworkSession> session_; |
| 213 | 217 |
| 214 const HttpRequestInfo* request_; | 218 const HttpRequestInfo* request_; |
| 215 HttpResponseInfo response_; | 219 HttpResponseInfo response_; |
| 216 | 220 |
| 217 ProxyService::PacRequest* pac_request_; | 221 ProxyService::PacRequest* pac_request_; |
| 218 ProxyInfo proxy_info_; | 222 ProxyInfo proxy_info_; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 STATE_DRAIN_BODY_FOR_AUTH_RESTART, | 311 STATE_DRAIN_BODY_FOR_AUTH_RESTART, |
| 308 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, | 312 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, |
| 309 STATE_NONE | 313 STATE_NONE |
| 310 }; | 314 }; |
| 311 State next_state_; | 315 State next_state_; |
| 312 }; | 316 }; |
| 313 | 317 |
| 314 } // namespace net | 318 } // namespace net |
| 315 | 319 |
| 316 #endif // NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ | 320 #endif // NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ |
| OLD | NEW |