diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 16:30:42 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 16:30:42 +0000 |
commit | 564b491ea6d163724307331648bd7b45cdada99e (patch) | |
tree | 135aa4b4e6e36e5ace999fb363c20b7913f4061d /net/http/http_alternate_protocols.cc | |
parent | ad54c1966904ed5b3d7e71c8f6caf4606c7e6a93 (diff) | |
download | chromium_src-564b491ea6d163724307331648bd7b45cdada99e.zip chromium_src-564b491ea6d163724307331648bd7b45cdada99e.tar.gz chromium_src-564b491ea6d163724307331648bd7b45cdada99e.tar.bz2 |
SPDY: Add basic support for Alternate-Protocol header.
Review URL: http://codereview.chromium.org/668197
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_alternate_protocols.cc')
-rw-r--r-- | net/http/http_alternate_protocols.cc | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/net/http/http_alternate_protocols.cc b/net/http/http_alternate_protocols.cc new file mode 100644 index 0000000..7f8bdfa --- /dev/null +++ b/net/http/http_alternate_protocols.cc @@ -0,0 +1,87 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/http/http_alternate_protocols.h" + +#include "base/logging.h" +#include "base/stl_util-inl.h" + +namespace net { + +const char HttpAlternateProtocols::kHeader[] = "Alternate-Protocol"; +const char HttpAlternateProtocols::kSpdyProtocol[] = "SPDY"; + +HttpAlternateProtocols::HttpAlternateProtocols() {} +HttpAlternateProtocols::~HttpAlternateProtocols() {} + +bool HttpAlternateProtocols::HasAlternateProtocolFor( + const HostPortPair& http_host_port_pair) const { + return ContainsKey(protocol_map_, http_host_port_pair); +} + +bool HttpAlternateProtocols::HasAlternateProtocolFor( + const std::string& host, uint16 port) const { + struct HostPortPair http_host_port_pair; + http_host_port_pair.host = host; + http_host_port_pair.port = port; + return HasAlternateProtocolFor(http_host_port_pair); +} + +HttpAlternateProtocols::PortProtocolPair +HttpAlternateProtocols::GetAlternateProtocolFor( + const HostPortPair& http_host_port_pair) const { + DCHECK(ContainsKey(protocol_map_, http_host_port_pair)); + return protocol_map_.find(http_host_port_pair)->second; +} + +HttpAlternateProtocols::PortProtocolPair +HttpAlternateProtocols::GetAlternateProtocolFor( + const std::string& host, uint16 port) const { + struct HostPortPair http_host_port_pair; + http_host_port_pair.host = host; + http_host_port_pair.port = port; + return GetAlternateProtocolFor(http_host_port_pair); +} + +void HttpAlternateProtocols::SetAlternateProtocolFor( + const HostPortPair& http_host_port_pair, + uint16 alternate_port, + Protocol alternate_protocol) { + if (alternate_protocol == BROKEN) { + LOG(DFATAL) << "Call MarkBrokenAlternateProtocolFor() instead."; + return; + } + + PortProtocolPair alternate; + alternate.port = alternate_port; + alternate.protocol = alternate_protocol; + if (HasAlternateProtocolFor(http_host_port_pair)) { + const PortProtocolPair existing_alternate = + GetAlternateProtocolFor(http_host_port_pair); + + if (existing_alternate.protocol == BROKEN) { + DLOG(INFO) << "Ignore alternate protocol since it's known to be broken."; + return; + } + + if (alternate_protocol != BROKEN && !existing_alternate.Equals(alternate)) { + LOG(WARNING) << "Changing the alternate protocol for: " + << http_host_port_pair.ToString() + << " from [Port: " << existing_alternate.port + << ", Protocol: " << existing_alternate.protocol + << "] to [Port: " << alternate_port + << ", Protocol: " << alternate_protocol + << "]."; + } + } + + protocol_map_[http_host_port_pair] = alternate; +} + +void HttpAlternateProtocols::MarkBrokenAlternateProtocolFor( + const HostPortPair& http_host_port_pair) { + protocol_map_[http_host_port_pair].protocol = BROKEN; +} + +} // namespace net |