bug 378637 part 8 - add https proxy info type r=hurley
authorPatrick McManus <mcmanus@ducksong.com>
Tue, 15 Apr 2014 18:16:41 -0400
changeset 183603 3b293e8b4713
parent 183602 a6a1c61cba7d
child 183604 c3d1fc8d2c26
push id26799
push userphilringnalda@gmail.com
push date2014-05-18 00:55 +0000
treeherdermozilla-central@00ef3a7d7aa7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershurley
bugs378637
milestone32.0a1
bug 378637 part 8 - add https proxy info type r=hurley
netwerk/base/src/ProxyAutoConfig.h
netwerk/base/src/nsProtocolProxyService.cpp
netwerk/base/src/nsProxyInfo.cpp
netwerk/base/src/nsProxyInfo.h
--- a/netwerk/base/src/ProxyAutoConfig.h
+++ b/netwerk/base/src/ProxyAutoConfig.h
@@ -39,17 +39,17 @@ public:
 
   /**
    * Get the proxy string for the specified URI.  The proxy string is
    * given by the following:
    *
    *   result      = proxy-spec *( proxy-sep proxy-spec )
    *   proxy-spec  = direct-type | proxy-type LWS proxy-host [":" proxy-port]
    *   direct-type = "DIRECT"
-   *   proxy-type  = "PROXY" | "SOCKS" | "SOCKS4" | "SOCKS5"
+   *   proxy-type  = "PROXY" | "HTTP" | "HTTPS" | "SOCKS" | "SOCKS4" | "SOCKS5"
    *   proxy-sep   = ";" LWS
    *   proxy-host  = hostname | ipv4-address-literal
    *   proxy-port  = <any 16-bit unsigned integer>
    *   LWS         = *( SP | HT )
    *   SP          = <US-ASCII SP, space (32)>
    *   HT          = <US-ASCII HT, horizontal-tab (9)>
    *
    * NOTE: direct-type and proxy-type are case insensitive
--- a/netwerk/base/src/nsProtocolProxyService.cpp
+++ b/netwerk/base/src/nsProtocolProxyService.cpp
@@ -29,16 +29,17 @@
 #include "mozilla/Mutex.h"
 #include "mozilla/CondVar.h"
 #include "nsISystemProxySettings.h"
 
 //----------------------------------------------------------------------------
 
 namespace mozilla {
   extern const char kProxyType_HTTP[];
+  extern const char kProxyType_HTTPS[];
   extern const char kProxyType_SOCKS[];
   extern const char kProxyType_SOCKS4[];
   extern const char kProxyType_SOCKS5[];
   extern const char kProxyType_DIRECT[];
 }
 
 using namespace mozilla;
 
@@ -653,16 +654,17 @@ nsProtocolProxyService::CanUseProxy(nsIU
     }
     return true;
 }
 
 // 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_HTTPS[]   = "https";
 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 *
@@ -681,21 +683,29 @@ nsProtocolProxyService::ExtractProxyInfo
 
     // find end of proxy type delimiter
     const char *sp = start;
     while (sp < end && *sp != ' ' && *sp != '\t') ++sp;
 
     uint32_t len = sp - start;
     const char *type = nullptr;
     switch (len) {
+    case 4:
+        if (PL_strncasecmp(start, kProxyType_HTTP, 5) == 0) {
+            type = kProxyType_HTTP;
+        }
+        break;
     case 5:
-        if (PL_strncasecmp(start, kProxyType_PROXY, 5) == 0)
+        if (PL_strncasecmp(start, kProxyType_PROXY, 5) == 0) {
             type = kProxyType_HTTP;
-        else if (PL_strncasecmp(start, kProxyType_SOCKS, 5) == 0)
+        } else if (PL_strncasecmp(start, kProxyType_SOCKS, 5) == 0) {
             type = kProxyType_SOCKS4; // assume v4 for 4x compat
+        } else if (PL_strncasecmp(start, kProxyType_HTTPS, 5) == 0) {
+            type = kProxyType_HTTPS;
+        }
         break;
     case 6:
         if (PL_strncasecmp(start, kProxyType_DIRECT, 6) == 0)
             type = kProxyType_DIRECT;
         else if (PL_strncasecmp(start, kProxyType_SOCKS4, 6) == 0)
             type = kProxyType_SOCKS4;
         else if (PL_strncasecmp(start, kProxyType_SOCKS5, 6) == 0)
             // map "SOCKS5" to "socks" to match contract-id of registered
@@ -714,20 +724,23 @@ nsProtocolProxyService::ExtractProxyInfo
             flags |= nsIProxyInfo::TRANSPARENT_PROXY_RESOLVES_HOST;
 
         // extract host:port
         start = sp;
         while ((*start == ' ' || *start == '\t') && start < end)
             start++;
 
         // port defaults
-        if (type == kProxyType_HTTP)
+        if (type == kProxyType_HTTP) {
             port = 80;
-        else
+        } else if (type == kProxyType_HTTPS) {
+            port = 443;
+        } else {
             port = 1080;
+        }
 
         nsProxyInfo *pi = new nsProxyInfo();
         pi->mType = type;
         pi->mFlags = flags;
         pi->mResolveFlags = aResolveFlags;
         pi->mTimeout = mFailedProxyTimeout;
 
         // www.foo.com:8080 and http://www.foo.com:8080
@@ -1157,25 +1170,26 @@ nsProtocolProxyService::NewProxyInfo(con
                                      int32_t aPort,
                                      uint32_t aFlags,
                                      uint32_t aFailoverTimeout,
                                      nsIProxyInfo *aFailoverProxy,
                                      nsIProxyInfo **aResult)
 {
     static const char *types[] = {
         kProxyType_HTTP,
+        kProxyType_HTTPS,
         kProxyType_SOCKS,
         kProxyType_SOCKS4,
         kProxyType_DIRECT
     };
 
     // resolve type; this allows us to avoid copying the type string into each
     // proxy info instance.  we just reference the string literals directly :)
     const char *type = nullptr;
-    for (uint32_t i=0; i<ArrayLength(types); ++i) {
+    for (uint32_t i = 0; i < ArrayLength(types); ++i) {
         if (aType.LowerCaseEqualsASCII(types[i])) {
             type = types[i];
             break;
         }
     }
     NS_ENSURE_TRUE(type, NS_ERROR_INVALID_ARG);
 
     if (aPort <= 0)
@@ -1720,17 +1734,18 @@ nsProtocolProxyService::PruneProxyInfo(c
     //
     // Pruning of disallowed proxies works like this:
     //   - If the protocol handler disallows the proxy, then we disallow it.
 
     // Start by removing all disallowed proxies if required:
     if (!(info.flags & nsIProtocolHandler::ALLOWS_PROXY_HTTP)) {
         nsProxyInfo *last = nullptr, *iter = head;
         while (iter) {
-            if (iter->Type() == kProxyType_HTTP) {
+            if ((iter->Type() == kProxyType_HTTP) ||
+                (iter->Type() == kProxyType_HTTPS)) {
                 // reject!
                 if (last)
                     last->mNext = iter->mNext;
                 else
                     head = iter->mNext;
                 nsProxyInfo *next = iter->mNext;
                 iter->mNext = nullptr;
                 iter->Release();
--- a/netwerk/base/src/nsProxyInfo.cpp
+++ b/netwerk/base/src/nsProxyInfo.cpp
@@ -70,16 +70,17 @@ nsProxyInfo::SetFailoverProxy(nsIProxyIn
   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_HTTPS[];
   extern const char kProxyType_SOCKS[];
   extern const char kProxyType_SOCKS4[];
   extern const char kProxyType_SOCKS5[];
   extern const char kProxyType_DIRECT[];
 }
 
 bool
 nsProxyInfo::IsDirect()
@@ -91,14 +92,20 @@ nsProxyInfo::IsDirect()
 
 bool
 nsProxyInfo::IsHTTP()
 {
   return mType == kProxyType_HTTP;
 }
 
 bool
+nsProxyInfo::IsHTTPS()
+{
+  return mType == kProxyType_HTTPS;
+}
+
+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
@@ -33,16 +33,17 @@ public:
   // 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 IsHTTPS();
   bool IsSOCKS();
 
 private:
   friend class nsProtocolProxyService;
 
   nsProxyInfo(const char *type = nullptr)
     : mType(type)
     , mPort(-1)