Author: gonzalo
Date: 2006-11-01 15:50:41 -0500 (Wed, 01 Nov 2006)
New Revision: 67243
Modified:
trunk/mcs/class/System/System.Net/ChangeLog
trunk/mcs/class/System/System.Net/GlobalProxySelection.cs
trunk/mcs/class/System/System.Net/WebRequest.cs
Log:
2006-11-01 Michael Hutchinson <[EMAIL PROTECTED]>
* GlobalProxySelection.cs: Obsolete GlobalProxySelection under 2.0
profile, and move code to new property WebRequest.DefaultWebProxy.
* WebRequest.cs: Implement new 2.0 property DefaultWebProxy.
Add support for config option UseSystemDefault using simplistic
implementation of new 2.0 method GetSystemWebProxy ().
Modified: trunk/mcs/class/System/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net/ChangeLog 2006-11-01 20:48:06 UTC (rev
67242)
+++ trunk/mcs/class/System/System.Net/ChangeLog 2006-11-01 20:50:41 UTC (rev
67243)
@@ -1,3 +1,11 @@
+2006-11-01 Michael Hutchinson <[EMAIL PROTECTED]>
+
+ * GlobalProxySelection.cs: Obsolete GlobalProxySelection under 2.0
+ profile, and move code to new property WebRequest.DefaultWebProxy.
+ * WebRequest.cs: Implement new 2.0 property DefaultWebProxy.
+ Add support for config option UseSystemDefault using simplistic
+ implementation of new 2.0 method GetSystemWebProxy ().
+
2006-10-30 Atsushi Enomoto <[EMAIL PROTECTED]>
* FtpWebRequest.cs : more build fixes.
Modified: trunk/mcs/class/System/System.Net/GlobalProxySelection.cs
===================================================================
--- trunk/mcs/class/System/System.Net/GlobalProxySelection.cs 2006-11-01
20:48:06 UTC (rev 67242)
+++ trunk/mcs/class/System/System.Net/GlobalProxySelection.cs 2006-11-01
20:50:41 UTC (rev 67243)
@@ -1,9 +1,9 @@
-//
-// System.Net.GlobalProxySelection
-//
-// Author:
-// Lawrence Pit ([EMAIL PROTECTED])
-//
+//
+// System.Net.GlobalProxySelection
+//
+// Author:
+// Lawrence Pit ([EMAIL PROTECTED])
+//
//
// Permission is hereby granted, free of charge, to any person obtaining
@@ -25,95 +25,93 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-
-using System;
-using System.Collections;
-using System.Configuration;
-using System.IO;
-using System.Runtime.Serialization;
-#if NET_2_0
-using System.Net.Configuration;
-#endif
-
-namespace System.Net
-{
- public class GlobalProxySelection
- {
+
+using System;
+using System.Collections;
+using System.Configuration;
+using System.IO;
+using System.Runtime.Serialization;
+#if NET_2_0
+using System.Net.Configuration;
+#endif
+
+namespace System.Net
+{
+#if NET_2_0
+ [ObsoleteAttribute("Use WebRequest.DefaultProxy instead")]
+#endif
+ public class GlobalProxySelection
+ {
+ // Constructors
+ public GlobalProxySelection() { }
+
+ // Properties
+
+#if !NET_2_0
volatile static IWebProxy proxy;
- static readonly object lockobj = new object ();
-
- // Constructors
- public GlobalProxySelection() { }
-
- // Properties
-
- static IWebProxy GetProxy ()
- {
- lock (lockobj) {
- if (proxy != null)
- return proxy;
-
- object p = ConfigurationSettings.GetConfig
("system.net/defaultProxy");
- if (p == null)
- p = new EmptyWebProxy ();
-#if NET_2_0 && CONFIGURATION_DEP
- DefaultProxySection s = p as
DefaultProxySection;
- if (s != null) {
- // FIXME: handle Module
- ProxyElement e = s.Proxy;
- // FIXME: handle AutoDetect,
ScriptLocation, UseSystemDefault
- if (e.BypassOnLocal ==
ProxyElement.BypassOnLocalValues.Unspecified)
- p = new WebProxy
(e.ProxyAddress);
- else
- p = new WebProxy
(e.ProxyAddress, e.BypassOnLocal == ProxyElement.BypassOnLocalValues.True);
- }
-#endif
- proxy = (IWebProxy) p;
- }
-
- return proxy;
- }
-
- public static IWebProxy Select {
- get { return GetProxy (); }
- set {
- if (value == null)
- throw new ArgumentNullException
("GlobalProxySelection.Select",
- "null IWebProxy not
allowed. Use GetEmptyWebProxy ()");
- proxy = value;
- }
- }
-
- // Methods
-
- public static IWebProxy GetEmptyWebProxy()
- {
- // must return a new one each time, as the credentials
- // can be set
- return new EmptyWebProxy ();
- }
-
- // Internal Classes
-
- internal class EmptyWebProxy : IWebProxy {
- private ICredentials credentials = null;
-
- internal EmptyWebProxy () { }
-
- public ICredentials Credentials {
- get { return credentials; }
- set { credentials = value; }
- }
-
- public Uri GetProxy (Uri destination)
- {
- return destination;
- }
-
- public bool IsBypassed (Uri host)
- {
- return true; // pass directly to host
- }
- }
- }
-}
+ static readonly object lockobj = new object ();
+
+ static IWebProxy GetProxy ()
+ {
+ lock (lockobj) {
+ if (proxy != null)
+ return proxy;
+
+ object p = ConfigurationSettings.GetConfig
("system.net/defaultProxy");
+ if (p == null)
+ p = new EmptyWebProxy ();
+ proxy = (IWebProxy) p;
+ }
+
+ return proxy;
+ }
+#endif
+
+ public static IWebProxy Select {
+#if NET_2_0
+ get { return WebRequest.DefaultWebProxy; }
+ set { WebRequest.DefaultWebProxy = value; }
+#else
+ get { return GetProxy (); }
+ set {
+ if (value == null)
+ throw new ArgumentNullException
("GlobalProxySelection.Select",
+ "null IWebProxy not
allowed. Use GetEmptyWebProxy ()");
+ proxy = value;
+ }
+#endif
+ }
+
+ // Methods
+
+ public static IWebProxy GetEmptyWebProxy()
+ {
+ // must return a new one each time, as the credentials
+ // can be set
+ return new EmptyWebProxy ();
+ }
+
+ // Internal Classes
+
+ internal class EmptyWebProxy : IWebProxy {
+ private ICredentials credentials = null;
+
+ internal EmptyWebProxy () { }
+
+ public ICredentials Credentials {
+ get { return credentials; }
+ set { credentials = value; }
+ }
+
+ public Uri GetProxy (Uri destination)
+ {
+ return destination;
+ }
+
+ public bool IsBypassed (Uri host)
+ {
+ return true; // pass directly to host
+ }
+ }
+ }
+}
Property changes on: trunk/mcs/class/System/System.Net/GlobalProxySelection.cs
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/mcs/class/System/System.Net/WebRequest.cs
===================================================================
--- trunk/mcs/class/System/System.Net/WebRequest.cs 2006-11-01 20:48:06 UTC
(rev 67242)
+++ trunk/mcs/class/System/System.Net/WebRequest.cs 2006-11-01 20:50:41 UTC
(rev 67243)
@@ -1,9 +1,9 @@
-//
-// System.Net.WebRequest
-//
-// Authors:
-// Lawrence Pit ([EMAIL PROTECTED])
-//
+//
+// System.Net.WebRequest
+//
+// Authors:
+// Lawrence Pit ([EMAIL PROTECTED])
+//
//
// Permission is hereby granted, free of charge, to any person obtaining
@@ -25,230 +25,293 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-
-using System;
-using System.Collections;
-using System.Collections.Specialized;
-using System.Configuration;
-using System.IO;
-using System.Runtime.Serialization;
-#if NET_2_0
-using System.Net.Configuration;
-#endif
-
-namespace System.Net
-{
- [Serializable]
- public abstract class WebRequest : MarshalByRefObject, ISerializable
- {
- static HybridDictionary prefixes = new HybridDictionary ();
-
- // Constructors
-
- static WebRequest ()
- {
-#if NET_2_0 && CONFIGURATION_DEP
- object cfg = ConfigurationManager.GetSection
("system.net/webRequestModules");
- WebRequestModulesSection s = cfg as
WebRequestModulesSection;
- if (s != null) {
- foreach (WebRequestModuleElement el in
- s.WebRequestModules)
- AddPrefix (el.Prefix, el.Type);
- return;
- }
-#endif
- ConfigurationSettings.GetConfig
("system.net/webRequestModules");
- }
-
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Configuration;
+using System.IO;
+using System.Runtime.Serialization;
+#if NET_2_0
+using System.Net.Configuration;
+#endif
+
+namespace System.Net
+{
+ [Serializable]
+ public abstract class WebRequest : MarshalByRefObject, ISerializable
+ {
+ static HybridDictionary prefixes = new HybridDictionary ();
+
+ // Constructors
+
+ static WebRequest ()
+ {
+#if NET_2_0 && CONFIGURATION_DEP
+ object cfg = ConfigurationManager.GetSection
("system.net/webRequestModules");
+ WebRequestModulesSection s = cfg as
WebRequestModulesSection;
+ if (s != null) {
+ foreach (WebRequestModuleElement el in
+ s.WebRequestModules)
+ AddPrefix (el.Prefix, el.Type);
+ return;
+ }
+#endif
+ ConfigurationSettings.GetConfig
("system.net/webRequestModules");
+ }
+
protected WebRequest ()
{
- }
-
- protected WebRequest (SerializationInfo serializationInfo,
StreamingContext streamingContext)
- {
- }
-
- // Properties
-
- public virtual string ConnectionGroupName {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- public virtual long ContentLength {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- public virtual string ContentType {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- public virtual ICredentials Credentials {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- public virtual WebHeaderCollection Headers {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- public virtual string Method {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- public virtual bool PreAuthenticate {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- public virtual IWebProxy Proxy {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- public virtual Uri RequestUri {
- get { throw new NotImplementedException (); }
- }
-
- public virtual int Timeout {
- get { throw new NotImplementedException (); }
- set { throw new NotImplementedException (); }
- }
-
- // Methods
-
- public virtual void Abort()
- {
- throw new NotImplementedException ();
- }
-
- public virtual IAsyncResult BeginGetRequestStream
(AsyncCallback callback, object state)
- {
- throw new NotImplementedException ();
- }
-
- public virtual IAsyncResult BeginGetResponse (AsyncCallback
callback, object state)
- {
- throw new NotImplementedException ();
- }
-
- public static WebRequest Create (string requestUriString)
- {
- if (requestUriString == null)
- throw new ArgumentNullException
("requestUriString");
- return Create (new Uri (requestUriString));
- }
-
- public static WebRequest Create (Uri requestUri)
- {
- if (requestUri == null)
- throw new ArgumentNullException ("requestUri");
- return GetCreator (requestUri.AbsoluteUri).Create
(requestUri);
- }
-
- public static WebRequest CreateDefault (Uri requestUri)
- {
- if (requestUri == null)
- throw new ArgumentNullException ("requestUri");
- return GetCreator (requestUri.Scheme).Create
(requestUri);
- }
-
- public virtual Stream EndGetRequestStream (IAsyncResult
asyncResult)
- {
- throw new NotImplementedException ();
- }
-
- public virtual WebResponse EndGetResponse (IAsyncResult
asyncResult)
- {
- throw new NotImplementedException ();
- }
-
- public virtual Stream GetRequestStream()
- {
- throw new NotImplementedException ();
- }
-
- public virtual WebResponse GetResponse()
- {
- throw new NotImplementedException ();
- }
-
- void ISerializable.GetObjectData (SerializationInfo
serializationInfo,
- StreamingContext
streamingContext)
- {
- throw new NotSupportedException ();
- }
-
- public static bool RegisterPrefix (string prefix,
IWebRequestCreate creator)
- {
- if (prefix == null)
- throw new ArgumentNullException("prefix");
- if (creator == null)
- throw new ArgumentNullException("creator");
-
- lock (prefixes.SyncRoot) {
- string lowerCasePrefix = prefix.ToLower ();
- if (prefixes.Contains (lowerCasePrefix))
- return false;
- prefixes.Add (lowerCasePrefix, creator);
- }
- return true;
- }
-
- private static IWebRequestCreate GetCreator (string prefix)
- {
- int longestPrefix = -1;
- IWebRequestCreate creator = null;
-
- prefix = prefix.ToLower ();
-
- IDictionaryEnumerator e = prefixes.GetEnumerator ();
- while (e.MoveNext ()) {
- string key = e.Key as string;
-
- if (key.Length <= longestPrefix)
- continue;
-
- if (!prefix.StartsWith (key))
- continue;
-
- longestPrefix = key.Length;
- creator = (IWebRequestCreate) e.Value;
- }
-
- if (creator == null)
- throw new NotSupportedException (prefix);
-
- return creator;
- }
-
- internal static void ClearPrefixes ()
- {
- prefixes.Clear ();
- }
-
- internal static void RemovePrefix (string prefix)
- {
- prefixes.Remove (prefix);
- }
-
- internal static void AddPrefix (string prefix, string typeName)
- {
- Type type = Type.GetType (typeName);
- if (type == null)
- throw new ConfigurationException (String.Format
("Type {0} not found", typeName));
- AddPrefix (prefix, type);
- }
-
- internal static void AddPrefix (string prefix, Type type)
- {
- object o = Activator.CreateInstance (type, true);
- prefixes [prefix] = o;
- }
- }
-}
-
+ }
+
+ protected WebRequest (SerializationInfo serializationInfo,
StreamingContext streamingContext)
+ {
+ }
+
+ // Properties
+
+ public virtual string ConnectionGroupName {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+ public virtual long ContentLength {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+ public virtual string ContentType {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+ public virtual ICredentials Credentials {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+ public virtual WebHeaderCollection Headers {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+ public virtual string Method {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+ public virtual bool PreAuthenticate {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+ public virtual IWebProxy Proxy {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+ public virtual Uri RequestUri {
+ get { throw new NotImplementedException (); }
+ }
+
+ public virtual int Timeout {
+ get { throw new NotImplementedException (); }
+ set { throw new NotImplementedException (); }
+ }
+
+#if NET_2_0
+ volatile static IWebProxy proxy;
+ static readonly object lockobj = new object ();
+
+ public static IWebProxy DefaultWebProxy {
+ get {
+ lock (lockobj) {
+ if (proxy == null)
+ proxy = GetDefaultWebProxy ();
+ return proxy;
+ }
+ }
+ set {
+ if (value == null)
+ throw new ArgumentNullException
("WebRequest.DefaultWebProxy",
+ "null IWebProxy not
allowed.");
+ proxy = value;
+ }
+ }
+
+ [MonoTODO("Needs to respect Module, Proxy.AutoDetect, and
Proxy.ScriptLocation config settings")]
+ static IWebProxy GetDefaultWebProxy ()
+ {
+ WebProxy p;
+
+#if CONFIGURATION_DEP
+ System.Configuration.Configuration config =
ConfigurationManager.OpenMachineConfiguration ();
+ DefaultProxySection sec = config.GetSection
("system.net/defaultProxy") as DefaultProxySection;
+ if (sec == null)
+ return GlobalProxySelection.GetEmptyWebProxy ();
+
+ ProxyElement pe = sec.Proxy;
+
+ if ((pe.UseSystemDefault ==
ProxyElement.UseSystemDefaultValues.True) && (pe.ProxyAddress == null))
+ p = (WebProxy) GetSystemWebProxy ();
+ else
+ p = new WebProxy ();
+
+ if (pe.ProxyAddress != null)
+ p.Address = pe.ProxyAddress;
+
+ if (pe.BypassOnLocal !=
ProxyElement.BypassOnLocalValues.Unspecified)
+ p.BypassProxyOnLocal = (pe.BypassOnLocal ==
ProxyElement.BypassOnLocalValues.True);
+#endif
+ return p;
+ }
+#endif
+
+ // Methods
+
+ public virtual void Abort()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public virtual IAsyncResult BeginGetRequestStream
(AsyncCallback callback, object state)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public virtual IAsyncResult BeginGetResponse (AsyncCallback
callback, object state)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public static WebRequest Create (string requestUriString)
+ {
+ if (requestUriString == null)
+ throw new ArgumentNullException
("requestUriString");
+ return Create (new Uri (requestUriString));
+ }
+
+ public static WebRequest Create (Uri requestUri)
+ {
+ if (requestUri == null)
+ throw new ArgumentNullException ("requestUri");
+ return GetCreator (requestUri.AbsoluteUri).Create
(requestUri);
+ }
+
+ public static WebRequest CreateDefault (Uri requestUri)
+ {
+ if (requestUri == null)
+ throw new ArgumentNullException ("requestUri");
+ return GetCreator (requestUri.Scheme).Create
(requestUri);
+ }
+
+ public virtual Stream EndGetRequestStream (IAsyncResult
asyncResult)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public virtual WebResponse EndGetResponse (IAsyncResult
asyncResult)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public virtual Stream GetRequestStream()
+ {
+ throw new NotImplementedException ();
+ }
+
+ public virtual WebResponse GetResponse()
+ {
+ throw new NotImplementedException ();
+ }
+
+#if NET_2_0
+ [MonoTODO("Look in other places for proxy config info")]
+ public static IWebProxy GetSystemWebProxy ()
+ {
+ string address = Environment.GetEnvironmentVariable
("http_proxy");
+ if (address != null) {
+ try {
+ WebProxy p = new WebProxy (address);
+ return p;
+ } catch (UriFormatException) {}
+ }
+ return new WebProxy ();
+ }
+#endif
+
+ void ISerializable.GetObjectData (SerializationInfo
serializationInfo,
+ StreamingContext
streamingContext)
+ {
+ throw new NotSupportedException ();
+ }
+
+ public static bool RegisterPrefix (string prefix,
IWebRequestCreate creator)
+ {
+ if (prefix == null)
+ throw new ArgumentNullException("prefix");
+ if (creator == null)
+ throw new ArgumentNullException("creator");
+
+ lock (prefixes.SyncRoot) {
+ string lowerCasePrefix = prefix.ToLower ();
+ if (prefixes.Contains (lowerCasePrefix))
+ return false;
+ prefixes.Add (lowerCasePrefix, creator);
+ }
+ return true;
+ }
+
+ private static IWebRequestCreate GetCreator (string prefix)
+ {
+ int longestPrefix = -1;
+ IWebRequestCreate creator = null;
+
+ prefix = prefix.ToLower ();
+
+ IDictionaryEnumerator e = prefixes.GetEnumerator ();
+ while (e.MoveNext ()) {
+ string key = e.Key as string;
+
+ if (key.Length <= longestPrefix)
+ continue;
+
+ if (!prefix.StartsWith (key))
+ continue;
+
+ longestPrefix = key.Length;
+ creator = (IWebRequestCreate) e.Value;
+ }
+
+ if (creator == null)
+ throw new NotSupportedException (prefix);
+
+ return creator;
+ }
+
+ internal static void ClearPrefixes ()
+ {
+ prefixes.Clear ();
+ }
+
+ internal static void RemovePrefix (string prefix)
+ {
+ prefixes.Remove (prefix);
+ }
+
+ internal static void AddPrefix (string prefix, string typeName)
+ {
+ Type type = Type.GetType (typeName);
+ if (type == null)
+ throw new ConfigurationException (String.Format
("Type {0} not found", typeName));
+ AddPrefix (prefix, type);
+ }
+
+ internal static void AddPrefix (string prefix, Type type)
+ {
+ object o = Activator.CreateInstance (type, true);
+ prefixes [prefix] = o;
+ }
+ }
+}
+
Property changes on: trunk/mcs/class/System/System.Net/WebRequest.cs
___________________________________________________________________
Name: svn:eol-style
+ native
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches