Esempio n. 1
0
        public void FileSystemConfiguration_AddSiteRoot_Adds_Trailing_Directory_Separator_To_Folder()
        {
            var folder = @"c:\web";

            _FileSystemProvider.AddFolder(folder);

            _Configuration.AddSiteRoot(new SiteRoot()
            {
                Folder = folder
            });

            var folders        = _Configuration.GetSiteRootFolders();
            var siteRootFolder = folders[0];

            Assert.AreEqual(Path.DirectorySeparatorChar, siteRootFolder[siteRootFolder.Length - 1]);
        }
Esempio n. 2
0
        /// <summary>
        /// Honours requests for files from the file system. Returns false if no file matched the request.
        /// </summary>
        /// <param name="environment"></param>
        /// <returns></returns>
        private bool ServeFromFileSystem(IDictionary <string, object> environment)
        {
            var result = false;

            var context  = PipelineContext.GetOrCreate(environment);
            var request  = context.Request;
            var response = context.Response;

            var relativePath = ConvertRequestPathToRelativeFilePath(request.FlattenedPath);

            relativePath = RejectInvalidCharacters(relativePath);
            if (!String.IsNullOrEmpty(relativePath))
            {
                foreach (var siteRoot in _Configuration.GetSiteRootFolders())
                {
                    var fullPath = Path.Combine(siteRoot, relativePath);

                    if (FileSystemProvider.FileExists(fullPath))
                    {
                        var extension = Path.GetExtension(fullPath);
                        var mimeType  = MimeType.GetForExtension(extension) ?? "application/octet-stream";
                        var content   = FileSystemProvider.FileReadAllBytes(fullPath);

                        if (_Configuration.IsFileUnmodified(siteRoot, request.FlattenedPath, content))
                        {
                            content = RaiseTextLoadedFromFile(request, content, mimeType);
                            SendContent(response, content, mimeType);
                        }
                        else
                        {
                            if (mimeType != MimeType.Html)
                            {
                                response.StatusCode = (int)HttpStatusCode.BadRequest;
                            }
                            else
                            {
                                content = Encoding.UTF8.GetBytes("<HTML><HEAD><TITLE>No</TITLE></HEAD><BODY>VRS will not serve content that has been tampered with. Install the custom content plugin if you want to alter the site's files.</BODY></HTML>");
                                SendContent(response, content, mimeType);
                            }
                        }

                        result = true;
                        break;
                    }
                }
            }

            return(result);
        }