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 "net/base/host_port_pair.h"
13 #include "net/base/net_export.h"
14 #include "net/http/http_pipelined_host_capability.h"
15 #include "net/socket/next_proto.h"
16 #include "net/spdy/spdy_framer.h" // TODO(willchan): Reconsider this.
20 enum AlternateProtocol {
21 DEPRECATED_NPN_SPDY_2 = 0,
22 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION = DEPRECATED_NPN_SPDY_2,
23 NPN_SPDY_MINIMUM_VERSION = DEPRECATED_NPN_SPDY_2,
27 // We lump in HTTP/2 with the SPDY protocols for now.
29 NPN_SPDY_MAXIMUM_VERSION = NPN_HTTP2_DRAFT_04,
31 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION = QUIC,
32 ALTERNATE_PROTOCOL_BROKEN, // The alternate protocol is known to be broken.
33 UNINITIALIZED_ALTERNATE_PROTOCOL,
36 // Simply returns whether |protocol| is between
37 // ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION and
38 // ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION (inclusive).
39 NET_EXPORT bool IsAlternateProtocolValid(AlternateProtocol protocol);
41 enum AlternateProtocolSize {
42 NUM_VALID_ALTERNATE_PROTOCOLS =
43 ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION -
44 ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION + 1,
47 NET_EXPORT const char* AlternateProtocolToString(AlternateProtocol protocol);
48 NET_EXPORT AlternateProtocol AlternateProtocolFromString(
49 const std::string& str);
50 NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto(
51 NextProto next_proto);
53 struct NET_EXPORT PortAlternateProtocolPair {
54 bool Equals(const PortAlternateProtocolPair& other) const {
55 return port == other.port && protocol == other.protocol;
58 std::string ToString() const;
61 AlternateProtocol protocol;
64 typedef std::map<HostPortPair, PortAlternateProtocolPair> AlternateProtocolMap;
65 typedef std::map<HostPortPair, SettingsMap> SpdySettingsMap;
66 typedef std::map<HostPortPair,
67 HttpPipelinedHostCapability> PipelineCapabilityMap;
69 extern const char kAlternateProtocolHeader[];
71 // The interface for setting/retrieving the HTTP server properties.
72 // Currently, this class manages servers':
73 // * SPDY support (based on NPN results)
74 // * Alternate-Protocol support
75 // * Spdy Settings (like CWND ID field)
76 class NET_EXPORT HttpServerProperties {
78 HttpServerProperties() {}
79 virtual ~HttpServerProperties() {}
81 // Gets a weak pointer for this object.
82 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0;
85 virtual void Clear() = 0;
87 // Returns true if |server| supports SPDY.
88 virtual bool SupportsSpdy(const HostPortPair& server) const = 0;
90 // Add |server| into the persistent store. Should only be called from IO
92 virtual void SetSupportsSpdy(const HostPortPair& server,
93 bool support_spdy) = 0;
95 // Returns true if |server| has an Alternate-Protocol header.
96 virtual bool HasAlternateProtocol(const HostPortPair& server) const = 0;
98 // Returns the Alternate-Protocol and port for |server|.
99 // HasAlternateProtocol(server) must be true.
100 virtual PortAlternateProtocolPair GetAlternateProtocol(
101 const HostPortPair& server) const = 0;
103 // Sets the Alternate-Protocol for |server|.
104 virtual void SetAlternateProtocol(const HostPortPair& server,
105 uint16 alternate_port,
106 AlternateProtocol alternate_protocol) = 0;
108 // Sets the Alternate-Protocol for |server| to be BROKEN.
109 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0;
111 // Returns all Alternate-Protocol mappings.
112 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0;
114 // Gets a reference to the SettingsMap stored for a host.
115 // If no settings are stored, returns an empty SettingsMap.
116 virtual const SettingsMap& GetSpdySettings(
117 const HostPortPair& host_port_pair) const = 0;
119 // Saves an individual SPDY setting for a host. Returns true if SPDY setting
120 // is to be persisted.
121 virtual bool SetSpdySetting(const HostPortPair& host_port_pair,
123 SpdySettingsFlags flags,
126 // Clears all SPDY settings for a host.
127 virtual void ClearSpdySettings(const HostPortPair& host_port_pair) = 0;
129 // Clears all SPDY settings for all hosts.
130 virtual void ClearAllSpdySettings() = 0;
132 // Returns all persistent SPDY settings.
133 virtual const SpdySettingsMap& spdy_settings_map() const = 0;
135 virtual HttpPipelinedHostCapability GetPipelineCapability(
136 const HostPortPair& origin) = 0;
138 virtual void SetPipelineCapability(
139 const HostPortPair& origin,
140 HttpPipelinedHostCapability capability) = 0;
142 virtual void ClearPipelineCapabilities() = 0;
144 virtual PipelineCapabilityMap GetPipelineCapabilityMap() const = 0;
147 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties);
152 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_