blob: 3d7933110b43a0c4b6f051bb5026975d619632d4 [file] [log] [blame]
[email protected]c0fe941d2012-02-25 00:15:321// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]fe2f62a2010-10-01 03:34:072// 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_SPDY_SPDY_PROXY_CLIENT_SOCKET_H_
6#define NET_SPDY_SPDY_PROXY_CLIENT_SOCKET_H_
[email protected]fe2f62a2010-10-01 03:34:077
[email protected]ba344362013-04-17 10:16:338#include <list>
[email protected]ca690b02013-04-17 10:38:439#include <string>
[email protected]fe2f62a2010-10-01 03:34:0710
11#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]6af4e412011-11-29 23:39:1813#include "base/memory/weak_ptr.h"
[email protected]fe2f62a2010-10-01 03:34:0714#include "net/base/completion_callback.h"
15#include "net/base/host_port_pair.h"
[email protected]57d2dfa2013-06-24 06:04:1216#include "net/base/load_timing_info.h"
[email protected]fe2f62a2010-10-01 03:34:0717#include "net/base/net_log.h"
18#include "net/http/http_auth_controller.h"
19#include "net/http/http_request_headers.h"
20#include "net/http/http_request_info.h"
21#include "net/http/http_response_info.h"
[email protected]511f6f52010-12-17 03:58:2922#include "net/http/proxy_client_socket.h"
23#include "net/spdy/spdy_http_stream.h"
[email protected]fe2f62a2010-10-01 03:34:0724#include "net/spdy/spdy_protocol.h"
[email protected]ca690b02013-04-17 10:38:4325#include "net/spdy/spdy_read_queue.h"
[email protected]fe2f62a2010-10-01 03:34:0726#include "net/spdy/spdy_session.h"
27#include "net/spdy/spdy_stream.h"
28
29
30class GURL;
31
32namespace net {
33
34class AddressList;
[email protected]fe2f62a2010-10-01 03:34:0735class HttpStream;
36class IOBuffer;
[email protected]fe2f62a2010-10-01 03:34:0737class SpdyStream;
38
[email protected]172da1b2011-08-12 15:52:2639class NET_EXPORT_PRIVATE SpdyProxyClientSocket : public ProxyClientSocket,
40 public SpdyStream::Delegate {
[email protected]fe2f62a2010-10-01 03:34:0741 public:
42 // Create a socket on top of the |spdy_stream| by sending a SYN_STREAM
43 // CONNECT frame for |endpoint|. After the SYN_REPLY is received,
44 // any data read/written to the socket will be transferred in data
[email protected]f6a78292013-03-09 14:36:3445 // frames. This object will set itself as |spdy_stream|'s delegate.
[email protected]d26ff352013-05-13 08:48:2846 SpdyProxyClientSocket(const base::WeakPtr<SpdyStream>& spdy_stream,
[email protected]fe2f62a2010-10-01 03:34:0747 const std::string& user_agent,
48 const HostPortPair& endpoint,
49 const GURL& url,
50 const HostPortPair& proxy_server,
[email protected]f6c63db52013-02-02 00:35:2251 const BoundNetLog& source_net_log,
[email protected]fe3b7dc2012-02-03 19:52:0952 HttpAuthCache* auth_cache,
53 HttpAuthHandlerFactory* auth_handler_factory);
54
[email protected]fe2f62a2010-10-01 03:34:0755
56 // On destruction Disconnect() is called.
57 virtual ~SpdyProxyClientSocket();
58
[email protected]767257802011-12-14 17:33:1859 // ProxyClientSocket methods:
[email protected]f2cbbc82011-11-16 01:10:2960 virtual const HttpResponseInfo* GetConnectResponseInfo() const OVERRIDE;
[email protected]f2cbbc82011-11-16 01:10:2961 virtual HttpStream* CreateConnectResponseStream() OVERRIDE;
[email protected]c0fe941d2012-02-25 00:15:3262 virtual const scoped_refptr<HttpAuthController>& GetAuthController() const
63 OVERRIDE;
64 virtual int RestartWithAuth(const CompletionCallback& callback) OVERRIDE;
65 virtual bool IsUsingSpdy() const OVERRIDE;
[email protected]8e3c78cb2012-03-31 03:58:4666 virtual NextProto GetProtocolNegotiated() const OVERRIDE;
[email protected]511f6f52010-12-17 03:58:2967
[email protected]dbf036f2011-12-06 23:33:2468 // StreamSocket implementation.
[email protected]dbf036f2011-12-06 23:33:2469 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
[email protected]f2cbbc82011-11-16 01:10:2970 virtual void Disconnect() OVERRIDE;
71 virtual bool IsConnected() const OVERRIDE;
72 virtual bool IsConnectedAndIdle() const OVERRIDE;
73 virtual const BoundNetLog& NetLog() const OVERRIDE;
74 virtual void SetSubresourceSpeculation() OVERRIDE;
75 virtual void SetOmniboxSpeculation() OVERRIDE;
76 virtual bool WasEverUsed() const OVERRIDE;
77 virtual bool UsingTCPFastOpen() const OVERRIDE;
[email protected]2d88e7d2012-07-19 17:55:1778 virtual bool WasNpnNegotiated() const OVERRIDE;
[email protected]33661e482012-04-03 16:16:2679 virtual NextProto GetNegotiatedProtocol() const OVERRIDE;
[email protected]2d88e7d2012-07-19 17:55:1780 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
[email protected]fe2f62a2010-10-01 03:34:0781
[email protected]3f55aa12011-12-07 02:03:3382 // Socket implementation.
[email protected]f2cbbc82011-11-16 01:10:2983 virtual int Read(IOBuffer* buf,
84 int buf_len,
[email protected]3f55aa12011-12-07 02:03:3385 const CompletionCallback& callback) OVERRIDE;
[email protected]6a60c8c2011-11-11 05:27:2686 virtual int Write(IOBuffer* buf,
87 int buf_len,
[email protected]83039bb2011-12-09 18:43:5588 const CompletionCallback& callback) OVERRIDE;
[email protected]f2cbbc82011-11-16 01:10:2989 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
90 virtual bool SetSendBufferSize(int32 size) OVERRIDE;
[email protected]a3528692012-06-08 00:11:4291 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
[email protected]f2cbbc82011-11-16 01:10:2992 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
[email protected]fe2f62a2010-10-01 03:34:0793
[email protected]3f55aa12011-12-07 02:03:3394 // SpdyStream::Delegate implementation.
[email protected]edbfa8c2013-05-29 00:22:3395 virtual void OnRequestHeadersSent() OVERRIDE;
[email protected]6d116e1a2013-06-24 07:42:1596 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated(
97 const SpdyHeaderBlock& response_headers) OVERRIDE;
98 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE;
[email protected]aa19cfc2013-05-23 16:41:3899 virtual void OnDataSent() OVERRIDE;
[email protected]f2cbbc82011-11-16 01:10:29100 virtual void OnClose(int status) OVERRIDE;
[email protected]fe2f62a2010-10-01 03:34:07101
102 private:
103 enum State {
[email protected]d9da5fe2010-10-13 22:37:16104 STATE_DISCONNECTED,
[email protected]fe2f62a2010-10-01 03:34:07105 STATE_GENERATE_AUTH_TOKEN,
106 STATE_GENERATE_AUTH_TOKEN_COMPLETE,
107 STATE_SEND_REQUEST,
108 STATE_SEND_REQUEST_COMPLETE,
109 STATE_READ_REPLY_COMPLETE,
[email protected]d9da5fe2010-10-13 22:37:16110 STATE_OPEN,
111 STATE_CLOSED
[email protected]fe2f62a2010-10-01 03:34:07112 };
113
[email protected]4eddbc732012-08-09 05:40:17114 void LogBlockedTunnelResponse() const;
115
[email protected]fe2f62a2010-10-01 03:34:07116 void OnIOComplete(int result);
117
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 DoReadReplyComplete(int result);
124
125 // Populates |user_buffer_| with as much read data as possible
126 // and returns the number of bytes read.
[email protected]ca690b02013-04-17 10:38:43127 size_t PopulateUserReadBuffer(char* out, size_t len);
[email protected]fe2f62a2010-10-01 03:34:07128
[email protected]fe2f62a2010-10-01 03:34:07129 State next_state_;
130
131 // Pointer to the SPDY Stream that this sits on top of.
[email protected]d26ff352013-05-13 08:48:28132 base::WeakPtr<SpdyStream> spdy_stream_;
[email protected]fe2f62a2010-10-01 03:34:07133
134 // Stores the callback to the layer above, called on completing Read() or
135 // Connect().
[email protected]dbf036f2011-12-06 23:33:24136 CompletionCallback read_callback_;
[email protected]fe2f62a2010-10-01 03:34:07137 // Stores the callback to the layer above, called on completing Write().
[email protected]83039bb2011-12-09 18:43:55138 CompletionCallback write_callback_;
[email protected]fe2f62a2010-10-01 03:34:07139
140 // CONNECT request and response.
141 HttpRequestInfo request_;
142 HttpResponseInfo response_;
143
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
149 // We buffer the response body as it arrives asynchronously from the stream.
[email protected]ca690b02013-04-17 10:38:43150 SpdyReadQueue read_buffer_queue_;
[email protected]fe2f62a2010-10-01 03:34:07151
152 // User provided buffer for the Read() response.
[email protected]ca690b02013-04-17 10:38:43153 scoped_refptr<IOBuffer> user_buffer_;
154 size_t user_buffer_len_;
[email protected]fe2f62a2010-10-01 03:34:07155
156 // User specified number of bytes to be written.
157 int write_buffer_len_;
[email protected]fe2f62a2010-10-01 03:34:07158
[email protected]fe2f62a2010-10-01 03:34:07159 // True if the transport socket has ever sent data.
160 bool was_ever_used_;
161
[email protected]57d2dfa2013-06-24 06:04:12162 // Used only for redirects.
163 bool redirect_has_load_timing_info_;
164 LoadTimingInfo redirect_load_timing_info_;
[email protected]511f6f52010-12-17 03:58:29165
[email protected]6af4e412011-11-29 23:39:18166 base::WeakPtrFactory<SpdyProxyClientSocket> weak_factory_;
167
[email protected]fe2f62a2010-10-01 03:34:07168 const BoundNetLog net_log_;
169
170 DISALLOW_COPY_AND_ASSIGN(SpdyProxyClientSocket);
171};
172
173} // namespace net
174
175#endif // NET_SPDY_SPDY_PROXY_CLIENT_SOCKET_H_