summaryrefslogtreecommitdiffstats
path: root/net/http/stream_factory.h
blob: 39b22412a638368c3d2fa1b5c4dfabf8d88ae225 (plain)
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
// Copyright (c) 2010 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_STREAM_FACTORY_H_
#define NET_HTTP_STREAM_FACTORY_H_

#include <string>

#include "base/ref_counted.h"
#include "net/base/load_states.h"

namespace net {

struct HttpRequestInfo;
class BoundNetLog;
class HostPortPair;
class HttpAlternateProtocols;
class HttpAuthController;
class HttpNetworkSession;
class HttpResponseInfo;
class HttpStream;
class HttpStreamHandle;
class ProxyInfo;
class SSLCertRequestInfo;
class SSLInfo;

// The StreamFactory defines an interface for creating usable HttpStreams.
class StreamFactory {
 public:
  // The StreamRequestDelegate is a set of callback methods for a
  // StreamRequestJob.  Generally, only one of these methods will be
  // called as a result of a stream request.
  class StreamRequestDelegate {
   public:
    virtual ~StreamRequestDelegate() {}

    // This is the success case.
    // |stream| is now owned by the delegate.
    virtual void OnStreamReady(HttpStreamHandle* stream) = 0;

    // This is the failure to create a stream case.
    virtual void OnStreamFailed(int status) = 0;

    // Called when we have a certificate error for the request.
    virtual void OnCertificateError(int status, 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 StreamRequest.  For the non-tunnel case, the caller will handle
    // the authentication failure and restart the StreamRequest entirely.
    // Ownership of |auth_controller| and |proxy_response| are maintained
    // by the StreamRequest.  They are not guaranteed to be usable after the
    // lifetime of this callback.
    virtual void OnNeedsProxyAuth(
        const scoped_refptr<HttpAuthController>& auth_controller,
        const HttpResponseInfo& proxy_response) = 0;

    // This is the failure for SSL Client Auth
    // Ownership of |cert_info| is retained by the StreamRequest.  The delegate
    // may take a reference if it needs the cert_info beyond the lifetime of
    // this callback.
    virtual void OnNeedsClientAuth(
        const scoped_refptr<SSLCertRequestInfo>& cert_info) = 0;
  };

  // The StreamRequestJob is the worker object which handles the creation
  // of an HttpStream.  While the HttpStream is being created, this job
  // is the creator's handle for interacting with the HttpStream creation
  // process.
  class StreamRequestJob : public base::RefCounted<StreamRequestJob> {
   public:
    virtual ~StreamRequestJob() {}

    // Start initiates the process of creating a new HttpStream.
    // 3 parameters are passed in by reference.  The caller asserts that the
    // lifecycle of these parameters will  remain valid until the stream is
    // created, failed, or until the caller calls Cancel() on the stream
    // request.  In all cases, the delegate will be called to notify
    // completion of the request.
    virtual void Start(const HttpRequestInfo* request_info,
                       SSLConfig* ssl_config,
                       ProxyInfo* proxy_info,
                       StreamRequestDelegate* delegate,
                       const BoundNetLog& net_log) = 0;

    // Cancel can be used to abort the HttpStream creation.  Once cancelled,
    // the delegates associated with the request will not be invoked.
    virtual void Cancel() = 0;

    // When a HttpStream creation process requires a SSL Certificate,
    // the delegate OnNeedsClientAuth handler will have been called.
    // It now becomes the delegate's responsibility to collect the certificate
    // (probably from the user), and then call this method to resume
    // the HttpStream creation process.
    // Ownership of |client_cert| remains with the StreamRequest.  The
    // delegate can take a reference if needed beyond the lifetime of this
    // call.
    virtual int RestartWithCertificate(
        const scoped_refptr<X509Certificate>& client_cert) = 0;

    // 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 an AlternateProtocol for this request was available.
    virtual bool was_alternate_protocol_available() 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;
  };

  virtual ~StreamFactory() {}

  // Request a stream.
  // Will callback to the StreamRequestDelegate upon completion.
  virtual void RequestStream(const HttpRequestInfo* info,
                             SSLConfig* ssl_config,
                             ProxyInfo* proxy_info,
                             StreamRequestDelegate* delegate,
                             const BoundNetLog& net_log,
                             const scoped_refptr<HttpNetworkSession>& session,
                             scoped_refptr<StreamRequestJob>* stream) = 0;

  // TLS Intolerant Server API
  virtual void AddTLSIntolerantServer(const GURL& url) = 0;
  virtual bool IsTLSIntolerantServer(const GURL& url) = 0;

  // Alternate Protocol API
  virtual void ProcessAlternateProtocol(
      HttpAlternateProtocols* alternate_protocols,
      const std::string& alternate_protocol_str,
      const HostPortPair& http_host_port_pair) = 0;
};

}  // namespace net

#endif  // NET_HTTP_STREAM_FACTORY_H_