Ejemplo n.º 1
0
        private void ParseRequest()
        {
            Match reqMatch = Regex.Match(_request, @"^\w+\s+([^\s\?]+)[^\s]*\s+HTTP/.*|"); // GET / HTTP/1.1

            if (reqMatch == Match.Empty)
            {
                SendError(HttpStatusCode.BadRequest);
                return;
            }

            RequestUrl = reqMatch.Groups[1].Value;

            if (Program.IsDebugEnabled)
            {
                Console.WriteLine("{0} requested: {1}", _currentTcpClient.Client.RemoteEndPoint, RequestUrl);
            }

            RequestUrl = Uri.UnescapeDataString(RequestUrl); // %20 => " "

            if (_request.Contains(".."))                     // pc.odstudio.site/../../../
            {
                SendError(HttpStatusCode.BadRequest);
                return;
            }

            if (RequestUrl.EndsWith('/'))
            {
                RequestUrl += Program.DefaultFileName;
            }

            RequestedFilePath = $"www/{RequestUrl}";
            if (Program.IsDebugEnabled)
            {
                Console.WriteLine($"Requested File: {RequestedFilePath}");
            }
            FileWork();
        }