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
{
22 NPN_SPDY_MINIMUM_VERSION
= NPN_SPDY_1
,
27 NPN_SPDY_MAXIMUM_VERSION
= NPN_SPDY_4A2
,
29 NUM_ALTERNATE_PROTOCOLS
,
30 ALTERNATE_PROTOCOL_BROKEN
, // The alternate protocol is known to be broken.
31 UNINITIALIZED_ALTERNATE_PROTOCOL
,
34 NET_EXPORT
const char* AlternateProtocolToString(AlternateProtocol protocol
);
35 NET_EXPORT AlternateProtocol
AlternateProtocolFromString(
36 const std::string
& protocol
);
37 NET_EXPORT_PRIVATE AlternateProtocol
AlternateProtocolFromNextProto(
38 NextProto next_proto
);
40 struct NET_EXPORT PortAlternateProtocolPair
{
41 bool Equals(const PortAlternateProtocolPair
& other
) const {
42 return port
== other
.port
&& protocol
== other
.protocol
;
45 std::string
ToString() const;
48 AlternateProtocol protocol
;
51 typedef std::map
<HostPortPair
, PortAlternateProtocolPair
> AlternateProtocolMap
;
52 typedef std::map
<HostPortPair
, SettingsMap
> SpdySettingsMap
;
53 typedef std::map
<HostPortPair
,
54 HttpPipelinedHostCapability
> PipelineCapabilityMap
;
56 extern const char kAlternateProtocolHeader
[];
57 extern const char* const kAlternateProtocolStrings
[NUM_ALTERNATE_PROTOCOLS
];
59 // The interface for setting/retrieving the HTTP server properties.
60 // Currently, this class manages servers':
61 // * SPDY support (based on NPN results)
62 // * Alternate-Protocol support
63 // * Spdy Settings (like CWND ID field)
64 class NET_EXPORT HttpServerProperties
{
66 HttpServerProperties() {}
67 virtual ~HttpServerProperties() {}
69 // Gets a weak pointer for this object.
70 virtual base::WeakPtr
<HttpServerProperties
> GetWeakPtr() = 0;
73 virtual void Clear() = 0;
75 // Returns true if |server| supports SPDY.
76 virtual bool SupportsSpdy(const HostPortPair
& server
) const = 0;
78 // Add |server| into the persistent store. Should only be called from IO
80 virtual void SetSupportsSpdy(const HostPortPair
& server
,
81 bool support_spdy
) = 0;
83 // Returns true if |server| has an Alternate-Protocol header.
84 virtual bool HasAlternateProtocol(const HostPortPair
& server
) const = 0;
86 // Returns the Alternate-Protocol and port for |server|.
87 // HasAlternateProtocol(server) must be true.
88 virtual PortAlternateProtocolPair
GetAlternateProtocol(
89 const HostPortPair
& server
) const = 0;
91 // Sets the Alternate-Protocol for |server|.
92 virtual void SetAlternateProtocol(const HostPortPair
& server
,
93 uint16 alternate_port
,
94 AlternateProtocol alternate_protocol
) = 0;
96 // Sets the Alternate-Protocol for |server| to be BROKEN.
97 virtual void SetBrokenAlternateProtocol(const HostPortPair
& server
) = 0;
99 // Returns all Alternate-Protocol mappings.
100 virtual const AlternateProtocolMap
& alternate_protocol_map() const = 0;
102 // Gets a reference to the SettingsMap stored for a host.
103 // If no settings are stored, returns an empty SettingsMap.
104 virtual const SettingsMap
& GetSpdySettings(
105 const HostPortPair
& host_port_pair
) const = 0;
107 // Saves an individual SPDY setting for a host. Returns true if SPDY setting
108 // is to be persisted.
109 virtual bool SetSpdySetting(const HostPortPair
& host_port_pair
,
111 SpdySettingsFlags flags
,
114 // Clears all SPDY settings for a host.
115 virtual void ClearSpdySettings(const HostPortPair
& host_port_pair
) = 0;
117 // Clears all SPDY settings for all hosts.
118 virtual void ClearAllSpdySettings() = 0;
120 // Returns all persistent SPDY settings.
121 virtual const SpdySettingsMap
& spdy_settings_map() const = 0;
123 virtual HttpPipelinedHostCapability
GetPipelineCapability(
124 const HostPortPair
& origin
) = 0;
126 virtual void SetPipelineCapability(
127 const HostPortPair
& origin
,
128 HttpPipelinedHostCapability capability
) = 0;
130 virtual void ClearPipelineCapabilities() = 0;
132 virtual PipelineCapabilityMap
GetPipelineCapabilityMap() const = 0;
135 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties
);
140 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_