OLD | NEW |
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 #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/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "net/base/address_list.h" | 14 #include "net/base/address_list.h" |
15 #include "net/base/host_resolver.h" | 15 #include "net/base/host_resolver.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/load_flags.h" | 17 #include "net/base/load_flags.h" |
18 #include "net/base/load_states.h" | 18 #include "net/base/load_states.h" |
19 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
20 #include "net/base/ssl_config_service.h" | 20 #include "net/base/ssl_config_service.h" |
21 #include "net/http/http_alternate_protocols.h" | 21 #include "net/http/http_alternate_protocols.h" |
22 #include "net/http/http_auth.h" | 22 #include "net/http/http_auth.h" |
| 23 #include "net/http/http_auth_controller.h" |
23 #include "net/http/http_auth_handler.h" | 24 #include "net/http/http_auth_handler.h" |
24 #include "net/http/http_response_info.h" | 25 #include "net/http/http_response_info.h" |
25 #include "net/http/http_transaction.h" | 26 #include "net/http/http_transaction.h" |
26 #include "net/proxy/proxy_service.h" | 27 #include "net/proxy/proxy_service.h" |
27 #include "net/socket/client_socket_pool.h" | 28 #include "net/socket/client_socket_pool.h" |
28 #include "testing/gtest/include/gtest/gtest_prod.h" | 29 #include "testing/gtest/include/gtest/gtest_prod.h" |
29 | 30 |
30 namespace net { | 31 namespace net { |
31 | 32 |
32 class ClientSocketFactory; | 33 class ClientSocketFactory; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 234 |
234 // Clear the state used to setup the tunnel. | 235 // Clear the state used to setup the tunnel. |
235 void ClearTunnelState(); | 236 void ClearTunnelState(); |
236 | 237 |
237 // Returns true if we should try to add a Proxy-Authorization header | 238 // Returns true if we should try to add a Proxy-Authorization header |
238 bool ShouldApplyProxyAuth() const; | 239 bool ShouldApplyProxyAuth() const; |
239 | 240 |
240 // Returns true if we should try to add an Authorization header. | 241 // Returns true if we should try to add an Authorization header. |
241 bool ShouldApplyServerAuth() const; | 242 bool ShouldApplyServerAuth() const; |
242 | 243 |
243 // Adds either the proxy auth header, or the origin server auth header, | |
244 // as specified by |target|. | |
245 void AddAuthorizationHeader( | |
246 HttpAuth::Target target, HttpRequestHeaders* authorization_headers); | |
247 | |
248 // Returns a log message for all the response headers related to the auth | |
249 // challenge. | |
250 std::string AuthChallengeLogMessage() const; | |
251 | |
252 // Handles HTTP status code 401 or 407. | 244 // Handles HTTP status code 401 or 407. |
253 // HandleAuthChallenge() returns a network error code, or OK on success. | 245 // HandleAuthChallenge() returns a network error code, or OK on success. |
254 // May update |pending_auth_target_| or |response_.auth_challenge|. | 246 // May update |pending_auth_target_| or |response_.auth_challenge|. |
255 int HandleAuthChallenge(bool establishing_tunnel); | 247 int HandleAuthChallenge(bool establishing_tunnel); |
256 | 248 |
257 // Populates response_.auth_challenge with the challenge information, so that | |
258 // URLRequestHttpJob can prompt for a username/password. | |
259 void PopulateAuthChallenge(HttpAuth::Target target, | |
260 const GURL& auth_origin); | |
261 | |
262 // Invalidates any auth cache entries after authentication has failed. | |
263 // The identity that was rejected is auth_identity_[target]. | |
264 void InvalidateRejectedAuthFromCache(HttpAuth::Target target, | |
265 const GURL& auth_origin); | |
266 | |
267 // Sets auth_identity_[target] to the next identity that the transaction | |
268 // should try. It chooses candidates by searching the auth cache | |
269 // and the URL for a username:password. Returns true if an identity | |
270 // was found. | |
271 bool SelectNextAuthIdentityToTry(HttpAuth::Target target, | |
272 const GURL& auth_origin); | |
273 | |
274 // Searches the auth cache for an entry that encompasses the request's path. | |
275 // If such an entry is found, updates auth_identity_[target] and | |
276 // auth_handler_[target] with the cache entry's data and returns true. | |
277 bool SelectPreemptiveAuth(HttpAuth::Target target); | |
278 | |
279 bool HaveAuth(HttpAuth::Target target) const { | 249 bool HaveAuth(HttpAuth::Target target) const { |
280 return auth_handler_[target].get() && !auth_identity_[target].invalid; | 250 return auth_controllers_[target].get() && |
| 251 auth_controllers_[target]->HaveAuth(); |
281 } | 252 } |
282 | 253 |
283 // Get the {scheme, host, port} for the authentication target | 254 // Get the {scheme, host, path, port} for the authentication target |
284 GURL AuthOrigin(HttpAuth::Target target) const; | 255 GURL AuthURL(HttpAuth::Target target) const; |
285 | |
286 // Same as AuthOrigin(), but will return an invalid GURL if the target is | |
287 // invalid. | |
288 GURL PossiblyInvalidAuthOrigin(HttpAuth::Target target) const; | |
289 | |
290 // Get the absolute path of the resource needing authentication. | |
291 // For proxy authentication the path is always empty string. | |
292 std::string AuthPath(HttpAuth::Target target) const; | |
293 | |
294 // Generate an authentication token for |target| if necessary. The return | |
295 // value is a net error code. |OK| will be returned both in the case that | |
296 // a token is correctly generated synchronously, as well as when no tokens | |
297 // were necessary. | |
298 int MaybeGenerateAuthToken(HttpAuth::Target target); | |
299 | 256 |
300 void MarkBrokenAlternateProtocolAndFallback(); | 257 void MarkBrokenAlternateProtocolAndFallback(); |
301 | 258 |
302 // Returns a string representation of a HttpAuth::Target value that can be | |
303 // used in log messages. | |
304 static std::string AuthTargetString(HttpAuth::Target target); | |
305 | |
306 static bool g_ignore_certificate_errors; | 259 static bool g_ignore_certificate_errors; |
307 | 260 |
308 // |auth_handler_| encapsulates the logic for the particular auth-scheme. | 261 scoped_ptr<HttpAuthController> auth_controllers_[HttpAuth::AUTH_NUM_TARGETS]; |
309 // This includes the challenge's parameters. If NULL, then there is no | |
310 // associated auth handler. | |
311 scoped_ptr<HttpAuthHandler> auth_handler_[HttpAuth::AUTH_NUM_TARGETS]; | |
312 | |
313 // |auth_identity_| holds the (username/password) that should be used by | |
314 // the |auth_handler_| to generate credentials. This identity can come from | |
315 // a number of places (url, cache, prompt). | |
316 HttpAuth::Identity auth_identity_[HttpAuth::AUTH_NUM_TARGETS]; | |
317 | |
318 // |auth_token_| contains the opaque string to pass to the proxy or | |
319 // server to authenticate the client. | |
320 std::string auth_token_[HttpAuth::AUTH_NUM_TARGETS]; | |
321 | 262 |
322 // Whether this transaction is waiting for proxy auth, server auth, or is | 263 // Whether this transaction is waiting for proxy auth, server auth, or is |
323 // not waiting for any auth at all. |pending_auth_target_| is read and | 264 // not waiting for any auth at all. |pending_auth_target_| is read and |
324 // cleared by RestartWithAuth(). | 265 // cleared by RestartWithAuth(). |
325 HttpAuth::Target pending_auth_target_; | 266 HttpAuth::Target pending_auth_target_; |
326 | 267 |
327 CompletionCallbackImpl<HttpNetworkTransaction> io_callback_; | 268 CompletionCallbackImpl<HttpNetworkTransaction> io_callback_; |
328 CompletionCallback* user_callback_; | 269 CompletionCallback* user_callback_; |
329 | 270 |
330 scoped_refptr<HttpNetworkSession> session_; | 271 scoped_refptr<HttpNetworkSession> session_; |
(...skipping 21 matching lines...) Expand all Loading... |
352 bool using_ssl_; // True if handling a HTTPS request | 293 bool using_ssl_; // True if handling a HTTPS request |
353 | 294 |
354 // True if this network transaction is using SPDY instead of HTTP. | 295 // True if this network transaction is using SPDY instead of HTTP. |
355 bool using_spdy_; | 296 bool using_spdy_; |
356 | 297 |
357 AlternateProtocolMode alternate_protocol_mode_; | 298 AlternateProtocolMode alternate_protocol_mode_; |
358 | 299 |
359 // Only valid if |alternate_protocol_mode_| == kUsingAlternateProtocol. | 300 // Only valid if |alternate_protocol_mode_| == kUsingAlternateProtocol. |
360 HttpAlternateProtocols::Protocol alternate_protocol_; | 301 HttpAlternateProtocols::Protocol alternate_protocol_; |
361 | 302 |
362 // True if we've used the username/password embedded in the URL. This | |
363 // makes sure we use the embedded identity only once for the transaction, | |
364 // preventing an infinite auth restart loop. | |
365 bool embedded_identity_used_; | |
366 | |
367 // True if default credentials have already been tried for this transaction | |
368 // in response to an HTTP authentication challenge. | |
369 bool default_credentials_used_; | |
370 | |
371 SSLConfig ssl_config_; | 303 SSLConfig ssl_config_; |
372 | 304 |
373 std::string request_headers_; | 305 std::string request_headers_; |
374 | 306 |
375 // The size in bytes of the buffer we use to drain the response body that | 307 // The size in bytes of the buffer we use to drain the response body that |
376 // we want to throw away. The response body is typically a small error | 308 // we want to throw away. The response body is typically a small error |
377 // page just a few hundred bytes long. | 309 // page just a few hundred bytes long. |
378 enum { kDrainBodyBufferSize = 1024 }; | 310 enum { kDrainBodyBufferSize = 1024 }; |
379 | 311 |
380 // User buffer and length passed to the Read method. | 312 // User buffer and length passed to the Read method. |
(...skipping 12 matching lines...) Expand all Loading... |
393 // The hostname and port of the endpoint. This is not necessarily the one | 325 // The hostname and port of the endpoint. This is not necessarily the one |
394 // specified by the URL, due to Alternate-Protocol or fixed testing ports. | 326 // specified by the URL, due to Alternate-Protocol or fixed testing ports. |
395 HostPortPair endpoint_; | 327 HostPortPair endpoint_; |
396 | 328 |
397 DISALLOW_COPY_AND_ASSIGN(HttpNetworkTransaction); | 329 DISALLOW_COPY_AND_ASSIGN(HttpNetworkTransaction); |
398 }; | 330 }; |
399 | 331 |
400 } // namespace net | 332 } // namespace net |
401 | 333 |
402 #endif // NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ | 334 #endif // NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ |
OLD | NEW |