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 #ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ | 5 #ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ |
6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ | 6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
17 #include "net/http/http_auth.h" | 17 #include "net/http/http_auth.h" |
18 #include "net/http/http_response_info.h" | 18 #include "net/http/http_response_info.h" |
19 #include "net/http/proxy_client_socket.h" | 19 #include "net/http/proxy_client_socket.h" |
20 #include "net/socket/client_socket_pool_base.h" | 20 #include "net/socket/client_socket_pool_base.h" |
21 #include "net/socket/client_socket_pool_histograms.h" | 21 #include "net/socket/client_socket_pool_histograms.h" |
22 #include "net/socket/client_socket_pool.h" | 22 #include "net/socket/client_socket_pool.h" |
23 #include "net/socket/ssl_client_socket.h" | 23 #include "net/socket/ssl_client_socket.h" |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 | 26 |
27 class HostResolver; | 27 class HostResolver; |
28 class HttpAuthCache; | 28 class HttpAuthCache; |
| 29 class HttpAuthController; |
29 class HttpAuthHandlerFactory; | 30 class HttpAuthHandlerFactory; |
30 class SSLClientSocketPool; | 31 class SSLClientSocketPool; |
31 class SSLSocketParams; | 32 class SSLSocketParams; |
32 class SpdySessionPool; | 33 class SpdySessionPool; |
33 class SpdyStream; | 34 class SpdyStream; |
34 class TransportClientSocketPool; | 35 class TransportClientSocketPool; |
35 class TransportSocketParams; | 36 class TransportSocketParams; |
36 | 37 |
| 38 // Called when a 407 Proxy Authentication Required response is received |
| 39 // from an HTTP or HTTPS proxy when attempting to establish a CONNECT tunnel |
| 40 // to an HTTPS server. Information about the challenge can be found in |
| 41 // the HttpResponse info. Credentials should be added to the |
| 42 // HttpAuthController, and the CompletionCallback should be invoked |
| 43 // with the status. |
| 44 typedef base::Callback<void (const HttpResponseInfo&, |
| 45 HttpAuthController*, |
| 46 CompletionCallback)> |
| 47 TunnelAuthCallback; |
| 48 |
37 // HttpProxySocketParams only needs the socket params for one of the proxy | 49 // HttpProxySocketParams only needs the socket params for one of the proxy |
38 // types. The other param must be NULL. When using an HTTP Proxy, | 50 // types. The other param must be NULL. When using an HTTP Proxy, |
39 // |transport_params| must be set. When using an HTTPS Proxy, |ssl_params| | 51 // |transport_params| must be set. When using an HTTPS Proxy, |ssl_params| |
40 // must be set. | 52 // must be set. |
41 class NET_EXPORT_PRIVATE HttpProxySocketParams | 53 class NET_EXPORT_PRIVATE HttpProxySocketParams |
42 : public base::RefCounted<HttpProxySocketParams> { | 54 : public base::RefCounted<HttpProxySocketParams> { |
43 public: | 55 public: |
44 HttpProxySocketParams( | 56 HttpProxySocketParams( |
45 const scoped_refptr<TransportSocketParams>& transport_params, | 57 const scoped_refptr<TransportSocketParams>& transport_params, |
46 const scoped_refptr<SSLSocketParams>& ssl_params, | 58 const scoped_refptr<SSLSocketParams>& ssl_params, |
47 const GURL& request_url, | 59 const GURL& request_url, |
48 const std::string& user_agent, | 60 const std::string& user_agent, |
49 HostPortPair endpoint, | 61 HostPortPair endpoint, |
50 HttpAuthCache* http_auth_cache, | 62 HttpAuthCache* http_auth_cache, |
51 HttpAuthHandlerFactory* http_auth_handler_factory, | 63 HttpAuthHandlerFactory* http_auth_handler_factory, |
52 SpdySessionPool* spdy_session_pool, | 64 SpdySessionPool* spdy_session_pool, |
53 bool tunnel); | 65 bool tunnel, |
| 66 TunnelAuthCallback auth_needed_callback); |
54 | 67 |
55 const scoped_refptr<TransportSocketParams>& transport_params() const { | 68 const scoped_refptr<TransportSocketParams>& transport_params() const { |
56 return transport_params_; | 69 return transport_params_; |
57 } | 70 } |
58 const scoped_refptr<SSLSocketParams>& ssl_params() const { | 71 const scoped_refptr<SSLSocketParams>& ssl_params() const { |
59 return ssl_params_; | 72 return ssl_params_; |
60 } | 73 } |
61 const GURL& request_url() const { return request_url_; } | 74 const GURL& request_url() const { return request_url_; } |
62 const std::string& user_agent() const { return user_agent_; } | 75 const std::string& user_agent() const { return user_agent_; } |
63 const HostPortPair& endpoint() const { return endpoint_; } | 76 const HostPortPair& endpoint() const { return endpoint_; } |
64 HttpAuthCache* http_auth_cache() const { return http_auth_cache_; } | 77 HttpAuthCache* http_auth_cache() const { return http_auth_cache_; } |
65 HttpAuthHandlerFactory* http_auth_handler_factory() const { | 78 HttpAuthHandlerFactory* http_auth_handler_factory() const { |
66 return http_auth_handler_factory_; | 79 return http_auth_handler_factory_; |
67 } | 80 } |
68 SpdySessionPool* spdy_session_pool() { | 81 SpdySessionPool* spdy_session_pool() { |
69 return spdy_session_pool_; | 82 return spdy_session_pool_; |
70 } | 83 } |
71 const HostResolver::RequestInfo& destination() const; | 84 const HostResolver::RequestInfo& destination() const; |
72 bool tunnel() const { return tunnel_; } | 85 bool tunnel() const { return tunnel_; } |
73 bool ignore_limits() const { return ignore_limits_; } | 86 bool ignore_limits() const { return ignore_limits_; } |
| 87 TunnelAuthCallback auth_needed_callback() { return auth_needed_callback_; } |
74 | 88 |
75 private: | 89 private: |
76 friend class base::RefCounted<HttpProxySocketParams>; | 90 friend class base::RefCounted<HttpProxySocketParams>; |
77 ~HttpProxySocketParams(); | 91 ~HttpProxySocketParams(); |
78 | 92 |
79 const scoped_refptr<TransportSocketParams> transport_params_; | 93 const scoped_refptr<TransportSocketParams> transport_params_; |
80 const scoped_refptr<SSLSocketParams> ssl_params_; | 94 const scoped_refptr<SSLSocketParams> ssl_params_; |
81 SpdySessionPool* spdy_session_pool_; | 95 SpdySessionPool* spdy_session_pool_; |
82 const GURL request_url_; | 96 const GURL request_url_; |
83 const std::string user_agent_; | 97 const std::string user_agent_; |
84 const HostPortPair endpoint_; | 98 const HostPortPair endpoint_; |
85 HttpAuthCache* const http_auth_cache_; | 99 HttpAuthCache* const http_auth_cache_; |
86 HttpAuthHandlerFactory* const http_auth_handler_factory_; | 100 HttpAuthHandlerFactory* const http_auth_handler_factory_; |
87 const bool tunnel_; | 101 const bool tunnel_; |
88 bool ignore_limits_; | 102 bool ignore_limits_; |
| 103 TunnelAuthCallback auth_needed_callback_; |
89 | 104 |
90 DISALLOW_COPY_AND_ASSIGN(HttpProxySocketParams); | 105 DISALLOW_COPY_AND_ASSIGN(HttpProxySocketParams); |
91 }; | 106 }; |
92 | 107 |
93 // HttpProxyConnectJob optionally establishes a tunnel through the proxy | 108 // HttpProxyConnectJob optionally establishes a tunnel through the proxy |
94 // server after connecting the underlying transport socket. | 109 // server after connecting the underlying transport socket. |
95 class HttpProxyConnectJob : public ConnectJob { | 110 class HttpProxyConnectJob : public ConnectJob { |
96 public: | 111 public: |
97 HttpProxyConnectJob(const std::string& group_name, | 112 HttpProxyConnectJob(const std::string& group_name, |
98 const scoped_refptr<HttpProxySocketParams>& params, | 113 const scoped_refptr<HttpProxySocketParams>& params, |
(...skipping 14 matching lines...) Expand all Loading... |
113 enum State { | 128 enum State { |
114 STATE_TCP_CONNECT, | 129 STATE_TCP_CONNECT, |
115 STATE_TCP_CONNECT_COMPLETE, | 130 STATE_TCP_CONNECT_COMPLETE, |
116 STATE_SSL_CONNECT, | 131 STATE_SSL_CONNECT, |
117 STATE_SSL_CONNECT_COMPLETE, | 132 STATE_SSL_CONNECT_COMPLETE, |
118 STATE_HTTP_PROXY_CONNECT, | 133 STATE_HTTP_PROXY_CONNECT, |
119 STATE_HTTP_PROXY_CONNECT_COMPLETE, | 134 STATE_HTTP_PROXY_CONNECT_COMPLETE, |
120 STATE_SPDY_PROXY_CREATE_STREAM, | 135 STATE_SPDY_PROXY_CREATE_STREAM, |
121 STATE_SPDY_PROXY_CREATE_STREAM_COMPLETE, | 136 STATE_SPDY_PROXY_CREATE_STREAM_COMPLETE, |
122 STATE_SPDY_PROXY_CONNECT_COMPLETE, | 137 STATE_SPDY_PROXY_CONNECT_COMPLETE, |
| 138 STATE_RESTART_WITH_AUTH, |
| 139 STATE_RESTART_WITH_AUTH_COMPLETE, |
123 STATE_NONE, | 140 STATE_NONE, |
124 }; | 141 }; |
125 | 142 |
126 void OnIOComplete(int result); | 143 void OnIOComplete(int result); |
127 | 144 |
128 // Runs the state transition loop. | 145 // Runs the state transition loop. |
129 int DoLoop(int result); | 146 int DoLoop(int result); |
130 | 147 |
131 // Connecting to HTTP Proxy | 148 // Connecting to HTTP Proxy |
132 int DoTransportConnect(); | 149 int DoTransportConnect(); |
133 int DoTransportConnectComplete(int result); | 150 int DoTransportConnectComplete(int result); |
134 // Connecting to HTTPS Proxy | 151 // Connecting to HTTPS Proxy |
135 int DoSSLConnect(); | 152 int DoSSLConnect(); |
136 int DoSSLConnectComplete(int result); | 153 int DoSSLConnectComplete(int result); |
137 | 154 |
138 int DoHttpProxyConnect(); | 155 int DoHttpProxyConnect(); |
139 int DoHttpProxyConnectComplete(int result); | 156 int DoHttpProxyConnectComplete(int result); |
140 | 157 |
141 int DoSpdyProxyCreateStream(); | 158 int DoSpdyProxyCreateStream(); |
142 int DoSpdyProxyCreateStreamComplete(int result); | 159 int DoSpdyProxyCreateStreamComplete(int result); |
143 | 160 |
| 161 int DoRestartWithAuth(); |
| 162 int DoRestartWithAuthComplete(int result); |
| 163 |
| 164 void HandleProxyAuthChallenge(); |
| 165 |
144 // Begins the tcp connection and the optional Http proxy tunnel. If the | 166 // Begins the tcp connection and the optional Http proxy tunnel. If the |
145 // request is not immediately servicable (likely), the request will return | 167 // request is not immediately servicable (likely), the request will return |
146 // ERR_IO_PENDING. An OK return from this function or the callback means | 168 // ERR_IO_PENDING. An OK return from this function or the callback means |
147 // that the connection is established; ERR_PROXY_AUTH_REQUESTED means | 169 // that the connection is established; ERR_PROXY_AUTH_REQUESTED means |
148 // that the tunnel needs authentication credentials, the socket will be | 170 // that the tunnel needs authentication credentials, the socket will be |
149 // returned in this case, and must be release back to the pool; or | 171 // returned in this case, and must be release back to the pool; or |
150 // a standard net error code will be returned. | 172 // a standard net error code will be returned. |
151 virtual int ConnectInternal() OVERRIDE; | 173 virtual int ConnectInternal() OVERRIDE; |
152 | 174 |
153 scoped_refptr<HttpProxySocketParams> params_; | 175 scoped_refptr<HttpProxySocketParams> params_; |
154 TransportClientSocketPool* const transport_pool_; | 176 TransportClientSocketPool* const transport_pool_; |
155 SSLClientSocketPool* const ssl_pool_; | 177 SSLClientSocketPool* const ssl_pool_; |
156 HostResolver* const resolver_; | 178 HostResolver* const resolver_; |
157 | 179 |
158 State next_state_; | 180 State next_state_; |
159 CompletionCallback callback_; | 181 CompletionCallback callback_; |
160 scoped_ptr<ClientSocketHandle> transport_socket_handle_; | 182 scoped_ptr<ClientSocketHandle> transport_socket_handle_; |
161 scoped_ptr<ProxyClientSocket> transport_socket_; | 183 scoped_ptr<ProxyClientSocket> transport_socket_; |
162 bool using_spdy_; | 184 bool using_spdy_; |
163 // Protocol negotiated with the server. | 185 // Protocol negotiated with the server. |
164 SSLClientSocket::NextProto protocol_negotiated_; | 186 SSLClientSocket::NextProto protocol_negotiated_; |
165 | 187 |
166 HttpResponseInfo error_response_info_; | 188 HttpResponseInfo error_response_info_; |
167 | 189 |
168 scoped_refptr<SpdyStream> spdy_stream_; | 190 scoped_refptr<SpdyStream> spdy_stream_; |
169 | 191 |
| 192 // AuthController to be used for *all* requests when setting up this tunnel. |
| 193 scoped_refptr<HttpAuthController> auth_; |
| 194 |
| 195 base::WeakPtrFactory<HttpProxyConnectJob> ptr_factory_; |
| 196 |
170 DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJob); | 197 DISALLOW_COPY_AND_ASSIGN(HttpProxyConnectJob); |
171 }; | 198 }; |
172 | 199 |
173 class NET_EXPORT_PRIVATE HttpProxyClientSocketPool | 200 class NET_EXPORT_PRIVATE HttpProxyClientSocketPool |
174 : public ClientSocketPool, | 201 : public ClientSocketPool, |
175 public LayeredPool { | 202 public LayeredPool { |
176 public: | 203 public: |
177 HttpProxyClientSocketPool( | 204 HttpProxyClientSocketPool( |
178 int max_sockets, | 205 int max_sockets, |
179 int max_sockets_per_group, | 206 int max_sockets_per_group, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 300 |
274 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocketPool); | 301 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocketPool); |
275 }; | 302 }; |
276 | 303 |
277 REGISTER_SOCKET_PARAMS_FOR_POOL(HttpProxyClientSocketPool, | 304 REGISTER_SOCKET_PARAMS_FOR_POOL(HttpProxyClientSocketPool, |
278 HttpProxySocketParams); | 305 HttpProxySocketParams); |
279 | 306 |
280 } // namespace net | 307 } // namespace net |
281 | 308 |
282 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ | 309 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_POOL_H_ |
OLD | NEW |