From ca0ecfd1a2ec914f7115c83f0fb33b77d9b7e636 Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Fri, 6 Jun 2003 16:15:21 +0000 Subject: [PATCH] 2003-06-06 Gonzalo Paniagua Javier * list.unix: added files. * System.Net/FileWebRequestCreator.cs: splitted from WebRequest. * System.Net/HttpRequestCreator.cs: splitted fromWebRequest. * System.Net/WebRequest.cs: added methods that are used by the new configuration handler to set prefix/type name requests creators. * System.Net.Configuration/WebRequestModuleHandler.cs: handles system.net/webRequestModules configuration section. svn path=/trunk/mcs/; revision=15160 --- .../System/System.Net.Configuration/ChangeLog | 5 ++ .../WebRequestModuleHandler.cs | 66 +++++++++++++++++++ mcs/class/System/System.Net/ChangeLog | 7 ++ .../System.Net/FileWebRequestCreator.cs | 20 ++++++ .../System/System.Net/HttpRequestCreator.cs | 20 ++++++ mcs/class/System/System.Net/WebRequest.cs | 57 ++++++++-------- mcs/class/System/list.unix | 3 + 7 files changed, 149 insertions(+), 29 deletions(-) create mode 100644 mcs/class/System/System.Net.Configuration/WebRequestModuleHandler.cs create mode 100644 mcs/class/System/System.Net/FileWebRequestCreator.cs create mode 100644 mcs/class/System/System.Net/HttpRequestCreator.cs diff --git a/mcs/class/System/System.Net.Configuration/ChangeLog b/mcs/class/System/System.Net.Configuration/ChangeLog index 9a5291d8884..e3452fa5273 100644 --- a/mcs/class/System/System.Net.Configuration/ChangeLog +++ b/mcs/class/System/System.Net.Configuration/ChangeLog @@ -1,3 +1,8 @@ +2003-06-06 Gonzalo Paniagua Javier + + * WebRequestModuleHandler.cs: handles system.net/webRequestModules + configuration section. + 2003-06-06 Gonzalo Paniagua Javier * DefaultProxyHandler.cs: new file. diff --git a/mcs/class/System/System.Net.Configuration/WebRequestModuleHandler.cs b/mcs/class/System/System.Net.Configuration/WebRequestModuleHandler.cs new file mode 100644 index 00000000000..fb4e86efd1d --- /dev/null +++ b/mcs/class/System/System.Net.Configuration/WebRequestModuleHandler.cs @@ -0,0 +1,66 @@ +// +// System.Net.Configuration.WebRequestModuleHandler +// +// Authors: +// Gonzalo Paniagua Javier (gonzalo@ximian.com) +// +// (C) 2003 Ximian, Inc (http://www.ximian.com) +// + +using System.Collections; +using System.Configuration; +using System.Xml; + +namespace System.Net.Configuration +{ + class WebRequestModuleHandler : IConfigurationSectionHandler + { + public virtual object Create (object parent, object configContext, XmlNode section) + { + if (section.Attributes != null && section.Attributes.Count != 0) + HandlersUtil.ThrowException ("Unrecognized attribute", section); + + XmlNodeList reqHandlers = section.ChildNodes; + foreach (XmlNode child in reqHandlers) { + XmlNodeType ntype = child.NodeType; + if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) + continue; + + if (ntype != XmlNodeType.Element) + HandlersUtil.ThrowException ("Only elements allowed", child); + + string name = child.Name; + if (name == "clear") { + if (child.Attributes != null && child.Attributes.Count != 0) + HandlersUtil.ThrowException ("Unrecognized attribute", child); + + WebRequest.ClearPrefixes (); + continue; + } + + string prefix = HandlersUtil.ExtractAttributeValue ("prefix", child); + if (name == "add") { + string type = HandlersUtil.ExtractAttributeValue ("type", child, false); + if (child.Attributes != null && child.Attributes.Count != 0) + HandlersUtil.ThrowException ("Unrecognized attribute", child); + + WebRequest.AddPrefix (prefix, type); + continue; + } + + if (name == "remove") { + if (child.Attributes != null && child.Attributes.Count != 0) + HandlersUtil.ThrowException ("Unrecognized attribute", child); + + WebRequest.RemovePrefix (prefix); + continue; + } + + HandlersUtil.ThrowException ("Unexpected element", child); + } + + return null; + } + } +} + diff --git a/mcs/class/System/System.Net/ChangeLog b/mcs/class/System/System.Net/ChangeLog index 774c36bb92d..9f8125cf7e2 100644 --- a/mcs/class/System/System.Net/ChangeLog +++ b/mcs/class/System/System.Net/ChangeLog @@ -1,3 +1,10 @@ +2003-06-06 Gonzalo Paniagua Javier + + * FileWebRequestCreator.cs: splitted from WebRequest. + * HttpRequestCreator.cs: splitted fromWebRequest. + * WebRequest.cs: added methods that are used by the new configuration + handler to set prefix/type name requests creators. + 2003-06-06 Gonzalo Paniagua Javier * AuthenticationManager.cs: diff --git a/mcs/class/System/System.Net/FileWebRequestCreator.cs b/mcs/class/System/System.Net/FileWebRequestCreator.cs new file mode 100644 index 00000000000..c20ab9ca5bb --- /dev/null +++ b/mcs/class/System/System.Net/FileWebRequestCreator.cs @@ -0,0 +1,20 @@ +// +// System.Net.FileWebRequestCreator +// +// Authors: +// Gonzalo Paniagua Javier (gonzalo@ximian.com) +// +// (C) 2003 Ximian, Inc (http://www.ximian.com) +// + +namespace System.Net +{ + class FileWebRequestCreator : IWebRequestCreate + { + public WebRequest Create (Uri uri) + { + return new FileWebRequest (uri); + } + } +} + diff --git a/mcs/class/System/System.Net/HttpRequestCreator.cs b/mcs/class/System/System.Net/HttpRequestCreator.cs new file mode 100644 index 00000000000..7bdacc2257f --- /dev/null +++ b/mcs/class/System/System.Net/HttpRequestCreator.cs @@ -0,0 +1,20 @@ +// +// System.Net.HttpWebRequestCreator +// +// Authors: +// Gonzalo Paniagua Javier (gonzalo@ximian.com) +// +// (C) 2003 Ximian, Inc (http://www.ximian.com) +// + +namespace System.Net +{ + class HttpRequestCreator : IWebRequestCreate + { + public WebRequest Create (Uri uri) + { + return new HttpWebRequest (uri); + } + } +} + diff --git a/mcs/class/System/System.Net/WebRequest.cs b/mcs/class/System/System.Net/WebRequest.cs index 0be53a781ef..22689725dbb 100644 --- a/mcs/class/System/System.Net/WebRequest.cs +++ b/mcs/class/System/System.Net/WebRequest.cs @@ -1,13 +1,14 @@ // // System.Net.WebRequest // -// Author: +// Authors: // Lawrence Pit (loz@cable.a2000.nl) // using System; using System.Collections; using System.Collections.Specialized; +using System.Configuration; using System.IO; using System.Runtime.Serialization; @@ -16,37 +17,14 @@ namespace System.Net [Serializable] public abstract class WebRequest : MarshalByRefObject, ISerializable { - private static HybridDictionary prefixes; + static HybridDictionary prefixes = new HybridDictionary (); - static WebRequest () { - prefixes = new HybridDictionary (3, true); - RegisterPrefix ("file", new FileWebRequestCreator ()); - RegisterPrefix ("http", new HttpWebRequestCreator ()); - RegisterPrefix ("https", new HttpWebRequestCreator ()); - } + // Constructors - internal class HttpWebRequestCreator : IWebRequestCreate - { - internal HttpWebRequestCreator () { } - - public WebRequest Create (Uri uri) - { - return new HttpWebRequest (uri); - } - } - - internal class FileWebRequestCreator : IWebRequestCreate + static WebRequest () { - internal FileWebRequestCreator () { } - - public WebRequest Create (Uri uri) - { - return new FileWebRequest (uri); - } + ConfigurationSettings.GetConfig ("system.net/webRequestModules"); } - - - // Constructors protected WebRequest () { } @@ -212,5 +190,26 @@ namespace System.Net 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)); + + object o = Activator.CreateInstance (type); + prefixes [prefix] = o; + } } -} \ No newline at end of file +} + diff --git a/mcs/class/System/list.unix b/mcs/class/System/list.unix index a3dfd60add7..34c8dbd926f 100755 --- a/mcs/class/System/list.unix +++ b/mcs/class/System/list.unix @@ -393,6 +393,7 @@ System.Net/ConnectionModes.cs System.Net.Configuration/ConnectionManagementHandler.cs System.Net.Configuration/DefaultProxyHandler.cs System.Net.Configuration/NetAuthenticationModuleHandler.cs +System.Net.Configuration/WebRequestModuleHandler.cs System.Net/CookieCollection.cs System.Net/CookieContainer.cs System.Net/Cookie.cs @@ -404,9 +405,11 @@ System.Net/DnsPermission.cs System.Net/EndPoint.cs System.Net/EndpointPermission.cs System.Net/FileWebRequest.cs +System.Net/FileWebRequestCreator.cs System.Net/FileWebResponse.cs System.Net/GlobalProxySelection.cs System.Net/HttpContinueDelegate.cs +System.Net/HttpRequestCreator.cs System.Net/HttpStatusCode.cs System.Net/HttpVersion.cs System.Net/HttpWebRequest.cs -- 2.25.1