[Mono-dev] [PATCH] Read System.Net proxy server address from environment

2005-10-30 Thread Michael Hutchinson
This minor patch enables the use of the "usesystemdefault" parameter
of the defaultProxy in application/machine config files, to read the
default System.Net proxy server address from environment. This means
that applications that use HttpWebRequests etc will use a defined
proxy server even if the developer has not explicitly added support.

The proxy address will be from the "http_proxy" environment variable
commonly used for this purpose. In .NET, the Internet Explorer
settings are used. Although more information about an HTTP proxy could
potentially be obtained from GConf or Mozilla or other sources, this
way is simple, reliable and introduces no dependencies. However, the
environment variable will not usually be set on Win32.

The second patch fixes the machine.config settings to their defaults.

I have tested this patch with MonoDevelop's new repository feature.
However, there is a fixme; I'm not quite sure of the precendence of
some of the settings, as I could not find adequate documentation.

Please review/approve, and I will commit.


Michael
Index: System.Net.Configuration/DefaultProxyHandler.cs
===
--- System.Net.Configuration/DefaultProxyHandler.cs	(revision 52400)
+++ System.Net.Configuration/DefaultProxyHandler.cs	(working copy)
@@ -57,8 +57,7 @@
 
 string name = child.Name;
 if (name == "proxy") {
-	// ignored
-	HandlersUtil.ExtractAttributeValue ("usesystemdefault", child, true);
+	string sysdefault = HandlersUtil.ExtractAttributeValue ("usesystemdefault", child, true);
 	string bypass = HandlersUtil.ExtractAttributeValue ("bypassonlocal", child, true);
 	string address = HandlersUtil.ExtractAttributeValue ("proxyaddress", child, true);
 	if (child.Attributes != null && child.Attributes.Count != 0) {
@@ -71,9 +70,13 @@
 		if (bypass != null && String.Compare (bypass, "false", true) != 0)
 			HandlersUtil.ThrowException ("Invalid boolean value", child);
 	}
-
+	
 	if (!(result is WebProxy))
 		continue;
+	
+	//FIXME: does usesystemdefault or presence of address take precedence?
+	if (sysdefault != null && String.Compare (sysdefault, "true", true) == 0)
+		address = Environment.GetEnvironmentVariable ("http_proxy");
 
 	((WebProxy) result).BypassProxyOnLocal = bp;
 	if (address == null)
@@ -81,7 +84,7 @@
 
 	try {
 		((WebProxy) result).Address = new Uri (address);
-	} catch (Exception) {
+	} catch (UriFormatException) {
 		HandlersUtil.ThrowException ("invalid uri", child);
 	}
 	continue;


Index: data/net_1_1/machine.config
===
--- data/net_1_1/machine.config	(revision 52400)
+++ data/net_1_1/machine.config	(working copy)
@@ -62,9 +62,11 @@
 			
 		
 		
-			
-			
-			
+			
+			
 		
 		
 			
Index: data/net_2_0/machine.config
===
--- data/net_2_0/machine.config	(revision 52400)
+++ data/net_2_0/machine.config	(working copy)
@@ -63,9 +63,11 @@
 			
 		
 		
-			
-			
-			
+			
+			
 		
 		
 			


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Read System.Net proxy server address from environment

2005-10-31 Thread Gonzalo Paniagua Javier
+   
+   //FIXME: does usesystemdefault
or presence of address take precedence?

Why not testing this now that you're on the case and make it work like
it does in MS?
 
try {
((WebProxy)
result).Address = new Uri (address);
-   } catch (Exception) {
+   } catch (UriFormatException) {

Do not change this. There might be other exceptions thrown.

-Gonzalo


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Read System.Net proxy server address from environment

2005-11-09 Thread Michael Hutchinson
> +   //FIXME: does usesystemdefault
> or presence of address take precedence?
>
> Why not testing this now that you're on the case and make it work like
> it does in MS?

I've got onto Windows and done some testing on .NET 1.1, and it
appears the values are treated as follows:

1. First the value of "proxyaddress" is used. If it is not empty and
parses correctly as a URI, this address is used.
2. If the address was not already assigned and "usesystemdefault" is
true (blank == false), then address is loaded from the environment.
3. If this is empty, or parsing it fails, the address is left blank.

> -   } catch (Exception) {
> +   } catch (UriFormatException) {
>
> Do not change this. There might be other exceptions thrown.

Note the silent fallthrough on bad URI formats on .NET. I therefore
think that that catching Exception is overzealous, as if it does occur
that will be due to a bug.

Is it okay to commit now? I don't have a direct internet connection
here, so if someone could double-check that it definately works
without a proxy that would be nice.

Michael
Index: data/net_1_1/machine.config
===
--- data/net_1_1/machine.config	(revision 52780)
+++ data/net_1_1/machine.config	(working copy)
@@ -62,9 +62,11 @@
 			
 		
 		
-			
-			
-			
+			
+			
 		
 		
 			
Index: data/net_2_0/machine.config
===
--- data/net_2_0/machine.config	(revision 52780)
+++ data/net_2_0/machine.config	(working copy)
@@ -63,9 +63,11 @@
 			
 		
 		
-			
-			
-			
+			
+			
 		
 		
 			
Index: ChangeLog
===
--- ChangeLog	(revision 52780)
+++ ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2005-11-09 Michael Hutchinson <[EMAIL PROTECTED]>
+
+	* data/net_1_1/machine.config, data/net_2_0/machine.config: Set 
+	default values for http proxy
+
 2005-11-07  Zoltan Varga  <[EMAIL PROTECTED]>
 
 	* docs/jit-regalloc: Merge forgotten documentation updates from

Index: System.Net.Configuration/ChangeLog
===
--- System.Net.Configuration/ChangeLog	(revision 52805)
+++ System.Net.Configuration/ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+2005-11-09 Michael Hutchinson <[EMAIL PROTECTED]>
+
+	* DefaultProxyHandler.cs: Read proxy address from environment, fall back on unvalid URIs
+
 2005-10-18 Gert Driesen <[EMAIL PROTECTED]>
 
 	* HttpWebRequestElement.cs: Added missing properties and 
Index: System.Net.Configuration/DefaultProxyHandler.cs
===
--- System.Net.Configuration/DefaultProxyHandler.cs	(revision 52805)
+++ System.Net.Configuration/DefaultProxyHandler.cs	(working copy)
@@ -57,8 +57,7 @@
 
 string name = child.Name;
 if (name == "proxy") {
-	// ignored
-	HandlersUtil.ExtractAttributeValue ("usesystemdefault", child, true);
+	string sysdefault = HandlersUtil.ExtractAttributeValue ("usesystemdefault", child, true);
 	string bypass = HandlersUtil.ExtractAttributeValue ("bypassonlocal", child, true);
 	string address = HandlersUtil.ExtractAttributeValue ("proxyaddress", child, true);
 	if (child.Attributes != null && child.Attributes.Count != 0) {
@@ -76,14 +75,22 @@
 		continue;
 
 	((WebProxy) result).BypassProxyOnLocal = bp;
-	if (address == null)
-		continue;
-
-	try {
-		((WebProxy) result).Address = new Uri (address);
-	} catch (Exception) {
-		HandlersUtil.ThrowException ("invalid uri", child);
+	
+	if (address != null)
+		try {
+			((WebProxy) result).Address = new Uri (address);
+			continue;
+		} catch (UriFormatException) {} //MS: ignore bad URIs, fall through to default
+	
+	//MS: presence of valid address URI takes precedence over usesystemdefault
+	if (sysdefault != null && String.Compare (sysdefault, "true", true) == 0) {
+		address = Environment.GetEnvironmentVariable ("http_proxy");
+		if (address != null)
+			try {
+((WebProxy) result).Address = new Uri (address);
+			} catch (UriFormatException) {}
 	}
+	
 	continue;
 }
 

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Read System.Net proxy server address from environment

2005-11-18 Thread Michael Hutchinson
> Is it okay to commit now? I don't have a direct internet connection
> here, so if someone could double-check that it definately works
> without a proxy that would be nice.

Looks like this slipped through the net. Can someone review it?

Thanks


Michael
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] [PATCH] Read System.Net proxy server address from environment

2005-11-18 Thread Gonzalo Paniagua Javier
On Fri, 2005-11-18 at 09:45 +, Michael Hutchinson wrote:
> > Is it okay to commit now? I don't have a direct internet connection
> > here, so if someone could double-check that it definately works
> > without a proxy that would be nice.
> 
> Looks like this slipped through the net. Can someone review it?

The patch is in svn now.
It would be nice to get a patch for the documentation in monodoc as
well ;-).

Thanks a lot and sorry for the delay reviewing it.

-Gonzalo

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list