summaryrefslogtreecommitdiffstats
path: root/net/http/http_stream_factory.h
blob: b619add57e9d872d05e642e33edb39820c479885 (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
// 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_HTTP_STREAM_FACTORY_H_
#define NET_HTTP_HTTP_STREAM_FACTORY_H_

#include <map>
#include <set>
#include <string>

#include "base/scoped_ptr.h"
#include "net/base/completion_callback.h"
#include "net/base/host_mapping_rules.h"
#include "net/base/ssl_config_service.h"
#include "net/http/http_auth.h"
#include "net/http/http_auth_controller.h"
#include "net/http/http_stream_request.h"
#include "net/http/stream_factory.h"
#include "net/proxy/proxy_service.h"
#include "net/socket/client_socket_handle.h"

namespace net {

class HttpNetworkSession;
struct HttpRequestInfo;
class HttpStreamRequest;

class HttpStreamFactory : public StreamFactory,
                          public HttpStreamRequest::PreconnectDelegate {
 public:
  HttpStreamFactory();
  virtual ~HttpStreamFactory();

  // StreamFactory Interface
  virtual StreamRequest* RequestStream(const HttpRequestInfo* info,
                                       SSLConfig* ssl_config,
                                       ProxyInfo* proxy_info,
                                       HttpNetworkSession* session,
                                       StreamRequest::Delegate* delegate,
                                       const BoundNetLog& net_log);

  virtual int PreconnectStreams(int num_streams,
                                const HttpRequestInfo* info,
                                SSLConfig* ssl_config,
                                ProxyInfo* proxy_info,
                                HttpNetworkSession* session,
                                const BoundNetLog& net_log,
                                CompletionCallback* callback);

  void AddTLSIntolerantServer(const GURL& url);
  bool IsTLSIntolerantServer(const GURL& url);

  virtual void ProcessAlternateProtocol(
      HttpAlternateProtocols* alternate_protocols,
      const std::string& alternate_protocol_str,
      const HostPortPair& http_host_port_pair);

  virtual GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint);

  // HttpStreamRequest::PreconnectDelegate API
  virtual void OnPreconnectsComplete(HttpStreamRequest* request, int result);

  // Static settings

  // 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_; }

  // 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 HttpStreamFactory 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 set_create_new_spdy_session_for_http(bool value) {
    g_create_new_spdy_session_for_http_ = value;
  }

  static bool create_new_spdy_session_for_http() {
    return g_create_new_spdy_session_for_http_;
  }

  static void SetHostMappingRules(const std::string& rules);

 private:
  typedef std::map<HttpStreamRequest*, CompletionCallback*> RequestCallbackMap;
  RequestCallbackMap request_callback_map_;
  std::set<std::string> tls_intolerant_servers_;

  static const HostMappingRules* host_mapping_rules_;
  static const std::string* next_protos_;
  static bool use_alternate_protocols_;
  static bool force_spdy_over_ssl_;
  static bool force_spdy_always_;
  static bool ignore_certificate_errors_;
  static bool g_create_new_spdy_session_for_http_;

  DISALLOW_COPY_AND_ASSIGN(HttpStreamFactory);
};

}  // namespace net

#endif  // NET_HTTP_HTTP_STREAM_FACTORY_H_