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_SERVER_PROPERTIES_H_
6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13 #include "net/base/host_port_pair.h"
14 #include "net/base/net_export.h"
15 #include "net/http/http_pipelined_host_capability.h"
16 #include "net/socket/next_proto.h"
17 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this.
21 enum AlternateProtocol {
22 DEPRECATED_NPN_SPDY_2 = 0,
23 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION = DEPRECATED_NPN_SPDY_2,
24 NPN_SPDY_MINIMUM_VERSION = DEPRECATED_NPN_SPDY_2,
28 // We lump in HTTP/2 with the SPDY protocols for now.
30 NPN_SPDY_MAXIMUM_VERSION = NPN_HTTP2_DRAFT_04,
32 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION = QUIC,
33 ALTERNATE_PROTOCOL_BROKEN, // The alternate protocol is known to be broken.
34 UNINITIALIZED_ALTERNATE_PROTOCOL,
37 // Simply returns whether |protocol| is between
38 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and
39 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive).
40 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol);
42 enum AlternateProtocolSize {
43 NUM_VALID_ALTERNATE_PROTOCOLS =
44 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION -
45 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1,
48 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol);
49 NET_EXPORT AlternateProtocol AlternateProtocolFromString(
50 const std::string& str);
51 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto(
52 NextProto next_proto);
54 struct NET_EXPORT PortAlternateProtocolPair {
55 bool Equals(const PortAlternateProtocolPair& other) const {
56 return port == other.port && protocol == other.protocol;
59 std::string ToString() const;
62 AlternateProtocol protocol;
65 typedef std::map<HostPortPair, PortAlternateProtocolPair> AlternateProtocolMap;
66 typedef std::map<HostPortPair, SettingsMap> SpdySettingsMap;
67 typedef std::map<HostPortPair,
68 HttpPipelinedHostCapability> PipelineCapabilityMap;
70 extern const char kAlternateProtocolHeader[];
72 // The interface for setting/retrieving the HTTP server properties.
73 // Currently, this class manages servers':
74 // * SPDY support (based on NPN results)
75 // * Alternate-Protocol support
76 // * Spdy Settings (like CWND ID field)
77 class NET_EXPORT HttpServerProperties {
81 uint64 bandwidth_estimate;
84 HttpServerProperties() {}
85 virtual ~HttpServerProperties() {}
87 // Gets a weak pointer for this object.
88 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0;
91 virtual void Clear() = 0;
93 // Returns true if |server| supports SPDY.
94 virtual bool SupportsSpdy(const HostPortPair& server) const = 0;
96 // Add |server| into the persistent store. Should only be called from IO
98 virtual void SetSupportsSpdy(const HostPortPair& server,
99 bool support_spdy) = 0;
101 // Returns true if |server| has an Alternate-Protocol header.
102 virtual bool HasAlternateProtocol(const HostPortPair& server) const = 0;
104 // Returns the Alternate-Protocol and port for |server|.
105 // HasAlternateProtocol(server) must be true.
106 virtual PortAlternateProtocolPair GetAlternateProtocol(
107 const HostPortPair& server) const = 0;
109 // Sets the Alternate-Protocol for |server|.
110 virtual void SetAlternateProtocol(const HostPortPair& server,
111 uint16 alternate_port,
112 AlternateProtocol alternate_protocol) = 0;
114 // Sets the Alternate-Protocol for |server| to be BROKEN.
115 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0;
117 // Returns all Alternate-Protocol mappings.
118 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0;
120 // Gets a reference to the SettingsMap stored for a host.
121 // If no settings are stored, returns an empty SettingsMap.
122 virtual const SettingsMap& GetSpdySettings(
123 const HostPortPair& host_port_pair) const = 0;
125 // Saves an individual SPDY setting for a host. Returns true if SPDY setting
126 // is to be persisted.
127 virtual bool SetSpdySetting(const HostPortPair& host_port_pair,
129 SpdySettingsFlags flags,
132 // Clears all SPDY settings for a host.
133 virtual void ClearSpdySettings(const HostPortPair& host_port_pair) = 0;
135 // Clears all SPDY settings for all hosts.
136 virtual void ClearAllSpdySettings() = 0;
138 // Returns all persistent SPDY settings.
139 virtual const SpdySettingsMap& spdy_settings_map() const = 0;
141 virtual void SetServerNetworkStats(const HostPortPair& host_port_pair,
142 NetworkStats stats) = 0;
144 virtual const NetworkStats* GetServerNetworkStats(
145 const HostPortPair& host_port_pair) const = 0;
147 virtual HttpPipelinedHostCapability GetPipelineCapability(
148 const HostPortPair& origin) = 0;
150 virtual void SetPipelineCapability(
151 const HostPortPair& origin,
152 HttpPipelinedHostCapability capability) = 0;
154 virtual void ClearPipelineCapabilities() = 0;
156 virtual PipelineCapabilityMap GetPipelineCapabilityMap() const = 0;
159 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties);
164 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_