예제 #1
0
        protected override void HandleHttpRequest(Connection connection, HttpServerRequest request, HttpServerResponse response)
        {
            base.HandleHttpRequest(connection, request, response);

            if (response.ContentSource != ContentSource.ContentNone)
            {
                return;
            }

            if (request.Header.RequestType != "GET")
            {
                response.SendError(HttpStatusCode.BadRequest, String.Format("Request Type '{0}' not supported.", request.Header.RequestType));
                return;
            }

            String lPath = RootPath + request.Header.RequestPath.Replace('/', Path.DirectorySeparatorChar);

            if (lPath.IndexOf("..") > -1)
            {
                response.SendError(HttpStatusCode.Forbidden, String.Format("Bad Request: Path '{0}' contains '..' which is invalid.", lPath));
                return;
            }

            if (!File.Exists(lPath))
            {
                response.SendError(HttpStatusCode.NotFound, String.Format("File '{0}' not found.", lPath));
                return;
            }

            response.Header.ContentType = "text/html";
            response.ContentStream      = new FileStream(lPath, FileOpenMode.ReadOnly);
            response.CloseStream        = true;      /* Response will close stream once it's been sent */
        }