Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/protocol/http/ASpdySession.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set sw=2 ts=8 et tw=80 : */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
// HttpLog.h should generally be included first
8
#include "HttpLog.h"
9
10
/*
11
  Currently supported is h2
12
*/
13
14
#include "nsHttp.h"
15
#include "nsHttpHandler.h"
16
17
#include "ASpdySession.h"
18
#include "PSpdyPush.h"
19
#include "Http2Push.h"
20
#include "Http2Session.h"
21
22
#include "mozilla/Telemetry.h"
23
24
namespace mozilla {
25
namespace net {
26
27
ASpdySession *
28
ASpdySession::NewSpdySession(net::SpdyVersion version,
29
                             nsISocketTransport *aTransport,
30
                             bool attemptingEarlyData)
31
0
{
32
0
  // This is a necko only interface, so we can enforce version
33
0
  // requests as a precondition
34
0
  MOZ_ASSERT(version == SpdyVersion::HTTP_2,
35
0
             "Unsupported spdy version");
36
0
37
0
  // Don't do a runtime check of IsSpdyV?Enabled() here because pref value
38
0
  // may have changed since starting negotiation. The selected protocol comes
39
0
  // from a list provided in the SERVER HELLO filtered by our acceptable
40
0
  // versions, so there is no risk of the server ignoring our prefs.
41
0
42
0
  Telemetry::Accumulate(Telemetry::SPDY_VERSION2, static_cast<uint32_t>(version));
43
0
44
0
  return new Http2Session(aTransport, version, attemptingEarlyData);
45
0
}
46
47
SpdyInformation::SpdyInformation()
48
1
{
49
1
  // highest index of enabled protocols is the
50
1
  // most preferred for ALPN negotiaton
51
1
  Version[0] = SpdyVersion::HTTP_2;
52
1
  VersionString[0] = NS_LITERAL_CSTRING("h2");
53
1
  ALPNCallbacks[0] = Http2Session::ALPNCallback;
54
1
}
55
56
bool
57
SpdyInformation::ProtocolEnabled(uint32_t index) const
58
0
{
59
0
  MOZ_ASSERT(index < kCount, "index out of range");
60
0
61
0
  return gHttpHandler->IsHttp2Enabled();
62
0
}
63
64
nsresult
65
SpdyInformation::GetNPNIndex(const nsACString &npnString,
66
                             uint32_t *result) const
67
0
{
68
0
  if (npnString.IsEmpty())
69
0
    return NS_ERROR_FAILURE;
70
0
71
0
  for (uint32_t index = 0; index < kCount; ++index) {
72
0
    if (npnString.Equals(VersionString[index])) {
73
0
      *result = index;
74
0
      return NS_OK;
75
0
    }
76
0
  }
77
0
78
0
  return NS_ERROR_FAILURE;
79
0
}
80
81
//////////////////////////////////////////
82
// SpdyPushCache
83
//////////////////////////////////////////
84
85
SpdyPushCache::~SpdyPushCache()
86
0
{
87
0
  mHashHttp2.Clear();
88
0
}
89
90
bool
91
SpdyPushCache::RegisterPushedStreamHttp2(const nsCString& key,
92
                                         Http2PushedStream *stream)
93
0
{
94
0
  LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X\n",
95
0
        key.get(), stream->StreamID()));
96
0
  if(mHashHttp2.Get(key)) {
97
0
    LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X duplicate key\n",
98
0
          key.get(), stream->StreamID()));
99
0
    return false;
100
0
  }
101
0
  mHashHttp2.Put(key, stream);
102
0
  return true;
103
0
}
104
105
Http2PushedStream *
106
SpdyPushCache::RemovePushedStreamHttp2(const nsCString& key)
107
0
{
108
0
  Http2PushedStream *rv = mHashHttp2.Get(key);
109
0
  LOG3(("SpdyPushCache::RemovePushedStreamHttp2 %s 0x%X\n",
110
0
        key.get(), rv ? rv->StreamID() : 0));
111
0
  if (rv)
112
0
    mHashHttp2.Remove(key);
113
0
  return rv;
114
0
}
115
116
Http2PushedStream *
117
SpdyPushCache::RemovePushedStreamHttp2ByID(const nsCString& key, const uint32_t& streamID)
118
0
{
119
0
  Http2PushedStream *rv = mHashHttp2.Get(key);
120
0
  LOG3(("SpdyPushCache::RemovePushedStreamHttp2ByID %s 0x%X 0x%X",
121
0
        key.get(), rv ? rv->StreamID() : 0, streamID));
122
0
  if (rv && streamID == rv->StreamID()) {
123
0
    mHashHttp2.Remove(key);
124
0
  } else {
125
0
    // Ensure we overwrite our rv with null in case the stream IDs don't match
126
0
    rv = nullptr;
127
0
  }
128
0
  return rv;
129
0
}
130
131
} // namespace net
132
} // namespace mozilla
133