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 // We lump in HTTP/2 with the SPDY protocols for now.
29 NPN_SPDY_MAXIMUM_VERSION
= NPN_HTTP2_DRAFT_04
,
31 NUM_ALTERNATE_PROTOCOLS
,
32 ALTERNATE_PROTOCOL_BROKEN
, // The alternate protocol is known to be broken.
33 UNINITIALIZED_ALTERNATE_PROTOCOL
,
36 NET_EXPORT
const char* AlternateProtocolToString(AlternateProtocol protocol
);
37 NET_EXPORT AlternateProtocol
AlternateProtocolFromString(
38 const std::string
& protocol
);
39 NET_EXPORT_PRIVATE AlternateProtocol
AlternateProtocolFromNextProto(
40 NextProto next_proto
);
42 struct NET_EXPORT PortAlternateProtocolPair
{
43 bool Equals(const PortAlternateProtocolPair
& other
) const {
44 return port
== other
.port
&& protocol
== other
.protocol
;
47 std::string
ToString() const;
50 AlternateProtocol protocol
;
53 typedef std::map
<HostPortPair
, PortAlternateProtocolPair
> AlternateProtocolMap
;
54 typedef std::map
<HostPortPair
, SettingsMap
> SpdySettingsMap
;
55 typedef std::map
<HostPortPair
,
56 HttpPipelinedHostCapability
> PipelineCapabilityMap
;
58 extern const char kAlternateProtocolHeader
[];
60 // The interface for setting/retrieving the HTTP server properties.
61 // Currently, this class manages servers':
62 // * SPDY support (based on NPN results)
63 // * Alternate-Protocol support
64 // * Spdy Settings (like CWND ID field)
65 class NET_EXPORT HttpServerProperties
{
67 HttpServerProperties() {}
68 virtual ~HttpServerProperties() {}
70 // Gets a weak pointer for this object.
71 virtual base::WeakPtr
<HttpServerProperties
> GetWeakPtr() = 0;
74 virtual void Clear() = 0;
76 // Returns true if |server| supports SPDY.
77 virtual bool SupportsSpdy(const HostPortPair
& server
) const = 0;
79 // Add |server| into the persistent store. Should only be called from IO
81 virtual void SetSupportsSpdy(const HostPortPair
& server
,
82 bool support_spdy
) = 0;
84 // Returns true if |server| has an Alternate-Protocol header.
85 virtual bool HasAlternateProtocol(const HostPortPair
& server
) const = 0;
87 // Returns the Alternate-Protocol and port for |server|.
88 // HasAlternateProtocol(server) must be true.
89 virtual PortAlternateProtocolPair
GetAlternateProtocol(
90 const HostPortPair
& server
) const = 0;
92 // Sets the Alternate-Protocol for |server|.
93 virtual void SetAlternateProtocol(const HostPortPair
& server
,
94 uint16 alternate_port
,
95 AlternateProtocol alternate_protocol
) = 0;
97 // Sets the Alternate-Protocol for |server| to be BROKEN.
98 virtual void SetBrokenAlternateProtocol(const HostPortPair
& server
) = 0;
100 // Returns all Alternate-Protocol mappings.
101 virtual const AlternateProtocolMap
& alternate_protocol_map() const = 0;
103 // Gets a reference to the SettingsMap stored for a host.
104 // If no settings are stored, returns an empty SettingsMap.
105 virtual const SettingsMap
& GetSpdySettings(
106 const HostPortPair
& host_port_pair
) const = 0;
108 // Saves an individual SPDY setting for a host. Returns true if SPDY setting
109 // is to be persisted.
110 virtual bool SetSpdySetting(const HostPortPair
& host_port_pair
,
112 SpdySettingsFlags flags
,
115 // Clears all SPDY settings for a host.
116 virtual void ClearSpdySettings(const HostPortPair
& host_port_pair
) = 0;
118 // Clears all SPDY settings for all hosts.
119 virtual void ClearAllSpdySettings() = 0;
121 // Returns all persistent SPDY settings.
122 virtual const SpdySettingsMap
& spdy_settings_map() const = 0;
124 virtual HttpPipelinedHostCapability
GetPipelineCapability(
125 const HostPortPair
& origin
) = 0;
127 virtual void SetPipelineCapability(
128 const HostPortPair
& origin
,
129 HttpPipelinedHostCapability capability
) = 0;
131 virtual void ClearPipelineCapabilities() = 0;
133 virtual PipelineCapabilityMap
GetPipelineCapabilityMap() const = 0;
136 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties
);
141 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_