bug 528288 - spdy: early configuration of npn negotiation from IsAlive() r=honzab

patch 1
This commit is contained in:
Patrick McManus 2011-12-02 10:28:57 -05:00
parent ce94c7ff4d
commit e502b4dfee
2 changed files with 47 additions and 27 deletions

View File

@ -86,6 +86,7 @@ nsHttpConnection::nsHttpConnection()
, mLastTransactionExpectedNoContent(false)
, mIdleMonitoring(false)
, mNPNComplete(false)
, mSetupNPNCalled(false)
, mUsingSpdy(false)
, mPriority(nsISupportsPriority::PRIORITY_NORMAL)
, mReportedSpdy(false)
@ -247,33 +248,7 @@ nsHttpConnection::Activate(nsAHttpTransaction *trans, PRUint8 caps, PRInt32 pri)
mCallbackTarget = callbackTarget;
}
// Setup NPN Negotiation if necessary (only for SPDY)
if (!mNPNComplete) {
mNPNComplete = true;
if (mConnInfo->UsingSSL() &&
!(caps & NS_HTTP_DISALLOW_SPDY) &&
gHttpHandler->IsSpdyEnabled()) {
LOG(("nsHttpConnection::Init Setting up SPDY Negotiation"));
nsCOMPtr<nsISupports> securityInfo;
nsresult rv =
mSocketTransport->GetSecurityInfo(getter_AddRefs(securityInfo));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISSLSocketControl> ssl =
do_QueryInterface(securityInfo, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsTArray<nsCString> protocolArray;
protocolArray.AppendElement(NS_LITERAL_CSTRING("spdy/2"));
protocolArray.AppendElement(NS_LITERAL_CSTRING("http/1.1"));
if (NS_SUCCEEDED(ssl->SetNPNList(protocolArray))) {
LOG(("nsHttpConnection::Init Setting up SPDY Negotiation OK"));
mNPNComplete = false;
}
}
}
SetupNPN(caps); // only for spdy
// take ownership of the transaction
mTransaction = trans;
@ -307,6 +282,45 @@ failed_activation:
return rv;
}
void
nsHttpConnection::SetupNPN(PRUint8 caps)
{
if (mSetupNPNCalled) /* do only once */
return;
mSetupNPNCalled = true;
// Setup NPN Negotiation if necessary (only for SPDY)
if (!mNPNComplete) {
mNPNComplete = true;
if (mConnInfo->UsingSSL() &&
!(caps & NS_HTTP_DISALLOW_SPDY) &&
gHttpHandler->IsSpdyEnabled()) {
LOG(("nsHttpConnection::Init Setting up SPDY Negotiation"));
nsCOMPtr<nsISupports> securityInfo;
nsresult rv =
mSocketTransport->GetSecurityInfo(getter_AddRefs(securityInfo));
if (NS_FAILED(rv))
return;
nsCOMPtr<nsISSLSocketControl> ssl =
do_QueryInterface(securityInfo, &rv);
if (NS_FAILED(rv))
return;
nsTArray<nsCString> protocolArray;
protocolArray.AppendElement(NS_LITERAL_CSTRING("spdy/2"));
protocolArray.AppendElement(NS_LITERAL_CSTRING("http/1.1"));
if (NS_SUCCEEDED(ssl->SetNPNList(protocolArray))) {
LOG(("nsHttpConnection::Init Setting up SPDY Negotiation OK"));
mNPNComplete = false;
}
}
}
}
nsresult
nsHttpConnection::AddTransaction(nsAHttpTransaction *httpTransaction,
PRInt32 priority)
@ -435,6 +449,10 @@ nsHttpConnection::IsAlive()
if (!mSocketTransport)
return false;
// SocketTransport::IsAlive can run the SSL state machine, so make sure
// the NPN options are set before that happens.
SetupNPN(0);
bool alive;
nsresult rv = mSocketTransport->IsAlive(&alive);
if (NS_FAILED(rv))

View File

@ -174,6 +174,7 @@ private:
// Makes certain the SSL handshake is complete and NPN negotiation
// has had a chance to happen
bool EnsureNPNComplete();
void SetupNPN(PRUint8 caps);
// Directly Add a transaction to an active connection for SPDY
nsresult AddTransaction(nsAHttpTransaction *, PRInt32);
@ -218,6 +219,7 @@ private:
// SPDY related
bool mNPNComplete;
bool mSetupNPNCalled;
bool mUsingSpdy;
nsRefPtr<mozilla::net::SpdySession> mSpdySession;
PRInt32 mPriority;