1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_HTTP_HTTP_STREAM_FACTORY_H_
#define NET_HTTP_HTTP_STREAM_FACTORY_H_
#include <list>
#include <string>
#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "net/base/completion_callback.h"
#include "net/base/load_states.h"
#include "net/base/net_api.h"
class GURL;
namespace net {
class BoundNetLog;
class HostMappingRules;
class HostPortPair;
class HttpAlternateProtocols;
class HttpAuthController;
class HttpNetworkSession;
class HttpResponseInfo;
class HttpStream;
class ProxyInfo;
class SSLCertRequestInfo;
class SSLInfo;
class X509Certificate;
struct HttpRequestInfo;
struct SSLConfig;
// The HttpStreamRequest is the client's handle to the worker object which
// handles the creation of an HttpStream. While the HttpStream is being
// created, this object is the creator's handle for interacting with the
// HttpStream creation process. The request is cancelled by deleting it, after
// which no callbacks will be invoked.
class NET_TEST HttpStreamRequest {
public:
// The HttpStreamRequest::Delegate is a set of callback methods for a
// HttpStreamRequestJob. Generally, only one of these methods will be
// called as a result of a stream request.
class NET_TEST Delegate {
public:
virtual ~Delegate() {}
// This is the success case.
// |stream| is now owned by the delegate.
// |used_ssl_config| indicates the actual SSL configuration used for this
// stream, since the HttpStreamRequest may have modified the configuration
// during stream processing.
// |used_proxy_info| indicates the actual ProxyInfo used for this stream,
// since the HttpStreamRequest performs the proxy resolution.
virtual void OnStreamReady(
const SSLConfig& used_ssl_config,
const ProxyInfo& used_proxy_info,
HttpStream* stream) = 0;
// This is the failure to create a stream case.
// |used_ssl_config| indicates the actual SSL configuration used for this
// stream, since the HttpStreamRequest may have modified the configuration
// during stream processing.
virtual void OnStreamFailed(int status,
const SSLConfig& used_ssl_config) = 0;
// Called when we have a certificate error for the request.
// |used_ssl_config| indicates the actual SSL configuration used for this
// stream, since the HttpStreamRequest may have modified the configuration
// during stream processing.
virtual void OnCertificateError(int status,
const SSLConfig& used_ssl_config,
const SSLInfo& ssl_info) = 0;
// This is the failure case where we need proxy authentication during
// proxy tunnel establishment. For the tunnel case, we were unable to
// create the HttpStream, so the caller provides the auth and then resumes
// the HttpStreamRequest.
//
// For the non-tunnel case, the caller will discover the authentication
// failure when reading response headers. At that point, he will handle the
// authentication failure and restart the HttpStreamRequest entirely.
//
// Ownership of |auth_controller| and |proxy_response| are owned
// by the HttpStreamRequest. |proxy_response| is not guaranteed to be usable
// after the lifetime of this callback. The delegate may take a reference
// to |auth_controller| if it is needed beyond the lifetime of this
// callback.
//
// |used_ssl_config| indicates the actual SSL configuration used for this
// stream, since the HttpStreamRequest may have modified the configuration
// during stream processing.
virtual void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
const SSLConfig& used_ssl_config,
const ProxyInfo& used_proxy_info,
HttpAuthController* auth_controller) = 0;
// This is the failure for SSL Client Auth
// Ownership of |cert_info| is retained by the HttpStreamRequest. The
// delegate may take a reference if it needs the cert_info beyond the
// lifetime of this callback.
virtual void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
SSLCertRequestInfo* cert_info) = 0;
// This is the failure of the CONNECT request through an HTTPS proxy.
// Headers can be read from |response_info|, while the body can be read
// from |stream|.
//
// |used_ssl_config| indicates the actual SSL configuration used for this
// stream, since the HttpStreamRequest may have modified the configuration
// during stream processing.
//
// |used_proxy_info| indicates the actual ProxyInfo used for this stream,
// since the HttpStreamRequest performs the proxy resolution.
//
// Ownership of |stream| is transferred to the delegate.
virtual void OnHttpsProxyTunnelResponse(
const HttpResponseInfo& response_info,
const SSLConfig& used_ssl_config,
const ProxyInfo& used_proxy_info,
HttpStream* stream) = 0;
};
virtual ~HttpStreamRequest() {}
// When a HttpStream creation process is stalled due to necessity
// of Proxy authentication credentials, the delegate OnNeedsProxyAuth
// will have been called. It now becomes the delegate's responsibility
// to collect the necessary credentials, and then call this method to
// resume the HttpStream creation process.
virtual int RestartTunnelWithProxyAuth(const string16& username,
const string16& password) = 0;
// Returns the LoadState for the request.
virtual LoadState GetLoadState() const = 0;
// Returns true if TLS/NPN was negotiated for this stream.
virtual bool was_npn_negotiated() const = 0;
// Returns true if this stream is being fetched over SPDY.
virtual bool using_spdy() const = 0;
};
// The HttpStreamFactory defines an interface for creating usable HttpStreams.
class NET_API HttpStreamFactory {
public:
virtual ~HttpStreamFactory();
void ProcessAlternateProtocol(
HttpAlternateProtocols* alternate_protocols,
const std::string& alternate_protocol_str,
const HostPortPair& http_host_port_pair);
// Virtual interface methods.
// Request a stream.
// Will callback to the HttpStreamRequestDelegate upon completion.
virtual HttpStreamRequest* RequestStream(
const HttpRequestInfo& info,
const SSLConfig& ssl_config,
HttpStreamRequest::Delegate* delegate,
const BoundNetLog& net_log) = 0;
// Requests that enough connections for |num_streams| be opened.
virtual void PreconnectStreams(int num_streams,
const HttpRequestInfo& info,
const SSLConfig& ssl_config,
const BoundNetLog& net_log) = 0;
virtual void AddTLSIntolerantServer(const HostPortPair& server) = 0;
virtual bool IsTLSIntolerantServer(const HostPortPair& server) const = 0;
// Static settings
static GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint);
// Turns spdy on or off.
static void set_spdy_enabled(bool value) {
spdy_enabled_ = value;
if (value == false)
set_next_protos("");
}
static bool spdy_enabled() { return spdy_enabled_; }
// Controls whether or not we use the Alternate-Protocol header.
static void set_use_alternate_protocols(bool value) {
use_alternate_protocols_ = value;
}
static bool use_alternate_protocols() { return use_alternate_protocols_; }
// Controls whether or not we use ssl when in spdy mode.
static void set_force_spdy_over_ssl(bool value) {
force_spdy_over_ssl_ = value;
}
static bool force_spdy_over_ssl() {
return force_spdy_over_ssl_;
}
// Controls whether or not we use spdy without npn.
static void set_force_spdy_always(bool value) {
force_spdy_always_ = value;
}
static bool force_spdy_always() { return force_spdy_always_; }
// Add a URL to exclude from forced SPDY.
static void add_forced_spdy_exclusion(const std::string& value);
// Check if a HostPortPair is excluded from using spdy.
static bool HasSpdyExclusion(const HostPortPair& endpoint);
// Sets the next protocol negotiation value used during the SSL handshake.
static void set_next_protos(const std::string& value) {
delete next_protos_;
next_protos_ = new std::string(value);
}
static const std::string* next_protos() { return next_protos_; }
// Sets the HttpStreamFactoryImpl into a mode where it can ignore certificate
// errors. This is for testing.
static void set_ignore_certificate_errors(bool value) {
ignore_certificate_errors_ = value;
}
static bool ignore_certificate_errors() {
return ignore_certificate_errors_;
}
static void SetHostMappingRules(const std::string& rules);
protected:
HttpStreamFactory();
private:
static const HostMappingRules& host_mapping_rules();
static const HostMappingRules* host_mapping_rules_;
static const std::string* next_protos_;
static bool spdy_enabled_;
static bool use_alternate_protocols_;
static bool force_spdy_over_ssl_;
static bool force_spdy_always_;
static std::list<HostPortPair>* forced_spdy_exclusions_;
static bool ignore_certificate_errors_;
DISALLOW_COPY_AND_ASSIGN(HttpStreamFactory);
};
} // namespace net
#endif // NET_HTTP_HTTP_STREAM_FACTORY_H_
|