+2008-09-08 Miguel de Icaza <miguel@novell.com>
+
+ * EndPointListener.cs (SearchListener): Cope with the raw_url not
+ being merely a path, but potentially a full URI (see the proxy
+ case).
+
+ * HttpListenerRequest.cs: Cope with raw_url not being merely a
+ path, but potentially a full Uri. Also uses TryCreate, hoping
+ that one day it will be faster.
+
2008-08-23 Zoltan Varga <vargaz@gmail.com>
* WebConnectionStream.cs (WriteRequest): Fix the copying in the
host = host.Substring (0, colon);
}
- string path = HttpUtility.UrlDecode (raw_url);
+ 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 = HttpUtility.UrlDecode (raw_url);
+
string path_slash = path [path.Length - 1] == '/' ? path : path + "/";
HttpListener best_match = null;
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);
(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;
}
+2008-09-08 Miguel de Icaza <miguel@novell.com>
+
+ * Uri.cs (MaybeUri): A helper routine for methods in other classes
+ to quickly determine if something might be a Uri, before calling
+ the more expensive Uri.TryCreate (see bug 424192).
+
2008-08-08 Sebastien Pouliot <sebastien@ximian.com>
* UriTypeConverter.cs: Fix cp typo found when cp (of course ;-)
return false;
}
+ internal static bool MaybeUri (string s)
+ {
+ int p = s.IndexOf (':');
+ if (p == -1)
+ return false;
+
+ if (p >= 10)
+ return false;
+
+ return IsPredefinedScheme (s.Substring (0, p));
+ }
+
private static bool IsPredefinedScheme (string scheme)
{
switch (scheme) {
Console.WriteLine ("Done");
listener.Close ();
}
-
+
+ //
+ // Test case for bug 341443, an pretty old bug, filed on November of 2007.
+ //
+ [Test]
+ public void Test_HostInUri ()
+ {
+ var wait = new ManualResetEvent (false);
+ var wait2 = new ManualResetEvent (false);
+
+ Thread t = new Thread (delegate (object a) {
+ wait.WaitOne ();
+
+ NetworkStream ns = HttpListener2Test.CreateNS (9145);
+ HttpListener2Test.Send (ns, "GET http://www.google.com/ HTTP/1.1\r\nHost: www.google.com\r\nContent-Length: 3\r\n\r\n123456");
+
+ wait2.WaitOne ();
+ ns.Close ();
+ });
+ t.Start ();
+
+ HttpListener listener = HttpListener2Test.CreateAndStartListener ("http://*:9145/");
+ wait.Set ();
+ HttpListenerContext ctx = listener.GetContext ();
+
+ Assert.AreEqual ("http://www.google.com:9145/", ctx.Request.Url.ToString ());
+ Assert.AreEqual ("http://www.google.com/", ctx.Request.RawUrl);
+ wait2.Set ();
+
+ listener.Close ();
+ }
+
}
}
#endif