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. 4 5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_H_ 6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_H_ 7 8 #include <map> 9 #include <string> 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. 17 18 namespace net { 19 20 enum AlternateProtocol { 21 NPN_SPDY_1 = 0, 22 NPN_SPDY_MINIMUM_VERSION = NPN_SPDY_1, 23 NPN_SPDY_2, 24 NPN_SPDY_3, 25 NPN_SPDY_3_1, 26 NPN_SPDY_4A2, 27 // We lump in HTTP/2 with the SPDY protocols for now. 28 NPN_HTTP2_DRAFT_04, 29 NPN_SPDY_MAXIMUM_VERSION = NPN_HTTP2_DRAFT_04, 30 QUIC, 31 NUM_ALTERNATE_PROTOCOLS, 32 ALTERNATE_PROTOCOL_BROKEN, // The alternate protocol is known to be broken. 33 UNINITIALIZED_ALTERNATE_PROTOCOL, 34 }; 35 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); 41 42 struct NET_EXPORT PortAlternateProtocolPair { 43 bool Equals(const PortAlternateProtocolPair& other) const { 44 return port == other.port && protocol == other.protocol; 45 } 46 47 std::string ToString() const; 48 49 uint16 port; 50 AlternateProtocol protocol; 51 }; 52 53 typedef std::map<HostPortPair, PortAlternateProtocolPair> AlternateProtocolMap; 54 typedef std::map<HostPortPair, SettingsMap> SpdySettingsMap; 55 typedef std::map<HostPortPair, 56 HttpPipelinedHostCapability> PipelineCapabilityMap; 57 58 extern const char kAlternateProtocolHeader[]; 59 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 { 66 public: 67 HttpServerProperties() {} 68 virtual ~HttpServerProperties() {} 69 70 // Gets a weak pointer for this object. 71 virtual base::WeakPtr<HttpServerProperties> GetWeakPtr() = 0; 72 73 // Deletes all data. 74 virtual void Clear() = 0; 75 76 // Returns true if |server| supports SPDY. 77 virtual bool SupportsSpdy(const HostPortPair& server) const = 0; 78 79 // Add |server| into the persistent store. Should only be called from IO 80 // thread. 81 virtual void SetSupportsSpdy(const HostPortPair& server, 82 bool support_spdy) = 0; 83 84 // Returns true if |server| has an Alternate-Protocol header. 85 virtual bool HasAlternateProtocol(const HostPortPair& server) const = 0; 86 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; 91 92 // Sets the Alternate-Protocol for |server|. 93 virtual void SetAlternateProtocol(const HostPortPair& server, 94 uint16 alternate_port, 95 AlternateProtocol alternate_protocol) = 0; 96 97 // Sets the Alternate-Protocol for |server| to be BROKEN. 98 virtual void SetBrokenAlternateProtocol(const HostPortPair& server) = 0; 99 100 // Returns all Alternate-Protocol mappings. 101 virtual const AlternateProtocolMap& alternate_protocol_map() const = 0; 102 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; 107 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, 111 SpdySettingsIds id, 112 SpdySettingsFlags flags, 113 uint32 value) = 0; 114 115 // Clears all SPDY settings for a host. 116 virtual void ClearSpdySettings(const HostPortPair& host_port_pair) = 0; 117 118 // Clears all SPDY settings for all hosts. 119 virtual void ClearAllSpdySettings() = 0; 120 121 // Returns all persistent SPDY settings. 122 virtual const SpdySettingsMap& spdy_settings_map() const = 0; 123 124 virtual HttpPipelinedHostCapability GetPipelineCapability( 125 const HostPortPair& origin) = 0; 126 127 virtual void SetPipelineCapability( 128 const HostPortPair& origin, 129 HttpPipelinedHostCapability capability) = 0; 130 131 virtual void ClearPipelineCapabilities() = 0; 132 133 virtual PipelineCapabilityMap GetPipelineCapabilityMap() const = 0; 134 135 private: 136 DISALLOW_COPY_AND_ASSIGN(HttpServerProperties); 137 }; 138 139 } // namespace net 140 141 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_H_ 142