bug 790321 - dont coalesce spdy hosts with socks proxy r=honzab
authorPatrick McManus <mcmanus@ducksong.com>
Sat, 27 Oct 2012 15:24:19 -0400
changeset 111750 7426b782e0b9494109079eb11d915b65cb0e4f58
parent 111749 fdefe523f873a2022d3e0c78026ac87940344f40
child 111751 b9f9c4a12b50ba4f6f88762a2c34b85568711990
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewershonzab
bugs790321
milestone19.0a1
bug 790321 - dont coalesce spdy hosts with socks proxy r=honzab
netwerk/base/src/nsProtocolProxyService.cpp
netwerk/base/src/nsProxyInfo.cpp
netwerk/base/src/nsProxyInfo.h
netwerk/protocol/http/nsHttpConnectionInfo.cpp
netwerk/protocol/http/nsHttpConnectionInfo.h
netwerk/protocol/http/nsHttpConnectionMgr.cpp
--- a/netwerk/base/src/nsProtocolProxyService.cpp
+++ b/netwerk/base/src/nsProtocolProxyService.cpp
@@ -638,23 +638,27 @@ nsProtocolProxyService::CanUseProxy(nsIU
                 if (!PL_strncasecmp(host_tail, hinfo->name.host, filter_host_len))
                     return false; // proxy disallowed
             }
         }
     }
     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,
                                          uint32_t aResolveFlags,
                                          nsProxyInfo **result)
 {
     *result = nullptr;
     uint32_t flags = 0;
--- a/netwerk/base/src/nsProxyInfo.cpp
+++ b/netwerk/base/src/nsProxyInfo.cpp
@@ -5,16 +5,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsProxyInfo.h"
 #include "nsCOMPtr.h"
 
 // Yes, we support QI to nsProxyInfo
 NS_IMPL_THREADSAFE_ISUPPORTS2(nsProxyInfo, nsProxyInfo, nsIProxyInfo) 
 
+using namespace mozilla;
+
 NS_IMETHODIMP
 nsProxyInfo::GetHost(nsACString &result)
 {
   result = mHost;
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -63,8 +65,40 @@ NS_IMETHODIMP
 nsProxyInfo::SetFailoverProxy(nsIProxyInfo *proxy)
 {
   nsCOMPtr<nsProxyInfo> pi = do_QueryInterface(proxy);
   NS_ENSURE_ARG(pi);
 
   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;
+}
+
--- a/netwerk/base/src/nsProxyInfo.h
+++ b/netwerk/base/src/nsProxyInfo.h
@@ -31,16 +31,20 @@ public:
   NS_DECL_NSIPROXYINFO
 
   // Cheap accessors for use within Necko
   const nsCString &Host()  { return mHost; }
   int32_t          Port()  { return mPort; }
   const char      *Type()  { return mType; }
   uint32_t         Flags() { return mFlags; }
 
+  bool IsDirect();
+  bool IsHTTP();
+  bool IsSOCKS();
+
 private:
   friend class nsProtocolProxyService;
 
   nsProxyInfo(const char *type = nullptr)
     : mType(type)
     , mPort(-1)
     , mFlags(0)
     , mResolveFlags(0)
--- a/netwerk/protocol/http/nsHttpConnectionInfo.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionInfo.cpp
@@ -72,8 +72,16 @@ nsHttpConnectionInfo::Clone() const
 
     // Make sure the anonymous and private flags are transferred!
     clone->SetAnonymous(GetAnonymous());
     clone->SetPrivate(GetPrivate());
 
     return clone;
 }
 
+bool
+nsHttpConnectionInfo::UsingProxy()
+{
+    if (!mProxyInfo)
+        return false;
+    return !mProxyInfo->IsDirect();
+}
+
--- a/netwerk/protocol/http/nsHttpConnectionInfo.h
+++ b/netwerk/protocol/http/nsHttpConnectionInfo.h
@@ -27,17 +27,17 @@ public:
                          bool usingSSL=false)
         : mRef(0)
         , mProxyInfo(proxyInfo)
         , mUsingSSL(usingSSL)
         , mUsingConnect(false)
     {
         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
             uint32_t resolveFlags = 0;
             if (NS_SUCCEEDED(mProxyInfo->GetResolveFlags(&resolveFlags)) &&
                 resolveFlags & nsIProtocolProxyService::RESOLVE_ALWAYS_TUNNEL) {
                 mUsingConnect = true;
             }
@@ -105,16 +105,19 @@ public:
     void          SetAnonymous(bool anon)         
                                          { mHashKey.SetCharAt(anon ? 'A' : '.', 2); }
     bool          GetAnonymous() const   { return mHashKey.CharAt(2) == 'A'; }
     void          SetPrivate(bool priv)  { mHashKey.SetCharAt(priv ? 'P' : '.', 3); }
     bool          GetPrivate() const     { return mHashKey.CharAt(3) == 'P'; }
 
     const nsCString &GetHost() { return mHost; }
 
+    // Returns true for any kind of proxy (http, socks, etc..)
+    bool UsingProxy();
+
 private:
     nsrefcnt               mRef;
     nsCString              mHashKey;
     nsCString              mHost;
     int32_t                mPort;
     nsCOMPtr<nsProxyInfo>  mProxyInfo;
     bool                   mUsingHttpProxy;
     bool                   mUsingSSL;
--- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
@@ -2761,17 +2761,17 @@ nsHttpConnectionMgr::nsHalfOpenSocket::O
     // for this entry before then make the hash key if our dns lookup
     // just completed. We can't do coalescing if using a proxy because the
     // ip addresses are not available to the client.
 
     if (status == NS_NET_STATUS_CONNECTED_TO &&
         gHttpHandler->IsSpdyEnabled() &&
         gHttpHandler->CoalesceSpdy() &&
         mEnt && mEnt->mConnInfo && mEnt->mConnInfo->UsingSSL() &&
-        !mEnt->mConnInfo->UsingHttpProxy() &&
+        !mEnt->mConnInfo->UsingProxy() &&
         mEnt->mCoalescingKey.IsEmpty()) {
 
         PRNetAddr addr;
         nsresult rv = mSocketTransport->GetPeerAddr(&addr);
         if (NS_SUCCEEDED(rv)) {
             mEnt->mCoalescingKey.SetCapacity(72);
             PR_NetAddrToString(&addr, mEnt->mCoalescingKey.BeginWriting(), 64);
             mEnt->mCoalescingKey.SetLength(