2009-02-23 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / class / System / System.Net / HttpListenerRequest.cs
index 3d598b5e11132c5421ba46cbec883f30c2076e8b..18586fb2df2a33cae7c98bee51a39d0d06cbf1d0 100644 (file)
@@ -65,6 +65,7 @@ namespace System.Net {
                        this.context = context;
                        headers = new WebHeaderCollection ();
                        input_stream = Stream.Null;
+                       version = HttpVersion.Version10;
                }
 
                static char [] separators = new char [] { ' ' };
@@ -138,9 +139,19 @@ namespace System.Net {
                                return;
                        }
 
-                       if (host == null || host.Length == 0)
+                       string path;
+                       Uri raw_uri;
+                       if (Uri.MaybeUri (raw_url) && Uri.TryCreate (raw_url, UriKind.Absolute, out raw_uri))
+                               path = raw_uri.PathAndQuery;
+                       else
+                               path = raw_url;
+
+                       if ((host == null || host.Length == 0))
                                host = UserHostAddress;
 
+                       if (raw_uri != null)
+                               host = raw_uri.Host;
+       
                        int colon = host.IndexOf (':');
                        if (colon >= 0)
                                host = host.Substring (0, colon);
@@ -149,10 +160,9 @@ namespace System.Net {
                                                                (IsSecureConnection) ? "https" : "http",
                                                                host,
                                                                LocalEndPoint.Port);
-                       try {
-                               url = new Uri (base_uri + raw_url);
-                       } catch {
-                               context.ErrorMessage = "Invalid url";
+
+                       if (!Uri.TryCreate (base_uri + path, UriKind.Absolute, out url)){
+                               context.ErrorMessage = "Invalid url: " + base_uri + path;
                                return;
                        }