Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StaticFilesModule" /> class.
        /// </summary>
        /// <param name="fileSystemPath">The file system path.</param>
        /// <param name="headers">The headers to set in every request.</param>
        /// <param name="additionalPaths">The additional paths.</param>
        /// <exception cref="System.ArgumentException">Path ' + fileSystemPath + ' does not exist.</exception>
        public StaticFilesModule(
            string fileSystemPath,
            Dictionary <string, string> headers         = null,
            Dictionary <string, string> additionalPaths = null)
        {
            if (Directory.Exists(fileSystemPath) == false)
            {
                throw new ArgumentException($"Path '{fileSystemPath}' does not exist.");
            }

            _virtualPaths.FileSystemPath = Path.GetFullPath(fileSystemPath);
            UseGzip = true;
#if DEBUG
            // When debugging, disable RamCache
            UseRamCache = false;
#else
// Otherwise, enable it by default
            this.UseRamCache = true;
#endif
            RamCache            = new RamCache();
            MaxRamCacheFileSize = 250 * 1024;
            DefaultDocument     = DefaultDocumentName;

            headers?.ForEach(DefaultHeaders.Add);
            additionalPaths?.Where(path => path.Key != "/")
            .ToDictionary(x => x.Key, x => x.Value)
            .ForEach(RegisterVirtualPath);

            AddHandler(ModuleMap.AnyPath, HttpVerbs.Head, (context, ct) => HandleGet(context, ct, false));
            AddHandler(ModuleMap.AnyPath, HttpVerbs.Get, (context, ct) => HandleGet(context, ct));
        }
 /// <summary>
 /// Clears the RAM cache.
 /// </summary>
 public void ClearRamCache()
 {
     RamCache.Clear();
 }
 /// <summary>
 /// Clears the RAM cache.
 /// </summary>
 public void ClearRamCache() => RamCache.Clear();