| 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_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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class HttpStream; | 28 class HttpStream; |
| 29 class IOBuffer;; | 29 class IOBuffer;; |
| 30 | 30 |
| 31 class HttpProxyClientSocket : public ClientSocket { | 31 class HttpProxyClientSocket : public ClientSocket { |
| 32 public: | 32 public: |
| 33 // Takes ownership of |transport_socket|, which should already be connected | 33 // Takes ownership of |transport_socket|, which should already be connected |
| 34 // by the time Connect() is called. If tunnel is true then on Connect() | 34 // by the time Connect() is called. If tunnel is true then on Connect() |
| 35 // this socket will establish an Http tunnel. | 35 // this socket will establish an Http tunnel. |
| 36 HttpProxyClientSocket(ClientSocketHandle* transport_socket, | 36 HttpProxyClientSocket(ClientSocketHandle* transport_socket, |
| 37 const GURL& request_url, const HostPortPair& endpoint, | 37 const GURL& request_url, const HostPortPair& endpoint, |
| 38 const HostPortPair& proxy_server, | 38 const scoped_refptr<HttpAuthController>& auth, |
| 39 const scoped_refptr<HttpNetworkSession>& session, | |
| 40 bool tunnel); | 39 bool tunnel); |
| 41 | 40 |
| 42 // On destruction Disconnect() is called. | 41 // On destruction Disconnect() is called. |
| 43 virtual ~HttpProxyClientSocket(); | 42 virtual ~HttpProxyClientSocket(); |
| 44 | 43 |
| 45 // If Connect (or its callback) returns PROXY_AUTH_REQUESTED, then | 44 // If Connect (or its callback) returns PROXY_AUTH_REQUESTED, then |
| 46 // credentials should be added to the HttpAuthController before calling | 45 // credentials should be added to the HttpAuthController before calling |
| 47 // RestartWithAuth. | 46 // RestartWithAuth. |
| 48 int RestartWithAuth(CompletionCallback* callback); | 47 int RestartWithAuth(CompletionCallback* callback); |
| 49 | 48 |
| 49 // Indicates if RestartWithAuth needs to be called. i.e. if Connect |
| 50 // returned PROXY_AUTH_REQUESTED. Only valid after Connect has been called. |
| 51 bool NeedsRestartWithAuth() const; |
| 52 |
| 50 const HttpResponseInfo* GetResponseInfo() const { | 53 const HttpResponseInfo* GetResponseInfo() const { |
| 51 return response_.headers ? &response_ : NULL; | 54 return response_.headers ? &response_ : NULL; |
| 52 } | |
| 53 | |
| 54 const scoped_refptr<HttpAuthController>& auth_controller() { | |
| 55 return auth_; | |
| 56 } | 55 } |
| 57 | 56 |
| 58 // ClientSocket methods: | 57 // ClientSocket methods: |
| 59 | 58 |
| 60 // Authenticates to the Http Proxy and then passes data freely. | 59 // Authenticates to the Http Proxy and then passes data freely. |
| 61 virtual int Connect(CompletionCallback* callback); | 60 virtual int Connect(CompletionCallback* callback); |
| 62 virtual void Disconnect(); | 61 virtual void Disconnect(); |
| 63 virtual bool IsConnected() const; | 62 virtual bool IsConnected() const; |
| 64 virtual bool IsConnectedAndIdle() const; | 63 virtual bool IsConnectedAndIdle() const; |
| 65 virtual const BoundNetLog& NetLog() const { return net_log_; } | 64 virtual const BoundNetLog& NetLog() const { return net_log_; } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 79 STATE_GENERATE_AUTH_TOKEN, | 78 STATE_GENERATE_AUTH_TOKEN, |
| 80 STATE_GENERATE_AUTH_TOKEN_COMPLETE, | 79 STATE_GENERATE_AUTH_TOKEN_COMPLETE, |
| 81 STATE_SEND_REQUEST, | 80 STATE_SEND_REQUEST, |
| 82 STATE_SEND_REQUEST_COMPLETE, | 81 STATE_SEND_REQUEST_COMPLETE, |
| 83 STATE_READ_HEADERS, | 82 STATE_READ_HEADERS, |
| 84 STATE_READ_HEADERS_COMPLETE, | 83 STATE_READ_HEADERS_COMPLETE, |
| 85 STATE_RESOLVE_CANONICAL_NAME, | 84 STATE_RESOLVE_CANONICAL_NAME, |
| 86 STATE_RESOLVE_CANONICAL_NAME_COMPLETE, | 85 STATE_RESOLVE_CANONICAL_NAME_COMPLETE, |
| 87 STATE_DRAIN_BODY, | 86 STATE_DRAIN_BODY, |
| 88 STATE_DRAIN_BODY_COMPLETE, | 87 STATE_DRAIN_BODY_COMPLETE, |
| 89 STATE_TCP_RESTART, | |
| 90 STATE_TCP_RESTART_COMPLETE, | |
| 91 STATE_DONE, | 88 STATE_DONE, |
| 92 }; | 89 }; |
| 93 | 90 |
| 94 // The size in bytes of the buffer we use to drain the response body that | 91 // The size in bytes of the buffer we use to drain the response body that |
| 95 // we want to throw away. The response body is typically a small error | 92 // we want to throw away. The response body is typically a small error |
| 96 // page just a few hundred bytes long. | 93 // page just a few hundred bytes long. |
| 97 enum { kDrainBodyBufferSize = 1024 }; | 94 enum { kDrainBodyBufferSize = 1024 }; |
| 98 | 95 |
| 99 int PrepareForAuthRestart(); | 96 int PrepareForAuthRestart(); |
| 100 int DidDrainBodyForAuthRestart(bool keep_alive); | 97 int DidDrainBodyForAuthRestart(bool keep_alive); |
| 101 | 98 |
| 102 int HandleAuthChallenge(); | 99 int HandleAuthChallenge(); |
| 103 | 100 |
| 104 void LogBlockedTunnelResponse(int response_code) const; | 101 void LogBlockedTunnelResponse(int response_code) const; |
| 105 | 102 |
| 106 void DoCallback(int result); | 103 void DoCallback(int result); |
| 107 void OnIOComplete(int result); | 104 void OnIOComplete(int result); |
| 108 | 105 |
| 109 int DoLoop(int last_io_result); | 106 int DoLoop(int last_io_result); |
| 110 int DoGenerateAuthToken(); | 107 int DoGenerateAuthToken(); |
| 111 int DoGenerateAuthTokenComplete(int result); | 108 int DoGenerateAuthTokenComplete(int result); |
| 112 int DoSendRequest(); | 109 int DoSendRequest(); |
| 113 int DoSendRequestComplete(int result); | 110 int DoSendRequestComplete(int result); |
| 114 int DoReadHeaders(); | 111 int DoReadHeaders(); |
| 115 int DoReadHeadersComplete(int result); | 112 int DoReadHeadersComplete(int result); |
| 116 int DoDrainBody(); | 113 int DoDrainBody(); |
| 117 int DoDrainBodyComplete(int result); | 114 int DoDrainBodyComplete(int result); |
| 118 int DoTCPRestart(); | |
| 119 int DoTCPRestartComplete(int result); | |
| 120 | 115 |
| 121 CompletionCallbackImpl<HttpProxyClientSocket> io_callback_; | 116 CompletionCallbackImpl<HttpProxyClientSocket> io_callback_; |
| 122 State next_state_; | 117 State next_state_; |
| 123 | 118 |
| 124 // Stores the callback to the layer above, called on completing Connect(). | 119 // Stores the callback to the layer above, called on completing Connect(). |
| 125 CompletionCallback* user_callback_; | 120 CompletionCallback* user_callback_; |
| 126 | 121 |
| 127 HttpRequestInfo request_; | 122 HttpRequestInfo request_; |
| 128 HttpResponseInfo response_; | 123 HttpResponseInfo response_; |
| 129 | 124 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 142 std::string request_headers_; | 137 std::string request_headers_; |
| 143 | 138 |
| 144 const BoundNetLog net_log_; | 139 const BoundNetLog net_log_; |
| 145 | 140 |
| 146 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocket); | 141 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocket); |
| 147 }; | 142 }; |
| 148 | 143 |
| 149 } // namespace net | 144 } // namespace net |
| 150 | 145 |
| 151 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ | 146 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ |
| OLD | NEW |