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"
|
|
|
|
|
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"
|
|
|
|
#include "SpdySession2.h"
|
2012-05-25 14:37:08 -07:00
|
|
|
#include "SpdySession3.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-07-08 06:10:18 -07:00
|
|
|
MOZ_ASSERT(version == SPDY_VERSION_2 ||
|
|
|
|
version == SPDY_VERSION_3,
|
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-08 06:10:18 -07:00
|
|
|
if (version == SPDY_VERSION_2)
|
2012-05-25 14:37:08 -07:00
|
|
|
return new SpdySession2(aTransaction, aTransport, aPriority);
|
|
|
|
|
|
|
|
return new SpdySession3(aTransaction, aTransport, aPriority);
|
2012-05-25 14:37:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SpdyInformation::SpdyInformation()
|
|
|
|
{
|
2012-05-25 14:37:08 -07:00
|
|
|
// list the preferred version first
|
|
|
|
Version[0] = SPDY_VERSION_3;
|
|
|
|
VersionString[0] = NS_LITERAL_CSTRING("spdy/3");
|
2012-05-25 14:37:01 -07:00
|
|
|
|
2012-05-25 14:37:08 -07:00
|
|
|
Version[1] = SPDY_VERSION_2;
|
|
|
|
VersionString[1] = NS_LITERAL_CSTRING("spdy/2");
|
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
|
|
|
{
|
|
|
|
if (index == 0)
|
2012-05-25 14:37:08 -07:00
|
|
|
return gHttpHandler->IsSpdyV3Enabled();
|
2012-05-25 14:37:01 -07:00
|
|
|
|
|
|
|
if (index == 1)
|
2012-05-25 14:37:08 -07:00
|
|
|
return gHttpHandler->IsSpdyV2Enabled();
|
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(false, "index out of range");
|
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;
|
|
|
|
|
|
|
|
if (npnString.Equals(VersionString[0]))
|
|
|
|
*result = Version[0];
|
|
|
|
else if (npnString.Equals(VersionString[1]))
|
|
|
|
*result = Version[1];
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla::net
|
|
|
|
} // namespace mozilla
|
|
|
|
|