/// <summary> /// Enables static file serving for the current request path. /// </summary> /// <param name="app">The <see cref="ServerOptions"/> instance this method extends.</param> /// <param name="options">The <see cref="StaticFileOptions"/> used to configure the middleware.</param> public static void UseStaticFiles(this ServerOptions app, StaticFileOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } app.UseMiddleware(new StaticFileMiddleware(options)); }
/// <summary> /// Initializes a new instance of the <see cref="StaticFileMiddleware"/> class. /// </summary> /// <param name="loggerFactory">The factory used to create loggers.</param> /// <param name="options">The <see cref="StaticFileOptions"/> used to configure the middleware.</param> public StaticFileMiddleware(ILoggerFactory loggerFactory, StaticFileOptions options) { if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _logger = loggerFactory.CreateLogger("Bytewizer.TinyCLR.Http"); _options = options; _driveProvider = _options.DriveProvider; _contentTypeProvider = _options.ContentTypeProvider ?? new DefaultContentTypeProvider(); }
private static bool LookupContentType( IContentTypeProvider contentTypeProvider, StaticFileOptions options, string subPath, out string contentType) { if (contentTypeProvider.TryGetContentType(subPath, out contentType)) { return(true); } if (options.ServeUnknownFileTypes) { contentType = options.DefaultContentType; return(true); } return(false); }
/// <summary> /// Initializes a default instance of the <see cref="StaticFileMiddleware"/> class. /// </summary> /// <param name="options">The <see cref="StaticFileOptions"/> used to configure the middleware.</param> public StaticFileMiddleware(StaticFileOptions options) : this(NullLoggerFactory.Instance, options) { }
/// <summary> /// Enables static file serving for the current request path. /// </summary> /// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param> /// <param name="options">The <see cref="StaticFileOptions"/> used to configure the middleware.</param> public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder app, StaticFileOptions options) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } return(app.UseMiddleware(typeof(StaticFileMiddleware), options)); }