Bug 459724. Make page reload bypass the DNS cache. r+sr=bzbarsky

This commit is contained in:
Patrick McManus 2008-11-04 11:05:46 -05:00
Родитель 03ce3578bd
Коммит c7c2671792
7 изменённых файлов: 54 добавлений и 6 удалений

Просмотреть файл

@ -51,7 +51,7 @@ native PRNetAddr(union PRNetAddr);
* NOTE: This is a free-threaded interface, meaning that the methods on * NOTE: This is a free-threaded interface, meaning that the methods on
* this interface may be called from any thread. * this interface may be called from any thread.
*/ */
[scriptable, uuid(66418cc8-5f5d-4f52-a7f9-db8fb3b2cfe6)] [scriptable, uuid(ef3f4993-cfbc-4e5a-9509-16deafe16549)]
interface nsISocketTransport : nsITransport interface nsISocketTransport : nsITransport
{ {
/** /**
@ -134,6 +134,22 @@ interface nsISocketTransport : nsITransport
const unsigned long STATUS_SENDING_TO = 0x804b0005; const unsigned long STATUS_SENDING_TO = 0x804b0005;
const unsigned long STATUS_WAITING_FOR = 0x804b000a; const unsigned long STATUS_WAITING_FOR = 0x804b000a;
const unsigned long STATUS_RECEIVING_FROM = 0x804b0006; const unsigned long STATUS_RECEIVING_FROM = 0x804b0006;
/**
* connectionFlags is a bitmask that can be used to modify underlying
* behavior of the socket connection.
*/
attribute unsigned long connectionFlags;
/**
* Values for the connectionFlags
*
* When making a new connection BYPASS_CACHE will force the Necko DNS
* cache entry to be refreshed with a new call to NSPR if it is set before
* opening the new stream.
*/
const unsigned long BYPASS_CACHE = (1 << 0);
}; };
%{C++ %{C++

Просмотреть файл

@ -707,6 +707,7 @@ nsSocketTransport::nsSocketTransport()
, mProxyPort(0) , mProxyPort(0)
, mProxyTransparent(PR_FALSE) , mProxyTransparent(PR_FALSE)
, mProxyTransparentResolvesHost(PR_FALSE) , mProxyTransparentResolvesHost(PR_FALSE)
, mConnectionFlags(0)
, mState(STATE_CLOSED) , mState(STATE_CLOSED)
, mAttached(PR_FALSE) , mAttached(PR_FALSE)
, mInputClosed(PR_TRUE) , mInputClosed(PR_TRUE)
@ -946,7 +947,11 @@ nsSocketTransport::ResolveHost()
mResolving = PR_TRUE; mResolving = PR_TRUE;
rv = dns->AsyncResolve(SocketHost(), 0, this, nsnull, PRUint32 dnsFlags = 0;
if (mConnectionFlags & nsSocketTransport::BYPASS_CACHE)
dnsFlags = nsIDNSService::RESOLVE_BYPASS_CACHE;
rv = dns->AsyncResolve(SocketHost(), dnsFlags, this, nsnull,
getter_AddRefs(mDNSRequest)); getter_AddRefs(mDNSRequest));
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
LOG((" advancing to STATE_RESOLVING\n")); LOG((" advancing to STATE_RESOLVING\n"));
@ -1946,6 +1951,21 @@ nsSocketTransport::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
} }
NS_IMETHODIMP
nsSocketTransport::GetConnectionFlags(PRUint32 *value)
{
*value = mConnectionFlags;
return NS_OK;
}
NS_IMETHODIMP
nsSocketTransport::SetConnectionFlags(PRUint32 value)
{
mConnectionFlags = value;
return NS_OK;
}
#ifdef ENABLE_SOCKET_TRACING #ifdef ENABLE_SOCKET_TRACING
#include <stdio.h> #include <stdio.h>

Просмотреть файл

@ -202,7 +202,8 @@ private:
PRUint16 mProxyPort; PRUint16 mProxyPort;
PRPackedBool mProxyTransparent; PRPackedBool mProxyTransparent;
PRPackedBool mProxyTransparentResolvesHost; PRPackedBool mProxyTransparentResolvesHost;
PRUint32 mConnectionFlags;
PRUint16 SocketPort() { return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyPort : mPort; } PRUint16 SocketPort() { return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyPort : mPort; }
const nsCString &SocketHost() { return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyHost : mHost; } const nsCString &SocketHost() { return (!mProxyHost.IsEmpty() && !mProxyTransparent) ? mProxyHost : mHost; }

Просмотреть файл

@ -104,6 +104,10 @@ typedef PRUint8 nsHttpVersion;
// preventing it from being reclaimed, even after the transaction completes. // preventing it from being reclaimed, even after the transaction completes.
#define NS_HTTP_STICKY_CONNECTION (1<<2) #define NS_HTTP_STICKY_CONNECTION (1<<2)
// a transaction with this caps flag will, upon opening a new connection,
// bypass the local DNS cache
#define NS_HTTP_REFRESH_DNS (1<<3)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// some default values // some default values
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

Просмотреть файл

@ -4010,6 +4010,10 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
if (mRequestHead.HasHeaderValue(nsHttp::Connection, "close")) if (mRequestHead.HasHeaderValue(nsHttp::Connection, "close"))
mCaps &= ~(NS_HTTP_ALLOW_KEEPALIVE | NS_HTTP_ALLOW_PIPELINING); mCaps &= ~(NS_HTTP_ALLOW_KEEPALIVE | NS_HTTP_ALLOW_PIPELINING);
if ((mLoadFlags & VALIDATE_ALWAYS) ||
(BYPASS_LOCAL_CACHE(mLoadFlags)))
mCaps |= NS_HTTP_REFRESH_DNS;
mIsPending = PR_TRUE; mIsPending = PR_TRUE;
mWasOpened = PR_TRUE; mWasOpened = PR_TRUE;

Просмотреть файл

@ -140,7 +140,7 @@ nsHttpConnection::Activate(nsAHttpTransaction *trans, PRUint8 caps)
// if we don't have a socket transport then create a new one // if we don't have a socket transport then create a new one
if (!mSocketTransport) { if (!mSocketTransport) {
rv = CreateTransport(); rv = CreateTransport(caps);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
goto loser; goto loser;
} }
@ -424,7 +424,7 @@ nsHttpConnection::ResumeRecv()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
nsresult nsresult
nsHttpConnection::CreateTransport() nsHttpConnection::CreateTransport(PRUint8 caps)
{ {
nsresult rv; nsresult rv;
@ -452,6 +452,9 @@ nsHttpConnection::CreateTransport()
getter_AddRefs(strans)); getter_AddRefs(strans));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (caps & NS_HTTP_REFRESH_DNS)
strans->SetConnectionFlags(nsISocketTransport::BYPASS_CACHE);
// NOTE: these create cyclical references, which we break inside // NOTE: these create cyclical references, which we break inside
// nsHttpConnection::Close // nsHttpConnection::Close
rv = strans->SetEventSink(this, nsnull); rv = strans->SetEventSink(this, nsnull);

Просмотреть файл

@ -125,7 +125,7 @@ private:
// called to cause the underlying socket to start speaking SSL // called to cause the underlying socket to start speaking SSL
nsresult ProxyStartSSL(); nsresult ProxyStartSSL();
nsresult CreateTransport(); nsresult CreateTransport(PRUint8 caps);
nsresult OnTransactionDone(nsresult reason); nsresult OnTransactionDone(nsresult reason);
nsresult OnSocketWritable(); nsresult OnSocketWritable();
nsresult OnSocketReadable(); nsresult OnSocketReadable();