Merge pull request #2799 from BrzVlad/fix-conc-card-clean
[mono.git] / mcs / class / System / System.Net / HttpListenerRequest.cs
index e1c032c6da0c44650c08dbf9b93849a61a3b3a70..f1c47802cb94bef9e16534919ff1d10aba148b8c 100644 (file)
 
 #if SECURITY_DEP
 
-#if MONOTOUCH || MONODROID
-using Mono.Security.Protocol.Tls;
-#else
-extern alias MonoSecurity;
-using MonoSecurity::Mono.Security.Protocol.Tls;
-#endif
-
 using System.Collections;
 using System.Collections.Specialized;
 using System.Globalization;
@@ -45,6 +38,7 @@ using System.Security.Cryptography.X509Certificates;
 using System.Text;
 using System.Security.Authentication.ExtendedProtection;
 using System.Threading.Tasks;
+using System.Net;
 
 namespace System.Net {
        public sealed class HttpListenerRequest
@@ -142,10 +136,10 @@ namespace System.Net {
                        foreach (string kv in components) {
                                int pos = kv.IndexOf ('=');
                                if (pos == -1) {
-                                       query_string.Add (null, HttpUtility.UrlDecode (kv));
+                                       query_string.Add (null, WebUtility.UrlDecode (kv));
                                } else {
-                                       string key = HttpUtility.UrlDecode (kv.Substring (0, pos));
-                                       string val = HttpUtility.UrlDecode (kv.Substring (pos + 1));
+                                       string key = WebUtility.UrlDecode (kv.Substring (0, pos));
+                                       string val = WebUtility.UrlDecode (kv.Substring (pos + 1));
                                        
                                        query_string.Add (key, val);
                                }
@@ -162,7 +156,7 @@ namespace System.Net {
 
                        string path;
                        Uri raw_uri = null;
-                       if (Uri.MaybeUri (raw_url) && Uri.TryCreate (raw_url, UriKind.Absolute, out raw_uri))
+                       if (Uri.MaybeUri (raw_url.ToLowerInvariant ()) && Uri.TryCreate (raw_url, UriKind.Absolute, out raw_uri))
                                path = raw_uri.PathAndQuery;
                        else
                                path = raw_url;
@@ -182,12 +176,17 @@ namespace System.Net {
                                                                host, LocalEndPoint.Port);
 
                        if (!Uri.TryCreate (base_uri + path, UriKind.Absolute, out url)){
-                               context.ErrorMessage = "Invalid url: " + base_uri + path;
+                               context.ErrorMessage = WebUtility.HtmlEncode ("Invalid url: " + base_uri + path);
                                return;
                        }
 
                        CreateQueryString (url.Query);
 
+                       // Use reference source HttpListenerRequestUriBuilder to process url.
+                       // Fixes #29927
+                       url = HttpListenerRequestUriBuilder.GetRequestUri (raw_url, url.Scheme,
+                                                               url.Authority, url.LocalPath, url.Query);
+
                        if (version >= HttpVersion.Version11) {
                                string t_encoding = Headers ["Transfer-Encoding"];
                                is_chunked = (t_encoding != null && String.Compare (t_encoding, "chunked", StringComparison.OrdinalIgnoreCase) == 0);
@@ -404,7 +403,7 @@ namespace System.Net {
                }
 
                public bool IsLocal {
-                       get { return IPAddress.IsLoopback (RemoteEndPoint.Address); }
+                       get { return LocalEndPoint.Address.Equals (RemoteEndPoint.Address); }
                }
 
                public bool IsSecureConnection {