New test.
[mono.git] / mcs / class / System / System.Net / ServicePointManager.cs
index ca176694532196367d4c056ea3802c489cfc4a53..7db019a9a76351d264df94b1ebe696f27df44efc 100644 (file)
@@ -84,8 +84,20 @@ namespace System.Net
                
                static ServicePointManager ()
                {
+#if NET_2_0 && CONFIGURATION_DEP
+                       object cfg = ConfigurationManager.GetSection (configKey);
+                       ConnectionManagementSection s = cfg as ConnectionManagementSection;
+                       if (s != null) {
+                               manager = new ConnectionManagementData (null);
+                               foreach (ConnectionManagementElement e in s.ConnectionManagement)
+                                       manager.Add (e.Address, e.MaxConnection);
+
+                               return;
+                       }
+#endif
                        manager = (ConnectionManagementData) ConfigurationSettings.GetConfig (configKey);
                }
+
                // Constructors
                private ServicePointManager ()
                {
@@ -186,18 +198,24 @@ namespace System.Net
                        RecycleServicePoints ();
                        
                        bool usesProxy = false;
+                       bool useConnect = false;
                        if (proxy != null && !proxy.IsBypassed(address)) {
                                usesProxy = true;
+                               bool isSecure = address.Scheme == "https";
                                address = proxy.GetProxy (address);
-                               if (address.Scheme != "http" && address.Scheme != "https")
+                               if (address.Scheme != "http" && !isSecure)
                                        throw new NotSupportedException ("Proxy scheme not supported.");
+
+                               if (isSecure && address.Scheme == "http")
+                                       useConnect = true;
                        } 
 
                        address = new Uri (address.Scheme + "://" + address.Authority);
                        
                        ServicePoint sp = null;
                        lock (servicePoints) {
-                               sp = servicePoints [address] as ServicePoint;
+                               int key = address.GetHashCode () + (int) ((useConnect) ? 1 : 0);
+                               sp = servicePoints [key] as ServicePoint;
                                if (sp != null)
                                        return sp;
 
@@ -212,7 +230,8 @@ namespace System.Net
                                sp.UseNagleAlgorithm = useNagle;
 #endif
                                sp.UsesProxy = usesProxy;
-                               servicePoints.Add (address, sp);
+                               sp.UseConnect = useConnect;
+                               servicePoints.Add (key, sp);
                        }
                        
                        return sp;