using System.Net.Configuration;
using System.Security.Cryptography.X509Certificates;
+#if NET_2_0
+using System.Net.Security;
+#endif
+
//
// notes:
// A service point manager manages service points (duh!).
{
public class ServicePointManager
{
+ class SPKey {
+ Uri uri; // schema/host/port
+ bool use_connect;
+
+ public SPKey (Uri uri, bool use_connect) {
+ this.uri = uri;
+ this.use_connect = use_connect;
+ }
+
+ public Uri Uri {
+ get { return uri; }
+ }
+
+ public bool UseConnect {
+ get { return use_connect; }
+ }
+
+ public override int GetHashCode () {
+ return uri.GetHashCode () + ((use_connect) ? 1 : 0);
+ }
+
+ public override bool Equals (object obj) {
+ SPKey other = obj as SPKey;
+ if (obj == null) {
+ return false;
+ }
+
+ return (uri.Equals (other.uri) && other.use_connect == use_connect);
+ }
+ }
+
private static HybridDictionary servicePoints = new HybridDictionary ();
// Static properties
private static int maxServicePointIdleTime = 900000; // 15 minutes
private static int maxServicePoints = 0;
private static bool _checkCRL = false;
-#if (NET_1_0 || NET_1_1)
- private static SecurityProtocolType _securityProtocol = SecurityProtocolType.Ssl3;
-#else
- private static SecurityProtocolType _securityProtocol = SecurityProtocolType.Default;
-#endif
+ private static SecurityProtocolType _securityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
+
#if NET_1_1
+#if TARGET_JVM
+ static bool expectContinue = false;
+#else
static bool expectContinue = true;
+#endif
static bool useNagle;
#endif
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);
+
+ defaultConnectionLimit = (int) manager.GetMaxConnections ("*");
+ return;
+ }
+#endif
manager = (ConnectionManagementData) ConfigurationSettings.GetConfig (configKey);
+ if (manager != null) {
+ defaultConnectionLimit = (int) manager.GetMaxConnections ("*");
+ }
}
+
// Constructors
private ServicePointManager ()
{
// Properties
+#if NET_2_0
+ [Obsolete ("Use ServerCertificateValidationCallback instead",
+ false)]
+#endif
public static ICertificatePolicy CertificatePolicy {
get { return policy; }
set { policy = value; }
defaultConnectionLimit = value;
}
}
+
+#if NET_2_0
+ static Exception GetMustImplement ()
+ {
+ return new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public static int DnsRefreshTimeout
+ {
+ get {
+ throw GetMustImplement ();
+ }
+ set {
+ throw GetMustImplement ();
+ }
+ }
+
+ [MonoTODO]
+ public static bool EnableDnsRoundRobin
+ {
+ get {
+ throw GetMustImplement ();
+ }
+ set {
+ throw GetMustImplement ();
+ }
+ }
+#endif
public static int MaxServicePointIdleTime {
get {
set { _securityProtocol = value; }
}
+#if NET_2_0 && SECURITY_DEP
+ [MonoTODO]
+ public static RemoteCertificateValidationCallback ServerCertificateValidationCallback
+ {
+ get {
+ throw GetMustImplement ();
+ }
+ set {
+ throw GetMustImplement ();
+ }
+ }
+#endif
+
#if NET_1_1
public static bool Expect100Continue {
get { return expectContinue; }
{
return FindServicePoint (new Uri(uriString), proxy);
}
-
+
public static ServicePoint FindServicePoint (Uri address, IWebProxy proxy)
{
if (address == null)
ServicePoint sp = null;
lock (servicePoints) {
- sp = servicePoints [address] as ServicePoint;
+ SPKey key = new SPKey (address, useConnect);
+ sp = servicePoints [key] as ServicePoint;
if (sp != null)
return sp;
#endif
sp.UsesProxy = usesProxy;
sp.UseConnect = useConnect;
- servicePoints.Add (address, sp);
+ servicePoints.Add (key, sp);
}
return sp;
ServicePoint sp = (ServicePoint) e.Value;
if (sp.CurrentConnections == 0) {
while (list.ContainsKey (sp.IdleSince))
- sp.IdleSince.AddMilliseconds (1);
+ sp.IdleSince = sp.IdleSince.AddMilliseconds (1);
list.Add (sp.IdleSince, sp.Address);
}
}