diff --git a/src/HTTP/HttpServer.cs b/src/HTTP/HttpServer.cs index 9fcbec45..232fa424 100644 --- a/src/HTTP/HttpServer.cs +++ b/src/HTTP/HttpServer.cs @@ -205,10 +205,10 @@ private void _ReceiveRequests() ); } - if (context.Request.IsWebSocketRequest is false) - { - bool answer = false; + bool foundPath = false; + if (request.IsWebSocket is false) // IS HTTP CONNECTION + { foreach (var path in _paths) { if (request.ComparePath(path.url)) @@ -222,38 +222,24 @@ private void _ReceiveRequests() _onPath?.Invoke(null, new PathContainer(request, response, null)); } - answer = true; + foundPath = true; } } - - if (!answer) - { - string data = $"{request.RawRequest.HttpMethod.ToUpper()} {request.Path}"; - response.Send(404, data); - } } else { - bool answer = false; - foreach (var path in _paths) { if (request.ComparePath(path.url)) { if (path.isWebSocket) { - answer = true; + foundPath = true; } } } - if (answer is false) - { - // TODO: Check best way for refuse connection. - string data = $"{request.RawRequest.HttpMethod.ToUpper()} {request.Path}"; - response.Send(404, data); - } - else + if (foundPath) { ThreadPool.QueueUserWorkItem(async __ => { @@ -269,6 +255,22 @@ private void _ReceiveRequests() }); } } + + if (foundPath is false) + { + if (request.IsWebSocket) + { + // TODO: Check best way for refuse websocket connection. + string data = $"{request.RawRequest.HttpMethod.ToUpper()} {request.Path}"; + response.Send(404, data); + } + else + { + // TODO: Check best may for refuse http connection. + string data = $"{request.RawRequest.HttpMethod.ToUpper()} {request.Path}"; + response.Send(404, data); + } + } } catch (Exception e) {