Merge pull request #981 from methane/websocket
[mono.git] / mcs / class / System / System.Net / HttpListenerRequest.cs
index f8be5c4f3b9e2e8b8d0eb065fe27b2be74937f33..37be80f1b94cc425d25146785eb129a14f144912 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;
@@ -42,7 +49,6 @@ using System.Security.Authentication.ExtendedProtection;
 #if NET_4_5
 using System.Threading.Tasks;
 #endif
-using Mono.Security.Protocol.Tls;
 
 namespace System.Net {
        public sealed class HttpListenerRequest
@@ -165,7 +171,7 @@ namespace System.Net {
                        if (Uri.MaybeUri (raw_url) && Uri.TryCreate (raw_url, UriKind.Absolute, out raw_uri))
                                path = raw_uri.PathAndQuery;
                        else
-                               path = HttpUtility.UrlDecode (raw_url);
+                               path = raw_url;
 
                        if ((host == null || host.Length == 0))
                                host = UserHostAddress;
@@ -319,7 +325,7 @@ namespace System.Net {
                                // TODO: test if MS has a timeout when doing this
                                try {
                                        IAsyncResult ares = InputStream.BeginRead (bytes, 0, length, null, null);
-                                       if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne (100))
+                                       if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne (1000))
                                                return false;
                                        if (InputStream.EndRead (ares) <= 0)
                                                return true;
@@ -519,10 +525,17 @@ namespace System.Net {
 #endif
                
 #if NET_4_5
-               [MonoTODO]
                public bool IsWebSocketRequest {
                        get {
-                               return false;
+                               string connection = headers.Get ("Connection");
+                               if (connection == null || ! connection.Equals ("upgrade", StringComparison.OrdinalIgnoreCase)) {
+                                       return false;
+                               }
+                               string upgrade = headers.Get ("Upgrade");
+                               if (upgrade == null || ! upgrade.Equals ("websocket", StringComparison.OrdinalIgnoreCase)) {
+                                       return false;
+                               }
+                               return true;
                        }
                }