2012-05-25 21:37:01 +00: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 15:52:43 +00: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 21:37:01 +00:00
|
|
|
|
2013-06-22 16:01:06 +00:00
|
|
|
// HttpLog.h should generally be included first
|
|
|
|
#include "HttpLog.h"
|
|
|
|
|
2013-07-26 21:22:46 +00:00
|
|
|
/*
|
2016-07-15 22:13:49 +00:00
|
|
|
Currently supported is h2
|
2013-07-26 21:22:46 +00:00
|
|
|
*/
|
|
|
|
|
2012-05-25 21:37:01 +00:00
|
|
|
#include "nsHttp.h"
|
2012-05-25 21:37:08 +00:00
|
|
|
#include "nsHttpHandler.h"
|
|
|
|
|
2012-05-25 21:37:01 +00:00
|
|
|
#include "ASpdySession.h"
|
2013-07-26 21:22:46 +00:00
|
|
|
#include "PSpdyPush.h"
|
2013-10-10 00:21:49 +00:00
|
|
|
#include "Http2Push.h"
|
|
|
|
#include "Http2Session.h"
|
2012-05-25 21:37:01 +00:00
|
|
|
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
ASpdySession *
|
2018-06-01 18:32:05 +00:00
|
|
|
ASpdySession::NewSpdySession(net::SpdyVersion version,
|
2017-02-21 20:19:46 +00:00
|
|
|
nsISocketTransport *aTransport,
|
|
|
|
bool attemptingEarlyData)
|
2012-05-25 21:37:01 +00:00
|
|
|
{
|
|
|
|
// This is a necko only interface, so we can enforce version
|
|
|
|
// requests as a precondition
|
2018-06-01 18:32:05 +00:00
|
|
|
MOZ_ASSERT(version == SpdyVersion::HTTP_2,
|
2013-05-16 13:30:41 +00:00
|
|
|
"Unsupported spdy version");
|
2012-05-25 21:37:08 +00: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 21:37:01 +00:00
|
|
|
|
2018-06-01 18:32:05 +00:00
|
|
|
Telemetry::Accumulate(Telemetry::SPDY_VERSION2, static_cast<uint32_t>(version));
|
2013-05-16 13:30:42 +00:00
|
|
|
|
2017-02-21 20:19:46 +00:00
|
|
|
return new Http2Session(aTransport, version, attemptingEarlyData);
|
2014-08-15 13:39:53 +00:00
|
|
|
}
|
2012-05-25 21:37:01 +00:00
|
|
|
|
|
|
|
SpdyInformation::SpdyInformation()
|
|
|
|
{
|
2014-08-04 20:54:08 +00:00
|
|
|
// highest index of enabled protocols is the
|
|
|
|
// most preferred for ALPN negotiaton
|
2018-06-01 18:32:05 +00:00
|
|
|
Version[0] = SpdyVersion::HTTP_2;
|
2016-07-15 22:13:49 +00:00
|
|
|
VersionString[0] = NS_LITERAL_CSTRING("h2");
|
|
|
|
ALPNCallbacks[0] = Http2Session::ALPNCallback;
|
2012-05-25 21:37:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-08-15 13:39:53 +00:00
|
|
|
SpdyInformation::ProtocolEnabled(uint32_t index) const
|
2012-05-25 21:37:01 +00:00
|
|
|
{
|
2013-07-26 21:22:46 +00:00
|
|
|
MOZ_ASSERT(index < kCount, "index out of range");
|
2012-05-25 21:37:01 +00:00
|
|
|
|
2016-07-15 22:13:49 +00:00
|
|
|
return gHttpHandler->IsHttp2Enabled();
|
2012-05-25 21:37:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-08-15 13:39:53 +00:00
|
|
|
SpdyInformation::GetNPNIndex(const nsACString &npnString,
|
|
|
|
uint32_t *result) const
|
2012-05-25 21:37:01 +00:00
|
|
|
{
|
|
|
|
if (npnString.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2013-07-26 21:22:46 +00:00
|
|
|
for (uint32_t index = 0; index < kCount; ++index) {
|
|
|
|
if (npnString.Equals(VersionString[index])) {
|
2014-08-15 13:39:53 +00:00
|
|
|
*result = index;
|
2013-07-26 21:22:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2012-05-25 21:37:01 +00:00
|
|
|
|
2013-07-26 21:22:46 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
// SpdyPushCache
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
SpdyPushCache::~SpdyPushCache()
|
|
|
|
{
|
2013-10-10 00:21:49 +00:00
|
|
|
mHashHttp2.Clear();
|
2013-07-26 21:22:46 +00:00
|
|
|
}
|
|
|
|
|
2013-10-10 00:21:49 +00:00
|
|
|
bool
|
2016-11-14 22:16:40 +00:00
|
|
|
SpdyPushCache::RegisterPushedStreamHttp2(const nsCString& key,
|
2013-10-10 00:21:49 +00:00
|
|
|
Http2PushedStream *stream)
|
|
|
|
{
|
|
|
|
LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X\n",
|
|
|
|
key.get(), stream->StreamID()));
|
2014-10-21 18:35:41 +00:00
|
|
|
if(mHashHttp2.Get(key)) {
|
|
|
|
LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X duplicate key\n",
|
|
|
|
key.get(), stream->StreamID()));
|
2013-10-10 00:21:49 +00:00
|
|
|
return false;
|
2014-10-21 18:35:41 +00:00
|
|
|
}
|
2013-10-10 00:21:49 +00:00
|
|
|
mHashHttp2.Put(key, stream);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Http2PushedStream *
|
2016-11-14 22:16:40 +00:00
|
|
|
SpdyPushCache::RemovePushedStreamHttp2(const nsCString& key)
|
2013-10-10 00:21:49 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2015-07-13 15:25:42 +00:00
|
|
|
|
2017-06-28 17:29:34 +00:00
|
|
|
Http2PushedStream *
|
|
|
|
SpdyPushCache::RemovePushedStreamHttp2ByID(const nsCString& key, const uint32_t& streamID)
|
|
|
|
{
|
|
|
|
Http2PushedStream *rv = mHashHttp2.Get(key);
|
|
|
|
LOG3(("SpdyPushCache::RemovePushedStreamHttp2ByID %s 0x%X 0x%X",
|
|
|
|
key.get(), rv ? rv->StreamID() : 0, streamID));
|
|
|
|
if (rv && streamID == rv->StreamID()) {
|
|
|
|
mHashHttp2.Remove(key);
|
|
|
|
} else {
|
|
|
|
// Ensure we overwrite our rv with null in case the stream IDs don't match
|
|
|
|
rv = nullptr;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace net
|
2012-05-25 21:37:01 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|