OLD | NEW |
1 // Copyright (c) 2012 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_H_ | 5 #ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ |
6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ | 6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_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 "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
16 #include "net/http/http_auth_controller.h" | 16 #include "net/http/http_auth_controller.h" |
17 #include "net/http/http_request_headers.h" | 17 #include "net/http/http_request_headers.h" |
18 #include "net/http/http_request_info.h" | 18 #include "net/http/http_request_info.h" |
19 #include "net/http/http_response_info.h" | 19 #include "net/http/http_response_info.h" |
20 #include "net/http/proxy_client_socket.h" | 20 #include "net/http/proxy_client_socket.h" |
21 #include "net/socket/ssl_client_socket.h" | 21 #include "net/socket/ssl_client_socket.h" |
22 | 22 |
23 class GURL; | 23 class GURL; |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 | 26 |
27 class AddressList; | 27 class AddressList; |
28 class ClientSocketHandle; | 28 class ClientSocketHandle; |
29 class GrowableIOBuffer; | 29 class GrowableIOBuffer; |
| 30 class HttpAuthCache; |
30 class HttpStream; | 31 class HttpStream; |
31 class HttpStreamParser; | 32 class HttpStreamParser; |
32 class IOBuffer; | 33 class IOBuffer; |
33 | 34 |
34 class HttpProxyClientSocket : public ProxyClientSocket { | 35 class HttpProxyClientSocket : public ProxyClientSocket { |
35 public: | 36 public: |
36 // Takes ownership of |transport_socket|, which should already be connected | 37 // Takes ownership of |transport_socket|, which should already be connected |
37 // by the time Connect() is called. If tunnel is true then on Connect() | 38 // by the time Connect() is called. If tunnel is true then on Connect() |
38 // this socket will establish an Http tunnel. | 39 // this socket will establish an Http tunnel. |
39 HttpProxyClientSocket(ClientSocketHandle* transport_socket, | 40 HttpProxyClientSocket(ClientSocketHandle* transport_socket, |
40 const GURL& request_url, | 41 const GURL& request_url, |
41 const std::string& user_agent, | 42 const std::string& user_agent, |
42 const HostPortPair& endpoint, | 43 const HostPortPair& endpoint, |
43 const HostPortPair& proxy_server, | 44 const HostPortPair& proxy_server, |
44 HttpAuthController* http_auth_controller, | 45 HttpAuthCache* http_auth_cache, |
| 46 HttpAuthHandlerFactory* http_auth_handler_factory, |
45 bool tunnel, | 47 bool tunnel, |
46 bool using_spdy, | 48 bool using_spdy, |
47 SSLClientSocket::NextProto protocol_negotiated, | 49 SSLClientSocket::NextProto protocol_negotiated, |
48 bool is_https_proxy); | 50 bool is_https_proxy); |
49 | 51 |
50 // On destruction Disconnect() is called. | 52 // On destruction Disconnect() is called. |
51 virtual ~HttpProxyClientSocket(); | 53 virtual ~HttpProxyClientSocket(); |
52 | 54 |
| 55 // If Connect (or its callback) returns PROXY_AUTH_REQUESTED, then |
| 56 // credentials should be added to the HttpAuthController before calling |
| 57 // RestartWithAuth. |
| 58 int RestartWithAuth(const CompletionCallback& callback); |
| 59 |
| 60 const scoped_refptr<HttpAuthController>& auth_controller() { |
| 61 return auth_; |
| 62 } |
| 63 |
53 bool using_spdy() { | 64 bool using_spdy() { |
54 return using_spdy_; | 65 return using_spdy_; |
55 } | 66 } |
56 | 67 |
57 SSLClientSocket::NextProto protocol_negotiated() { | 68 SSLClientSocket::NextProto protocol_negotiated() { |
58 return protocol_negotiated_; | 69 return protocol_negotiated_; |
59 } | 70 } |
60 | 71 |
61 // ProxyClientSocket implementation. | 72 // ProxyClientSocket implementation. |
62 virtual const HttpResponseInfo* GetConnectResponseInfo() const OVERRIDE; | 73 virtual const HttpResponseInfo* GetConnectResponseInfo() const OVERRIDE; |
63 virtual HttpStream* CreateConnectResponseStream() OVERRIDE; | 74 virtual HttpStream* CreateConnectResponseStream() OVERRIDE; |
64 virtual int RestartWithAuth(const CompletionCallback& callback) OVERRIDE; | |
65 virtual const scoped_refptr<HttpAuthController>& GetAuthController() OVERRIDE; | |
66 | 75 |
67 // StreamSocket implementation. | 76 // StreamSocket implementation. |
68 virtual int Connect(const CompletionCallback& callback) OVERRIDE; | 77 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
69 virtual void Disconnect() OVERRIDE; | 78 virtual void Disconnect() OVERRIDE; |
70 virtual bool IsConnected() const OVERRIDE; | 79 virtual bool IsConnected() const OVERRIDE; |
71 virtual bool IsConnectedAndIdle() const OVERRIDE; | 80 virtual bool IsConnectedAndIdle() const OVERRIDE; |
72 virtual const BoundNetLog& NetLog() const OVERRIDE; | 81 virtual const BoundNetLog& NetLog() const OVERRIDE; |
73 virtual void SetSubresourceSpeculation() OVERRIDE; | 82 virtual void SetSubresourceSpeculation() OVERRIDE; |
74 virtual void SetOmniboxSpeculation() OVERRIDE; | 83 virtual void SetOmniboxSpeculation() OVERRIDE; |
75 virtual bool WasEverUsed() const OVERRIDE; | 84 virtual bool WasEverUsed() const OVERRIDE; |
(...skipping 17 matching lines...) Expand all Loading... |
93 enum State { | 102 enum State { |
94 STATE_NONE, | 103 STATE_NONE, |
95 STATE_GENERATE_AUTH_TOKEN, | 104 STATE_GENERATE_AUTH_TOKEN, |
96 STATE_GENERATE_AUTH_TOKEN_COMPLETE, | 105 STATE_GENERATE_AUTH_TOKEN_COMPLETE, |
97 STATE_SEND_REQUEST, | 106 STATE_SEND_REQUEST, |
98 STATE_SEND_REQUEST_COMPLETE, | 107 STATE_SEND_REQUEST_COMPLETE, |
99 STATE_READ_HEADERS, | 108 STATE_READ_HEADERS, |
100 STATE_READ_HEADERS_COMPLETE, | 109 STATE_READ_HEADERS_COMPLETE, |
101 STATE_DRAIN_BODY, | 110 STATE_DRAIN_BODY, |
102 STATE_DRAIN_BODY_COMPLETE, | 111 STATE_DRAIN_BODY_COMPLETE, |
| 112 STATE_TCP_RESTART, |
| 113 STATE_TCP_RESTART_COMPLETE, |
103 STATE_DONE, | 114 STATE_DONE, |
104 }; | 115 }; |
105 | 116 |
106 // The size in bytes of the buffer we use to drain the response body that | 117 // The size in bytes of the buffer we use to drain the response body that |
107 // we want to throw away. The response body is typically a small error | 118 // we want to throw away. The response body is typically a small error |
108 // page just a few hundred bytes long. | 119 // page just a few hundred bytes long. |
109 static const int kDrainBodyBufferSize = 1024; | 120 static const int kDrainBodyBufferSize = 1024; |
110 | 121 |
111 int PrepareForAuthRestart(); | 122 int PrepareForAuthRestart(); |
112 int DidDrainBodyForAuthRestart(bool keep_alive); | 123 int DidDrainBodyForAuthRestart(bool keep_alive); |
113 | 124 |
| 125 int HandleAuthChallenge(); |
| 126 |
114 void LogBlockedTunnelResponse(int response_code) const; | 127 void LogBlockedTunnelResponse(int response_code) const; |
115 | 128 |
116 void DoCallback(int result); | 129 void DoCallback(int result); |
117 void OnIOComplete(int result); | 130 void OnIOComplete(int result); |
118 | 131 |
119 int DoLoop(int last_io_result); | 132 int DoLoop(int last_io_result); |
120 int DoGenerateAuthToken(); | 133 int DoGenerateAuthToken(); |
121 int DoGenerateAuthTokenComplete(int result); | 134 int DoGenerateAuthTokenComplete(int result); |
122 int DoSendRequest(); | 135 int DoSendRequest(); |
123 int DoSendRequestComplete(int result); | 136 int DoSendRequestComplete(int result); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 HttpRequestHeaders request_headers_; | 173 HttpRequestHeaders request_headers_; |
161 | 174 |
162 const BoundNetLog net_log_; | 175 const BoundNetLog net_log_; |
163 | 176 |
164 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocket); | 177 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocket); |
165 }; | 178 }; |
166 | 179 |
167 } // namespace net | 180 } // namespace net |
168 | 181 |
169 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ | 182 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ |
OLD | NEW |