From e9c52b0e321461e09162a383f74527d2f69a6bfd Mon Sep 17 00:00:00 2001 From: Patrick McManus Date: Sat, 27 Oct 2012 15:24:19 -0400 Subject: [PATCH] bug 790321 - dont coalesce spdy hosts with socks proxy r=honzab --- netwerk/base/src/nsProtocolProxyService.cpp | 18 ++++++---- netwerk/base/src/nsProxyInfo.cpp | 34 +++++++++++++++++++ netwerk/base/src/nsProxyInfo.h | 4 +++ .../protocol/http/nsHttpConnectionInfo.cpp | 8 +++++ netwerk/protocol/http/nsHttpConnectionInfo.h | 5 ++- netwerk/protocol/http/nsHttpConnectionMgr.cpp | 2 +- 6 files changed, 62 insertions(+), 9 deletions(-) diff --git a/netwerk/base/src/nsProtocolProxyService.cpp b/netwerk/base/src/nsProtocolProxyService.cpp index 424366ac97fc..267be09b41b9 100644 --- a/netwerk/base/src/nsProtocolProxyService.cpp +++ b/netwerk/base/src/nsProtocolProxyService.cpp @@ -643,13 +643,17 @@ nsProtocolProxyService::CanUseProxy(nsIURI *aURI, int32_t defaultPort) return true; } -static const char kProxyType_HTTP[] = "http"; -static const char kProxyType_PROXY[] = "proxy"; -static const char kProxyType_SOCKS[] = "socks"; -static const char kProxyType_SOCKS4[] = "socks4"; -static const char kProxyType_SOCKS5[] = "socks5"; -static const char kProxyType_DIRECT[] = "direct"; -static const char kProxyType_UNKNOWN[] = "unknown"; +// kProxyType\* may be referred to externally in +// nsProxyInfo in order to compare by string pointer +namespace mozilla { +const char *kProxyType_HTTP = "http"; +const char *kProxyType_PROXY = "proxy"; +const char *kProxyType_SOCKS = "socks"; +const char *kProxyType_SOCKS4 = "socks4"; +const char *kProxyType_SOCKS5 = "socks5"; +const char *kProxyType_DIRECT = "direct"; +const char *kProxyType_UNKNOWN = "unknown"; +} const char * nsProtocolProxyService::ExtractProxyInfo(const char *start, diff --git a/netwerk/base/src/nsProxyInfo.cpp b/netwerk/base/src/nsProxyInfo.cpp index 31803e39b62a..d21e579f3c48 100644 --- a/netwerk/base/src/nsProxyInfo.cpp +++ b/netwerk/base/src/nsProxyInfo.cpp @@ -10,6 +10,8 @@ // Yes, we support QI to nsProxyInfo NS_IMPL_THREADSAFE_ISUPPORTS2(nsProxyInfo, nsProxyInfo, nsIProxyInfo) +using namespace mozilla; + NS_IMETHODIMP nsProxyInfo::GetHost(nsACString &result) { @@ -68,3 +70,35 @@ nsProxyInfo::SetFailoverProxy(nsIProxyInfo *proxy) pi.swap(mNext); return NS_OK; } + +// These pointers are declared in nsProtocolProxyService.cpp and +// comparison of mType by string pointer is valid within necko +namespace mozilla { + extern const char *kProxyType_HTTP; + extern const char *kProxyType_SOCKS; + extern const char *kProxyType_SOCKS4; + extern const char *kProxyType_SOCKS5; + extern const char *kProxyType_DIRECT; +} + +bool +nsProxyInfo::IsDirect() +{ + if (!mType) + return true; + return mType == kProxyType_DIRECT; +} + +bool +nsProxyInfo::IsHTTP() +{ + return mType == kProxyType_HTTP; +} + +bool +nsProxyInfo::IsSOCKS() +{ + return mType == kProxyType_SOCKS || + mType == kProxyType_SOCKS4 || mType == kProxyType_SOCKS5; +} + diff --git a/netwerk/base/src/nsProxyInfo.h b/netwerk/base/src/nsProxyInfo.h index bfb5af4970f4..9f11f041f423 100644 --- a/netwerk/base/src/nsProxyInfo.h +++ b/netwerk/base/src/nsProxyInfo.h @@ -36,6 +36,10 @@ public: const char *Type() { return mType; } uint32_t Flags() { return mFlags; } + bool IsDirect(); + bool IsHTTP(); + bool IsSOCKS(); + private: friend class nsProtocolProxyService; diff --git a/netwerk/protocol/http/nsHttpConnectionInfo.cpp b/netwerk/protocol/http/nsHttpConnectionInfo.cpp index e1dc1a310988..5cfcf3fa7fb6 100644 --- a/netwerk/protocol/http/nsHttpConnectionInfo.cpp +++ b/netwerk/protocol/http/nsHttpConnectionInfo.cpp @@ -77,3 +77,11 @@ nsHttpConnectionInfo::Clone() const return clone; } +bool +nsHttpConnectionInfo::UsingProxy() +{ + if (!mProxyInfo) + return false; + return !mProxyInfo->IsDirect(); +} + diff --git a/netwerk/protocol/http/nsHttpConnectionInfo.h b/netwerk/protocol/http/nsHttpConnectionInfo.h index 987bedade871..ec43c0dcb738 100644 --- a/netwerk/protocol/http/nsHttpConnectionInfo.h +++ b/netwerk/protocol/http/nsHttpConnectionInfo.h @@ -32,7 +32,7 @@ public: { LOG(("Creating nsHttpConnectionInfo @%x\n", this)); - mUsingHttpProxy = (proxyInfo && !nsCRT::strcmp(proxyInfo->Type(), "http")); + mUsingHttpProxy = (proxyInfo && proxyInfo->IsHTTP()); if (mUsingHttpProxy) { mUsingConnect = mUsingSSL; // SSL always uses CONNECT @@ -110,6 +110,9 @@ public: const nsCString &GetHost() { return mHost; } + // Returns true for any kind of proxy (http, socks, etc..) + bool UsingProxy(); + private: nsrefcnt mRef; nsCString mHashKey; diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp index 846a0a882f58..0209363df4a8 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp +++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp @@ -2766,7 +2766,7 @@ nsHttpConnectionMgr::nsHalfOpenSocket::OnTransportStatus(nsITransport *trans, gHttpHandler->IsSpdyEnabled() && gHttpHandler->CoalesceSpdy() && mEnt && mEnt->mConnInfo && mEnt->mConnInfo->UsingSSL() && - !mEnt->mConnInfo->UsingHttpProxy() && + !mEnt->mConnInfo->UsingProxy() && mEnt->mCoalescingKey.IsEmpty()) { PRNetAddr addr;