private void processRequest(TcpListenerWebSocketContext context)
        {
            var uri = context.RequestUri;

            if (uri == null)
            {
                context.Close(HttpStatusCode.BadRequest);
                return;
            }

            if (!_allowForwardedRequest)
            {
                if (uri.Port != _port)
                {
                    context.Close(HttpStatusCode.BadRequest);
                    return;
                }

                if (!checkHostNameForRequest(uri.DnsSafeHost))
                {
                    context.Close(HttpStatusCode.NotFound);
                    return;
                }
            }

            WebSocketServiceHost host;

            if (!_services.InternalTryGetServiceHost(uri.AbsolutePath, out host))
            {
                context.Close(HttpStatusCode.NotImplemented);
                return;
            }

            host.StartSession(context);
        }
Example #2
0
        private void processRequest(TcpListenerWebSocketContext context)
        {
            var uri = context.RequestUri;

            if (uri == null)
            {
                context.Close(HttpStatusCode.BadRequest);
                return;
            }

            if (_uri.IsAbsoluteUri)
            {
                var actual   = uri.DnsSafeHost;
                var expected = _uri.DnsSafeHost;
                if (Uri.CheckHostName(actual) == UriHostNameType.Dns &&
                    Uri.CheckHostName(expected) == UriHostNameType.Dns &&
                    actual != expected)
                {
                    context.Close(HttpStatusCode.NotFound);
                    return;
                }
            }

            WebSocketServiceHost host;

            if (!_services.InternalTryGetServiceHost(uri.AbsolutePath, out host))
            {
                context.Close(HttpStatusCode.NotImplemented);
                return;
            }

            host.StartSession(context);
        }
Example #3
0
        private void processRequest(TcpListenerWebSocketContext context)
        {
            var uri = context.RequestUri;

            if (uri == null || uri.Port != _port)
            {
                context.Close(HttpStatusCode.BadRequest);
                return;
            }

            if (_dnsStyle)
            {
                var hostname = uri.DnsSafeHost;
                if (Uri.CheckHostName(hostname) == UriHostNameType.Dns && hostname != _hostname)
                {
                    context.Close(HttpStatusCode.NotFound);
                    return;
                }
            }

            WebSocketServiceHost host;

            if (!_services.InternalTryGetServiceHost(uri.AbsolutePath, out host))
            {
                context.Close(HttpStatusCode.NotImplemented);
                return;
            }

            host.StartSession(context);
        }
Example #4
0
        private void processRequest(HttpListenerWebSocketContext context)
        {
            var uri = context.RequestUri;

            if (uri == null)
            {
                context.Close(HttpStatusCode.BadRequest);

                return;
            }

            var path = uri.AbsolutePath;

            if (path.IndexOfAny(new[] { '%', '+' }) > -1)
            {
                path = HttpUtility.UrlDecode(path, Encoding.UTF8);
            }

            WebSocketServiceHost host;

            if (!_services.InternalTryGetServiceHost(path, out host))
            {
                context.Close(HttpStatusCode.NotImplemented);

                return;
            }

            host.StartSession(context);
        }
        private void processRequest(TcpListenerWebSocketContext context)
        {
            Uri requestUri = context.RequestUri;

            if (requestUri == null)
            {
                context.Close(WebSocketSharp.Net.HttpStatusCode.BadRequest);
                return;
            }
            if (_uri.IsAbsoluteUri)
            {
                string dnsSafeHost  = requestUri.DnsSafeHost;
                string dnsSafeHost2 = _uri.DnsSafeHost;
                if (Uri.CheckHostName(dnsSafeHost) == UriHostNameType.Dns && Uri.CheckHostName(dnsSafeHost2) == UriHostNameType.Dns && dnsSafeHost != dnsSafeHost2)
                {
                    context.Close(WebSocketSharp.Net.HttpStatusCode.NotFound);
                    return;
                }
            }
            if (!_services.InternalTryGetServiceHost(requestUri.AbsolutePath, out var host))
            {
                context.Close(WebSocketSharp.Net.HttpStatusCode.NotImplemented);
            }
            else
            {
                host.StartSession(context);
            }
        }
Example #6
0
 private void processRequest(HttpListenerWebSocketContext context)
 {
     if (!_services.InternalTryGetServiceHost(context.RequestUri.AbsolutePath, out var host))
     {
         context.Close(HttpStatusCode.NotImplemented);
     }
     else
     {
         host.StartSession(context);
     }
 }
Example #7
0
        private void processRequest(TcpListenerWebSocketContext context)
        {
            if (!authenticateClient(context))
            {
                context.Close(HttpStatusCode.Forbidden);

                return;
            }

            var uri = context.RequestUri;

            if (uri == null)
            {
                context.Close(HttpStatusCode.BadRequest);

                return;
            }

            if (!_allowForwardedRequest)
            {
                if (uri.Port != _port)
                {
                    context.Close(HttpStatusCode.BadRequest);

                    return;
                }

                if (!checkHostNameForRequest(uri.DnsSafeHost))
                {
                    context.Close(HttpStatusCode.NotFound);

                    return;
                }
            }

            var path = uri.AbsolutePath;

            if (path.IndexOfAny(new[] { '%', '+' }) > -1)
            {
                path = HttpUtility.UrlDecode(path, Encoding.UTF8);
            }

            WebSocketServiceHost host;

            if (!_services.InternalTryGetServiceHost(path, out host))
            {
                context.Close(HttpStatusCode.NotImplemented);

                return;
            }

            host.StartSession(context);
        }
Example #8
0
		private void processRequest (HttpListenerWebSocketContext context)
			{
			WebSocketServiceHost host;
			string path = context.RequestUri.AbsolutePath;
			if (!_services.InternalTryGetServiceHost (path, out host))
				{
				if (OnResolveWebSocketServiceHost != null)
					{
					var hrwsshea = new HttpResolveWebSocketServiceHostEventArgs (HttpUtility.UrlDecode (path).TrimSlashFromEnd ());
					OnResolveWebSocketServiceHost (this, hrwsshea);
					host = hrwsshea.Host;
					}

				if (host == null)
					{
					context.Close (HttpStatusCode.NotImplemented);
					return;
					}
				}

			host.StartSession (context);
			}
        private async Task ProcessWebSocketRequest(TcpListenerWebSocketContext context)
        {
            var uri = await context.GetRequestUri().ConfigureAwait(false);

            if (uri == null)
            {
                await context.Close(HttpStatusCode.BadRequest).ConfigureAwait(false);

                return;
            }

            if (_uri.IsAbsoluteUri)
            {
                var actual   = uri.DnsSafeHost;
                var expected = _uri.DnsSafeHost;
                if (Uri.CheckHostName(actual) == UriHostNameType.Dns &&
                    Uri.CheckHostName(expected) == UriHostNameType.Dns &&
                    actual != expected)
                {
                    await context.Close(HttpStatusCode.NotFound).ConfigureAwait(false);

                    return;
                }
            }

            WebSocketServiceHost host;

            if (!_services.InternalTryGetServiceHost(uri.AbsolutePath, out host))
            {
                await context.Close(HttpStatusCode.NotImplemented).ConfigureAwait(false);

                return;
            }

            await host.StartSession(context).ConfigureAwait(false);
        }