Update V8 to version 4.7.47.
[chromium-blink-merge.git] / net / http / http_proxy_client_socket.h
blobab973cc86b1cbe1de24769c2a0f7a25ea609997f
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.
5 #ifndef NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_
6 #define NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_
8 #include <string>
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/http/http_auth_controller.h"
16 #include "net/http/http_request_headers.h"
17 #include "net/http/http_request_info.h"
18 #include "net/http/http_response_info.h"
19 #include "net/http/proxy_client_socket.h"
20 #include "net/log/net_log.h"
21 #include "net/socket/ssl_client_socket.h"
23 namespace net {
25 class AddressList;
26 class ClientSocketHandle;
27 class GrowableIOBuffer;
28 class HttpAuthCache;
29 class HttpStream;
30 class HttpStreamParser;
31 class IOBuffer;
32 class ProxyDelegate;
34 class HttpProxyClientSocket : public ProxyClientSocket {
35 public:
36 // 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 // this socket will establish an Http tunnel.
39 HttpProxyClientSocket(ClientSocketHandle* transport_socket,
40 const std::string& user_agent,
41 const HostPortPair& endpoint,
42 const HostPortPair& proxy_server,
43 HttpAuthCache* http_auth_cache,
44 HttpAuthHandlerFactory* http_auth_handler_factory,
45 bool tunnel,
46 bool using_spdy,
47 NextProto protocol_negotiated,
48 ProxyDelegate* proxy_delegate,
49 bool is_https_proxy);
51 // On destruction Disconnect() is called.
52 ~HttpProxyClientSocket() override;
54 // ProxyClientSocket implementation.
55 const HttpResponseInfo* GetConnectResponseInfo() const override;
56 HttpStream* CreateConnectResponseStream() override;
57 int RestartWithAuth(const CompletionCallback& callback) override;
58 const scoped_refptr<HttpAuthController>& GetAuthController() const override;
59 bool IsUsingSpdy() const override;
60 NextProto GetProtocolNegotiated() const override;
62 // StreamSocket implementation.
63 int Connect(const CompletionCallback& callback) override;
64 void Disconnect() override;
65 bool IsConnected() const override;
66 bool IsConnectedAndIdle() const override;
67 const BoundNetLog& NetLog() const override;
68 void SetSubresourceSpeculation() override;
69 void SetOmniboxSpeculation() override;
70 bool WasEverUsed() const override;
71 bool UsingTCPFastOpen() const override;
72 bool WasNpnNegotiated() const override;
73 NextProto GetNegotiatedProtocol() const override;
74 bool GetSSLInfo(SSLInfo* ssl_info) override;
75 void GetConnectionAttempts(ConnectionAttempts* out) const override;
76 void ClearConnectionAttempts() override {}
77 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {}
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;
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_DONE,
105 // The size in bytes of the buffer we use to drain the response body that
106 // we want to throw away. The response body is typically a small error
107 // page just a few hundred bytes long.
108 static const int kDrainBodyBufferSize = 1024;
110 int PrepareForAuthRestart();
111 int DidDrainBodyForAuthRestart();
113 void LogBlockedTunnelResponse() const;
115 void DoCallback(int result);
116 void OnIOComplete(int result);
118 int DoLoop(int last_io_result);
119 int DoGenerateAuthToken();
120 int DoGenerateAuthTokenComplete(int result);
121 int DoSendRequest();
122 int DoSendRequestComplete(int result);
123 int DoReadHeaders();
124 int DoReadHeadersComplete(int result);
125 int DoDrainBody();
126 int DoDrainBodyComplete(int result);
128 CompletionCallback io_callback_;
129 State next_state_;
131 // Stores the callback to the layer above, called on completing Connect().
132 CompletionCallback user_callback_;
134 HttpRequestInfo request_;
135 HttpResponseInfo response_;
137 scoped_refptr<GrowableIOBuffer> parser_buf_;
138 scoped_ptr<HttpStreamParser> http_stream_parser_;
139 scoped_refptr<IOBuffer> drain_buf_;
141 // Stores the underlying socket.
142 scoped_ptr<ClientSocketHandle> transport_;
144 // The hostname and port of the endpoint. This is not necessarily the one
145 // specified by the URL, due to Alternate-Protocol or fixed testing ports.
146 const HostPortPair endpoint_;
147 scoped_refptr<HttpAuthController> auth_;
148 const bool tunnel_;
149 // If true, then the connection to the proxy is a SPDY connection.
150 const bool using_spdy_;
151 // Protocol negotiated with the server.
152 NextProto protocol_negotiated_;
153 // If true, then SSL is used to communicate with this proxy
154 const bool is_https_proxy_;
156 std::string request_line_;
157 HttpRequestHeaders request_headers_;
159 // Used only for redirects.
160 bool redirect_has_load_timing_info_;
161 LoadTimingInfo redirect_load_timing_info_;
163 const HostPortPair proxy_server_;
165 // This delegate must outlive this proxy client socket.
166 ProxyDelegate* proxy_delegate_;
168 const BoundNetLog net_log_;
170 DISALLOW_COPY_AND_ASSIGN(HttpProxyClientSocket);
173 } // namespace net
175 #endif // NET_HTTP_HTTP_PROXY_CLIENT_SOCKET_H_