| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ | |
| 6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "net/base/completion_callback.h" | |
| 13 #include "net/base/host_port_pair.h" | |
| 14 #include "net/base/load_timing_info.h" | |
| 15 #include "net/base/net_log.h" | |
| 16 #include "net/http/http_auth_controller.h" | |
| 17 #include "net/http/http_request_headers.h" | |
| 18 #include "net/http/http_request_info.h" | |
| 19 #include "net/http/http_response_info.h" | |
| 20 #include "net/http/proxy_client_socket.h" | |
| 21 #include "net/socket/ssl_client_socket.h" | |
| 22 | |
| 23 class GURL; | |
| 24 | |
| 25 namespace net { | |
| 26 | |
| 27 class AddressList; | |
| 28 class ClientSocketHandle; | |
| 29 class GrowableIOBuffer; | |
| 30 class HttpAuthCache; | |
| 31 class HttpStream; | |
| 32 class HttpStreamParser; | |
| 33 class IOBuffer; | |
| 34 class ProxyDelegate; | |
| 35 | |
| 36 class HttpProxyClientSocket : public ProxyClientSocket { | |
| 37 public: | |
| 38 // Takes ownership of |transport_socket|, which should already be connected | |
| 39 // by the time Connect() is called. If tunnel is true then on Connect() | |
| 40 // this socket will establish an Http tunnel. | |
| 41 HttpProxyClientSocket(ClientSocketHandle* transport_socket, | |
| 42 const GURL& request_url, | |
| 43 const std::string& user_agent, | |
| 44 const HostPortPair& endpoint, | |
| 45 const HostPortPair& proxy_server, | |
| 46 HttpAuthCache* http_auth_cache, | |
| 47 HttpAuthHandlerFactory* http_auth_handler_factory, | |
| 48 bool tunnel, | |
| 49 bool using_spdy, | |
| 50 NextProto protocol_negotiated, | |
| 51 ProxyDelegate* proxy_delegate, | |
| 52 bool is_https_proxy); | |
| 53 | |
| 54 // On destruction Disconnect() is called. | |
| 55 ~HttpProxyClientSocket() override; | |
| 56 | |
| 57 // ProxyClientSocket implementation. | |
| 58 const HttpResponseInfo* GetConnectResponseInfo() const override; | |
| 59 HttpStream* CreateConnectResponseStream() override; | |
| 60 int RestartWithAuth(const CompletionCallback& callback) override; | |
| 61 const scoped_refptr<HttpAuthController>& GetAuthController() const override; | |
| 62 bool IsUsingSpdy() const override; | |
| 63 NextProto GetProtocolNegotiated() const override; | |
| 64 | |
| 65 // StreamSocket implementation. | |
| 66 int Connect(const CompletionCallback& callback) override; | |
| 67 void Disconnect() override; | |
| 68 bool IsConnected() const override; | |
| 69 bool IsConnectedAndIdle() const override; | |
| 70 const BoundNetLog& NetLog() const override; | |
| 71 void SetSubresourceSpeculation() override; | |
| 72 void SetOmniboxSpeculation() override; | |
| 73 bool WasEverUsed() const override; | |
| 74 bool UsingTCPFastOpen() const override; | |
| 75 bool WasNpnNegotiated() const override; | |
| 76 NextProto GetNegotiatedProtocol() const override; | |
| 77 bool GetSSLInfo(SSLInfo* ssl_info) override; | |
| 78 | |
| 79 // Socket implementation. | |
| 80 int Read(IOBuffer* buf, | |
| 81 int buf_len, | |
| 82 const CompletionCallback& callback) override; | |
| 83 int Write(IOBuffer* buf, | |
| 84 int buf_len, | |
| 85 const CompletionCallback& callback) override; | |
| 86 int SetReceiveBufferSize(int32 size) override; | |
| 87 int SetSendBufferSize(int32 size) override; | |
| 88 int GetPeerAddress(IPEndPoint* address) const override; | |
| 89 int GetLocalAddress(IPEndPoint* address) const override; | |
| 90 | |
| 91 private: | |
| 92 enum State { | |
| 93 STATE_NONE, | |
| 94 STATE_GENERATE_AUTH_TOKEN, | |
| 95 STATE_GENERATE_AUTH_TOKEN_COMPLETE, | |
| 96 STATE_SEND_REQUEST, | |
| 97 STATE_SEND_REQUEST_COMPLETE, | |
| 98 STATE_READ_HEADERS, | |
| 99 STATE_READ_HEADERS_COMPLETE, | |
| 100 STATE_DRAIN_BODY, | |
| 101 STATE_DRAIN_BODY_COMPLETE, | |
| 102 STATE_TCP_RESTART, | |
| 103 STATE_TCP_RESTART_COMPLETE, | |
| 104 STATE_DONE, | |
| 105 }; | |
| 106 | |
| 107 // The size in bytes of the buffer we use to drain the response body that | |
| 108 // we want to throw away. The response body is typically a small error | |
| 109 // page just a few hundred bytes long. | |
| 110 static const int kDrainBodyBufferSize = 1024; | |
| 111 | |
| 112 int PrepareForAuthRestart(); | |
| 113 int DidDrainBodyForAuthRestart(bool keep_alive); | |
| 114 | |
| 115 void LogBlockedTunnelResponse() const; | |
| 116 | |
| 117 void DoCallback(int result); | |
| 118 void OnIOComplete(int result); | |
| 119 | |
| 120 int DoLoop(int last_io_result); | |
| 121 int DoGenerateAuthToken(); | |
| 122 int DoGenerateAuthTokenComplete(int result); | |
| 123 int DoSendRequest(); | |
| 124 int DoSendRequestComplete(int result); | |
| 125 int DoReadHeaders(); | |
| 126 int DoReadHeadersComplete(int result); | |
| 127 int DoDrainBody(); | |
| 128 int DoDrainBodyComplete(int result); | |
| 129 int DoTCPRestart(); | |
| 130 int DoTCPRestartComplete(int result); | |
| 131 | |
| 132 CompletionCallback io_callback_; | |
| 133 State next_state_; | |
| 134 | |
| 135 // Stores the callback to the layer above, called on completing Connect(). | |
| 136 CompletionCallback user_callback_; | |
| 137 | |
| 138 HttpRequestInfo request_; | |
| 139 HttpResponseInfo response_; | |
| 140 | |
| 141 scoped_refptr<GrowableIOBuffer> parser_buf_; | |
| 142 scoped_ptr<HttpStreamParser> http_stream_parser_; | |
| 143 scoped_refptr<IOBuffer> drain_buf_; | |
| 144 | |
| 145 // Stores the underlying socket. | |
| 146 scoped_ptr<ClientSocketHandle> transport_; | |
| 147 | |
| 148 // The hostname and port of the endpoint. This is not necessarily the one | |
| 149 // specified by the URL, due to Alternate-Protocol or fixed testing ports. | |
| 150 const HostPortPair endpoint_; | |
| 151 scoped_refptr<HttpAuthController> auth_; | |
| 152 const bool tunnel_; | |
| 153 // If true, then the connection to the proxy is a SPDY connection. | |
| 154 const bool using_spdy_; | |
| 155 // Protocol negotiated with the server. | |
| 156 NextProto protocol_negotiated_; | |
| 157 // If true, then SSL is used to communicate with this proxy | |
| 158 const bool is_https_proxy_; | |
| 159 | |
| 160 std::string request_line_; | |
| 161 HttpRequestHeaders request_headers_; | |
| 162 | |
| 163 // Used only for redirects. | |
| 164 bool redirect_has_load_timing_info_; | |
| 165 LoadTimingInfo redirect_load_timing_info_; | |
| 166 | |
| 167 const HostPortPair proxy_server_; | |
| 168 | |
| 169 // This delegate must outlive this proxy client socket. | |
| 170 ProxyDelegate* proxy_delegate_; | |
| 171 | |
| 172 const BoundNetLog net_log_; | |
| 173 | |
| 174 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocket); | |
| 175 }; | |
| 176 | |
| 177 } // namespace net | |
| 178 | |
| 179 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_ | |
| OLD | NEW |