2012-05-25 14:37:01 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
2012-05-29 08:52:43 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-05-25 14:37:01 -07:00
|
|
|
|
2013-06-22 09:01:06 -07:00
|
|
|
// HttpLog.h should generally be included first
|
|
|
|
#include "HttpLog.h"
|
|
|
|
|
2013-07-26 14:22:46 -07:00
|
|
|
/*
|
2013-10-09 17:21:49 -07:00
|
|
|
Currently supported are HTTP-draft-[see nshttp.h]/2.0 spdy/3.1 and spdy/3
|
2013-07-26 14:22:46 -07:00
|
|
|
*/
|
|
|
|
|
2012-05-25 14:37:01 -07:00
|
|
|
#include "nsHttp.h"
|
2012-05-25 14:37:08 -07:00
|
|
|
#include "nsHttpHandler.h"
|
|
|
|
|
2012-05-25 14:37:01 -07:00
|
|
|
#include "ASpdySession.h"
|
2013-07-26 14:22:46 -07:00
|
|
|
#include "PSpdyPush.h"
|
|
|
|
#include "SpdyPush3.h"
|
|
|
|
#include "SpdyPush31.h"
|
2013-10-09 17:21:49 -07:00
|
|
|
#include "Http2Push.h"
|
2012-05-25 14:37:08 -07:00
|
|
|
#include "SpdySession3.h"
|
2013-07-26 14:22:46 -07:00
|
|
|
#include "SpdySession31.h"
|
2013-10-09 17:21:49 -07:00
|
|
|
#include "Http2Session.h"
|
2012-05-25 14:37:01 -07:00
|
|
|
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
ASpdySession *
|
2012-08-22 08:56:38 -07:00
|
|
|
ASpdySession::NewSpdySession(uint32_t version,
|
2012-05-25 14:37:01 -07:00
|
|
|
nsAHttpTransaction *aTransaction,
|
|
|
|
nsISocketTransport *aTransport,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aPriority)
|
2012-05-25 14:37:01 -07:00
|
|
|
{
|
|
|
|
// This is a necko only interface, so we can enforce version
|
|
|
|
// requests as a precondition
|
2013-09-27 10:55:24 -07:00
|
|
|
MOZ_ASSERT(version == SPDY_VERSION_3 ||
|
2013-10-09 17:21:49 -07:00
|
|
|
version == SPDY_VERSION_31 ||
|
|
|
|
version == NS_HTTP2_DRAFT_VERSION,
|
2013-05-16 06:30:41 -07:00
|
|
|
"Unsupported spdy version");
|
2012-05-25 14:37:08 -07:00
|
|
|
|
|
|
|
// Don't do a runtime check of IsSpdyV?Enabled() here because pref value
|
|
|
|
// may have changed since starting negotiation. The selected protocol comes
|
|
|
|
// from a list provided in the SERVER HELLO filtered by our acceptable
|
|
|
|
// versions, so there is no risk of the server ignoring our prefs.
|
2012-05-25 14:37:01 -07:00
|
|
|
|
2012-06-19 17:38:44 -07:00
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_VERSION2, version);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2013-07-26 14:22:46 -07:00
|
|
|
if (version == SPDY_VERSION_3)
|
|
|
|
return new SpdySession3(aTransaction, aTransport, aPriority);
|
|
|
|
|
2013-10-09 17:21:49 -07:00
|
|
|
if (version == SPDY_VERSION_31)
|
|
|
|
return new SpdySession31(aTransaction, aTransport, aPriority);
|
|
|
|
|
|
|
|
if (version == NS_HTTP2_DRAFT_VERSION)
|
|
|
|
return new Http2Session(aTransaction, aTransport, aPriority);
|
|
|
|
|
|
|
|
return nullptr;
|
2012-05-25 14:37:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SpdyInformation::SpdyInformation()
|
|
|
|
{
|
2013-09-27 10:55:24 -07:00
|
|
|
Version[0] = SPDY_VERSION_3;
|
|
|
|
VersionString[0] = NS_LITERAL_CSTRING("spdy/3");
|
2012-05-25 14:37:01 -07:00
|
|
|
|
2013-09-27 10:55:24 -07:00
|
|
|
Version[1] = SPDY_VERSION_31;
|
|
|
|
VersionString[1] = NS_LITERAL_CSTRING("spdy/3.1");
|
2013-10-09 17:21:49 -07:00
|
|
|
|
|
|
|
Version[2] = NS_HTTP2_DRAFT_VERSION;
|
|
|
|
VersionString[2] = NS_LITERAL_CSTRING(NS_HTTP2_DRAFT_TOKEN);
|
2012-05-25 14:37:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
SpdyInformation::ProtocolEnabled(uint32_t index)
|
2012-05-25 14:37:01 -07:00
|
|
|
{
|
2013-07-26 14:22:46 -07:00
|
|
|
MOZ_ASSERT(index < kCount, "index out of range");
|
2012-05-25 14:37:01 -07:00
|
|
|
|
2013-07-26 14:22:46 -07:00
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
return gHttpHandler->IsSpdyV3Enabled();
|
2013-09-27 10:55:24 -07:00
|
|
|
case 1:
|
2013-07-26 14:22:46 -07:00
|
|
|
return gHttpHandler->IsSpdyV31Enabled();
|
2013-10-09 17:21:49 -07:00
|
|
|
case 2:
|
|
|
|
return gHttpHandler->IsHttp2DraftEnabled();
|
2013-07-26 14:22:46 -07:00
|
|
|
}
|
2012-05-25 14:37:01 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
SpdyInformation::GetNPNVersionIndex(const nsACString &npnString,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t *result)
|
2012-05-25 14:37:01 -07:00
|
|
|
{
|
|
|
|
if (npnString.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2013-07-26 14:22:46 -07:00
|
|
|
for (uint32_t index = 0; index < kCount; ++index) {
|
|
|
|
if (npnString.Equals(VersionString[index])) {
|
|
|
|
*result = Version[index];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2012-05-25 14:37:01 -07:00
|
|
|
|
2013-07-26 14:22:46 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// SpdyPushCache
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
SpdyPushCache::SpdyPushCache()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SpdyPushCache::~SpdyPushCache()
|
|
|
|
{
|
|
|
|
mHashSpdy3.Clear();
|
|
|
|
mHashSpdy31.Clear();
|
2013-10-09 17:21:49 -07:00
|
|
|
mHashHttp2.Clear();
|
2013-07-26 14:22:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpdyPushCache::RegisterPushedStreamSpdy3(nsCString key,
|
|
|
|
SpdyPushedStream3 *stream)
|
|
|
|
{
|
|
|
|
LOG3(("SpdyPushCache::RegisterPushedStreamSpdy3 %s 0x%X\n",
|
|
|
|
key.get(), stream->StreamID()));
|
|
|
|
if(mHashSpdy3.Get(key))
|
|
|
|
return false;
|
|
|
|
mHashSpdy3.Put(key, stream);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SpdyPushedStream3 *
|
|
|
|
SpdyPushCache::RemovePushedStreamSpdy3(nsCString key)
|
|
|
|
{
|
|
|
|
SpdyPushedStream3 *rv = mHashSpdy3.Get(key);
|
|
|
|
LOG3(("SpdyPushCache::RemovePushedStream %s 0x%X\n",
|
|
|
|
key.get(), rv ? rv->StreamID() : 0));
|
|
|
|
if (rv)
|
|
|
|
mHashSpdy3.Remove(key);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpdyPushCache::RegisterPushedStreamSpdy31(nsCString key,
|
|
|
|
SpdyPushedStream31 *stream)
|
|
|
|
{
|
|
|
|
LOG3(("SpdyPushCache::RegisterPushedStreamSpdy31 %s 0x%X\n",
|
|
|
|
key.get(), stream->StreamID()));
|
|
|
|
if(mHashSpdy31.Get(key))
|
|
|
|
return false;
|
|
|
|
mHashSpdy31.Put(key, stream);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SpdyPushedStream31 *
|
|
|
|
SpdyPushCache::RemovePushedStreamSpdy31(nsCString key)
|
|
|
|
{
|
|
|
|
SpdyPushedStream31 *rv = mHashSpdy31.Get(key);
|
|
|
|
LOG3(("SpdyPushCache::RemovePushedStream %s 0x%X\n",
|
|
|
|
key.get(), rv ? rv->StreamID() : 0));
|
|
|
|
if (rv)
|
|
|
|
mHashSpdy31.Remove(key);
|
|
|
|
return rv;
|
2012-05-25 14:37:01 -07:00
|
|
|
}
|
|
|
|
|
2013-10-09 17:21:49 -07:00
|
|
|
bool
|
|
|
|
SpdyPushCache::RegisterPushedStreamHttp2(nsCString key,
|
|
|
|
Http2PushedStream *stream)
|
|
|
|
{
|
|
|
|
LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X\n",
|
|
|
|
key.get(), stream->StreamID()));
|
|
|
|
if(mHashHttp2.Get(key))
|
|
|
|
return false;
|
|
|
|
mHashHttp2.Put(key, stream);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Http2PushedStream *
|
|
|
|
SpdyPushCache::RemovePushedStreamHttp2(nsCString key)
|
|
|
|
{
|
|
|
|
Http2PushedStream *rv = mHashHttp2.Get(key);
|
|
|
|
LOG3(("SpdyPushCache::RemovePushedStreamHttp2 %s 0x%X\n",
|
|
|
|
key.get(), rv ? rv->StreamID() : 0));
|
|
|
|
if (rv)
|
|
|
|
mHashHttp2.Remove(key);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-05-25 14:37:01 -07:00
|
|
|
} // namespace mozilla::net
|
|
|
|
} // namespace mozilla
|
|
|
|
|