public static httpResponse GetResponse(RequestParser parsedRequest)
        {
            string   filePath = Environment.CurrentDirectory + HTTPServer.WEB_DIR + parsedRequest.Url;
            FileInfo file     = new FileInfo(filePath);

            if (!file.Exists)
            {
                return(GetFileFromDirectory(filePath + "/"));
            }
            return(GetResponseMessage(file));
        }
Exemple #2
0
      public static bool IsValidFile(RequestParser parsedRequest, out int statusCode)
      {
          string   filePath = Environment.CurrentDirectory + HTTPServer.WEB_DIR + parsedRequest.Url;
          FileInfo file     = new FileInfo(filePath);

          if (file.Exists)
          {
              statusCode = 200;
              return(true);
          }
          return(IsValidDirectory(filePath, out statusCode));
      }
Exemple #3
0
 { public static bool IsValidRequest(RequestParser parsedRequest, out int statusCode)
   {
       if (parsedRequest.Host == null)
       {
           statusCode = 400;
           return(false);
       }
       else if (parsedRequest.Method != "GET")
       {
           statusCode = 405;
           return(false);
       }
       return(IsValidFile(parsedRequest, out statusCode));
   }
        public HttpRequestHandler(string requestMessage, TcpClient client)
        {
            httpResponse  httpResponse  = null;
            RequestParser parsedRequest = new RequestParser(requestMessage);

            if (!RequestValidator.IsValidRequest(parsedRequest, out int statusCode))
            {
                httpResponse = ErrorHandler.GetErrorResponseMessage(statusCode);
            }
            else
            {
                httpResponse = FileHandler.GetResponse(parsedRequest);
            }

            httpResponse.Post(client.GetStream());
        }