Bug 888583 - Expose protocol version in about:networking. r=mcmanus

This commit is contained in:
Robert Bindar 2013-07-08 09:10:19 -04:00
parent 73fd524632
commit f2cbf97856
7 changed files with 59 additions and 4 deletions

View File

@ -15,8 +15,9 @@ dictionary SocketsDict {
};
dictionary HttpConnInfoDict {
sequence<unsigned long> rtt;
sequence<unsigned long> ttl;
sequence<unsigned long> rtt;
sequence<unsigned long> ttl;
sequence<DOMString> protocolVersion;
};
dictionary HttpConnDict {

View File

@ -165,10 +165,13 @@ Dashboard::GetHttpConnections()
HttpConnInfoDict &activeInfo = *active.AppendElement();
activeInfo.mRtt.Construct();
activeInfo.mTtl.Construct();
activeInfo.mProtocolVersion.Construct();
Sequence<uint32_t> &active_rtt = activeInfo.mRtt.Value();
Sequence<uint32_t> &active_ttl = activeInfo.mTtl.Value();
Sequence<nsString> &active_protocolVersion = activeInfo.mProtocolVersion.Value();
if (!active_rtt.SetCapacity(mHttp.data[i].active.Length()) ||
!active_ttl.SetCapacity(mHttp.data[i].active.Length())) {
!active_ttl.SetCapacity(mHttp.data[i].active.Length()) ||
!active_protocolVersion.SetCapacity(mHttp.data[i].active.Length())) {
mHttp.cb = nullptr;
mHttp.data.Clear();
JS_ReportOutOfMemory(cx);
@ -177,15 +180,19 @@ Dashboard::GetHttpConnections()
for (uint32_t j = 0; j < mHttp.data[i].active.Length(); j++) {
*active_rtt.AppendElement() = mHttp.data[i].active[j].rtt;
*active_ttl.AppendElement() = mHttp.data[i].active[j].ttl;
*active_protocolVersion.AppendElement() = mHttp.data[i].active[j].protocolVersion;
}
HttpConnInfoDict &idleInfo = *idle.AppendElement();
idleInfo.mRtt.Construct();
idleInfo.mTtl.Construct();
idleInfo.mProtocolVersion.Construct();
Sequence<uint32_t> &idle_rtt = idleInfo.mRtt.Value();
Sequence<uint32_t> &idle_ttl = idleInfo.mTtl.Value();
Sequence<nsString> &idle_protocolVersion = idleInfo.mProtocolVersion.Value();
if (!idle_rtt.SetCapacity(mHttp.data[i].idle.Length()) ||
!idle_ttl.SetCapacity(mHttp.data[i].idle.Length())) {
!idle_ttl.SetCapacity(mHttp.data[i].idle.Length()) ||
!idle_protocolVersion.SetCapacity(mHttp.data[i].idle.Length())) {
mHttp.cb = nullptr;
mHttp.data.Clear();
JS_ReportOutOfMemory(cx);
@ -194,6 +201,7 @@ Dashboard::GetHttpConnections()
for (uint32_t j = 0; j < mHttp.data[i].idle.Length(); j++) {
*idle_rtt.AppendElement() = mHttp.data[i].idle[j].rtt;
*idle_ttl.AppendElement() = mHttp.data[i].idle[j].ttl;
*idle_protocolVersion.AppendElement() = mHttp.data[i].idle[j].protocolVersion;
}
}
@ -436,4 +444,31 @@ Dashboard::GetDNSCacheEntries()
return NS_OK;
}
void
HttpConnInfo::SetHTTP1ProtocolVersion(uint8_t pv)
{
switch (pv) {
case NS_HTTP_VERSION_0_9:
protocolVersion.Assign(NS_LITERAL_STRING("http/0.9"));
break;
case NS_HTTP_VERSION_1_0:
protocolVersion.Assign(NS_LITERAL_STRING("http/1.0"));
break;
case NS_HTTP_VERSION_1_1:
protocolVersion.Assign(NS_LITERAL_STRING("http/1.1"));
break;
default:
protocolVersion.Assign(NS_LITERAL_STRING("unknown protocol version"));
}
}
void
HttpConnInfo::SetHTTP2ProtocolVersion(uint8_t pv)
{
if (pv == Spdy::SPDY_VERSION_2)
protocolVersion.Assign(NS_LITERAL_STRING("spdy/2"));
else
protocolVersion.Assign(NS_LITERAL_STRING("spdy/3"));
}
} } // namespace mozilla::net

View File

@ -14,6 +14,7 @@
#include "nsIThread.h"
#include "nsSocketTransport2.h"
#include "mozilla/net/DashboardTypes.h"
#include "nsHttp.h"
namespace mozilla {
namespace net {

View File

@ -34,6 +34,10 @@ struct HttpConnInfo
{
uint32_t ttl;
uint32_t rtt;
nsString protocolVersion;
void SetHTTP1ProtocolVersion(uint8_t pv);
void SetHTTP2ProtocolVersion(uint8_t pv);
};
struct HttpRetParams

View File

@ -71,6 +71,7 @@ nsHttpConnection::nsHttpConnection()
, mReportedSpdy(false)
, mEverUsedSpdy(false)
, mTransactionCaps(0)
, mLastHttpResponseVersion(NS_HTTP_VERSION_1_1)
{
LOG(("Creating nsHttpConnection @%x\n", this));
@ -886,6 +887,8 @@ nsHttpConnection::OnHeadersAvailable(nsAHttpTransaction *trans,
}
}
mLastHttpResponseVersion = responseHead->Version();
return NS_OK;
}

View File

@ -119,6 +119,7 @@ public:
nsresult ResumeSend();
nsresult ResumeRecv();
int64_t MaxBytesRead() {return mMaxBytesRead;}
uint8_t GetLastHttpResponseVersion() { return mLastHttpResponseVersion; }
friend class nsHttpConnectionForceRecv;
nsresult ForceRecv();
@ -134,6 +135,7 @@ public:
void EndIdleMonitoring();
bool UsingSpdy() { return !!mUsingSpdyVersion; }
uint8_t GetSpdyVersion() { return mUsingSpdyVersion; }
bool EverUsedSpdy() { return mEverUsedSpdy; }
PRIntervalTime Rtt() { return mRtt; }
@ -255,6 +257,9 @@ private:
// The capabailities associated with the most recent transaction
uint32_t mTransactionCaps;
// mLastHttpResponseVersion stores the last response's http version seen.
uint8_t mLastHttpResponseVersion;
};
#endif // nsHttpConnection_h__

View File

@ -3321,12 +3321,18 @@ nsHttpConnectionMgr::ReadConnectionEntry(const nsACString &key,
HttpConnInfo info;
info.ttl = ent->mActiveConns[i]->TimeToLive();
info.rtt = ent->mActiveConns[i]->Rtt();
if (ent->mActiveConns[i]->UsingSpdy())
info.SetHTTP2ProtocolVersion(ent->mActiveConns[i]->GetSpdyVersion());
else
info.SetHTTP1ProtocolVersion(ent->mActiveConns[i]->GetLastHttpResponseVersion());
data.active.AppendElement(info);
}
for (uint32_t i = 0; i < ent->mIdleConns.Length(); i++) {
HttpConnInfo info;
info.ttl = ent->mIdleConns[i]->TimeToLive();
info.rtt = ent->mIdleConns[i]->Rtt();
info.SetHTTP1ProtocolVersion(ent->mIdleConns[i]->GetLastHttpResponseVersion());
data.idle.AppendElement(info);
}
data.spdy = ent->mUsingSpdy;