1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/protocol/http/ASpdySession.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,194 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set sw=2 ts=8 et tw=80 : */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +// HttpLog.h should generally be included first 1.11 +#include "HttpLog.h" 1.12 + 1.13 +/* 1.14 + Currently supported are HTTP-draft-[see nshttp.h]/2.0 spdy/3.1 and spdy/3 1.15 +*/ 1.16 + 1.17 +#include "nsHttp.h" 1.18 +#include "nsHttpHandler.h" 1.19 + 1.20 +#include "ASpdySession.h" 1.21 +#include "PSpdyPush.h" 1.22 +#include "SpdyPush3.h" 1.23 +#include "SpdyPush31.h" 1.24 +#include "Http2Push.h" 1.25 +#include "SpdySession3.h" 1.26 +#include "SpdySession31.h" 1.27 +#include "Http2Session.h" 1.28 + 1.29 +#include "mozilla/Telemetry.h" 1.30 + 1.31 +namespace mozilla { 1.32 +namespace net { 1.33 + 1.34 +ASpdySession * 1.35 +ASpdySession::NewSpdySession(uint32_t version, 1.36 + nsAHttpTransaction *aTransaction, 1.37 + nsISocketTransport *aTransport, 1.38 + int32_t aPriority) 1.39 +{ 1.40 + // This is a necko only interface, so we can enforce version 1.41 + // requests as a precondition 1.42 + MOZ_ASSERT(version == SPDY_VERSION_3 || 1.43 + version == SPDY_VERSION_31 || 1.44 + version == NS_HTTP2_DRAFT_VERSION, 1.45 + "Unsupported spdy version"); 1.46 + 1.47 + // Don't do a runtime check of IsSpdyV?Enabled() here because pref value 1.48 + // may have changed since starting negotiation. The selected protocol comes 1.49 + // from a list provided in the SERVER HELLO filtered by our acceptable 1.50 + // versions, so there is no risk of the server ignoring our prefs. 1.51 + 1.52 + Telemetry::Accumulate(Telemetry::SPDY_VERSION2, version); 1.53 + 1.54 + if (version == SPDY_VERSION_3) 1.55 + return new SpdySession3(aTransaction, aTransport, aPriority); 1.56 + 1.57 + if (version == SPDY_VERSION_31) 1.58 + return new SpdySession31(aTransaction, aTransport, aPriority); 1.59 + 1.60 + if (version == NS_HTTP2_DRAFT_VERSION) 1.61 + return new Http2Session(aTransaction, aTransport, aPriority); 1.62 + 1.63 + return nullptr; 1.64 +} 1.65 + 1.66 +SpdyInformation::SpdyInformation() 1.67 +{ 1.68 + Version[0] = SPDY_VERSION_3; 1.69 + VersionString[0] = NS_LITERAL_CSTRING("spdy/3"); 1.70 + 1.71 + Version[1] = SPDY_VERSION_31; 1.72 + VersionString[1] = NS_LITERAL_CSTRING("spdy/3.1"); 1.73 + 1.74 + Version[2] = NS_HTTP2_DRAFT_VERSION; 1.75 + VersionString[2] = NS_LITERAL_CSTRING(NS_HTTP2_DRAFT_TOKEN); 1.76 +} 1.77 + 1.78 +bool 1.79 +SpdyInformation::ProtocolEnabled(uint32_t index) 1.80 +{ 1.81 + MOZ_ASSERT(index < kCount, "index out of range"); 1.82 + 1.83 + switch (index) { 1.84 + case 0: 1.85 + return gHttpHandler->IsSpdyV3Enabled(); 1.86 + case 1: 1.87 + return gHttpHandler->IsSpdyV31Enabled(); 1.88 + case 2: 1.89 + return gHttpHandler->IsHttp2DraftEnabled(); 1.90 + } 1.91 + return false; 1.92 +} 1.93 + 1.94 +nsresult 1.95 +SpdyInformation::GetNPNVersionIndex(const nsACString &npnString, 1.96 + uint8_t *result) 1.97 +{ 1.98 + if (npnString.IsEmpty()) 1.99 + return NS_ERROR_FAILURE; 1.100 + 1.101 + for (uint32_t index = 0; index < kCount; ++index) { 1.102 + if (npnString.Equals(VersionString[index])) { 1.103 + *result = Version[index]; 1.104 + return NS_OK; 1.105 + } 1.106 + } 1.107 + 1.108 + return NS_ERROR_FAILURE; 1.109 +} 1.110 + 1.111 +////////////////////////////////////////// 1.112 +// SpdyPushCache 1.113 +////////////////////////////////////////// 1.114 + 1.115 +SpdyPushCache::SpdyPushCache() 1.116 +{ 1.117 +} 1.118 + 1.119 +SpdyPushCache::~SpdyPushCache() 1.120 +{ 1.121 + mHashSpdy3.Clear(); 1.122 + mHashSpdy31.Clear(); 1.123 + mHashHttp2.Clear(); 1.124 +} 1.125 + 1.126 +bool 1.127 +SpdyPushCache::RegisterPushedStreamSpdy3(nsCString key, 1.128 + SpdyPushedStream3 *stream) 1.129 +{ 1.130 + LOG3(("SpdyPushCache::RegisterPushedStreamSpdy3 %s 0x%X\n", 1.131 + key.get(), stream->StreamID())); 1.132 + if(mHashSpdy3.Get(key)) 1.133 + return false; 1.134 + mHashSpdy3.Put(key, stream); 1.135 + return true; 1.136 +} 1.137 + 1.138 +SpdyPushedStream3 * 1.139 +SpdyPushCache::RemovePushedStreamSpdy3(nsCString key) 1.140 +{ 1.141 + SpdyPushedStream3 *rv = mHashSpdy3.Get(key); 1.142 + LOG3(("SpdyPushCache::RemovePushedStream %s 0x%X\n", 1.143 + key.get(), rv ? rv->StreamID() : 0)); 1.144 + if (rv) 1.145 + mHashSpdy3.Remove(key); 1.146 + return rv; 1.147 +} 1.148 + 1.149 +bool 1.150 +SpdyPushCache::RegisterPushedStreamSpdy31(nsCString key, 1.151 + SpdyPushedStream31 *stream) 1.152 +{ 1.153 + LOG3(("SpdyPushCache::RegisterPushedStreamSpdy31 %s 0x%X\n", 1.154 + key.get(), stream->StreamID())); 1.155 + if(mHashSpdy31.Get(key)) 1.156 + return false; 1.157 + mHashSpdy31.Put(key, stream); 1.158 + return true; 1.159 +} 1.160 + 1.161 +SpdyPushedStream31 * 1.162 +SpdyPushCache::RemovePushedStreamSpdy31(nsCString key) 1.163 +{ 1.164 + SpdyPushedStream31 *rv = mHashSpdy31.Get(key); 1.165 + LOG3(("SpdyPushCache::RemovePushedStream %s 0x%X\n", 1.166 + key.get(), rv ? rv->StreamID() : 0)); 1.167 + if (rv) 1.168 + mHashSpdy31.Remove(key); 1.169 + return rv; 1.170 +} 1.171 + 1.172 +bool 1.173 +SpdyPushCache::RegisterPushedStreamHttp2(nsCString key, 1.174 + Http2PushedStream *stream) 1.175 +{ 1.176 + LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X\n", 1.177 + key.get(), stream->StreamID())); 1.178 + if(mHashHttp2.Get(key)) 1.179 + return false; 1.180 + mHashHttp2.Put(key, stream); 1.181 + return true; 1.182 +} 1.183 + 1.184 +Http2PushedStream * 1.185 +SpdyPushCache::RemovePushedStreamHttp2(nsCString key) 1.186 +{ 1.187 + Http2PushedStream *rv = mHashHttp2.Get(key); 1.188 + LOG3(("SpdyPushCache::RemovePushedStreamHttp2 %s 0x%X\n", 1.189 + key.get(), rv ? rv->StreamID() : 0)); 1.190 + if (rv) 1.191 + mHashHttp2.Remove(key); 1.192 + return rv; 1.193 +} 1.194 + 1.195 +} // namespace mozilla::net 1.196 +} // namespace mozilla 1.197 +