2 // System.Net.GlobalProxySelection
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
\r
31 using System.Configuration;
\r
33 using System.Runtime.Serialization;
\r
35 using System.Net.Configuration;
\r
38 namespace System.Net
\r
40 public class GlobalProxySelection
\r
42 volatile static IWebProxy proxy;
43 static readonly object lockobj = new object ();
\r
46 public GlobalProxySelection() { }
\r
50 static IWebProxy GetProxy ()
\r
56 object p = ConfigurationSettings.GetConfig ("system.net/defaultProxy");
\r
58 p = new EmptyWebProxy ();
\r
59 #if NET_2_0 && CONFIGURATION_DEP
\r
60 DefaultProxySection s = p as DefaultProxySection;
\r
62 // FIXME: handle Module
\r
63 ProxyElement e = s.Proxy;
\r
64 // FIXME: handle AutoDetect, ScriptLocation, UseSystemDefault
\r
65 if (e.BypassOnLocal == ProxyElement.BypassOnLocalValues.Unspecified)
\r
66 p = new WebProxy (e.ProxyAddress);
\r
68 p = new WebProxy (e.ProxyAddress, e.BypassOnLocal == ProxyElement.BypassOnLocalValues.True);
\r
71 proxy = (IWebProxy) p;
\r
77 public static IWebProxy Select {
\r
78 get { return GetProxy (); }
\r
81 throw new ArgumentNullException ("GlobalProxySelection.Select",
\r
82 "null IWebProxy not allowed. Use GetEmptyWebProxy ()");
\r
89 public static IWebProxy GetEmptyWebProxy()
\r
91 // must return a new one each time, as the credentials
\r
93 return new EmptyWebProxy ();
\r
98 internal class EmptyWebProxy : IWebProxy {
\r
99 private ICredentials credentials = null;
\r
101 internal EmptyWebProxy () { }
\r
103 public ICredentials Credentials {
\r
104 get { return credentials; }
\r
105 set { credentials = value; }
\r
108 public Uri GetProxy (Uri destination)
\r
110 return destination;
\r
113 public bool IsBypassed (Uri host)
\r
115 return true; // pass directly to host
\r