Exemplo n.º 1
0
        public LibraryFileContext(HttpContext context, LibraryFileOptions options, PathString prefixUrl, ILogger logger, IContentTypeProvider contentTypeProvider, ILibraryPathProvider pathProvider)
        {
            _context             = context;
            _options             = options;
            _prefixUrl           = prefixUrl;
            _request             = context.Request;
            _response            = context.Response;
            _logger              = logger;
            _requestHeaders      = _request.GetTypedHeaders();
            _responseHeaders     = _response.GetTypedHeaders();
            _contentTypeProvider = contentTypeProvider;
            _pathProvider        = pathProvider;

            _method                 = null;
            _isGet                  = false;
            _isHead                 = false;
            _subPath                = PathString.Empty;
            _library                = null;
            _fileProvider           = null;
            _contentType            = null;
            _fileInfo               = null;
            _length                 = 0;
            _lastModified           = new DateTimeOffset();
            _etag                   = null;
            _ifMatchState           = PreconditionState.Unspecified;
            _ifNoneMatchState       = PreconditionState.Unspecified;
            _ifModifiedSinceState   = PreconditionState.Unspecified;
            _ifUnmodifiedSinceState = PreconditionState.Unspecified;
            _range                  = null;
            _isRangeRequest         = false;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the StaticFileMiddleware.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="hostingEnv">The <see cref="IHostingEnvironment"/> used by this middleware.</param>
        /// <param name="options">The configuration options.</param>
        /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
        /// <param name="pathProvider">The <see cref="ILibraryPathProvider"/> instanc used to provide libraries exposed by this server.</param>
        public LibraryFileMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, IOptions <LibraryFileOptions> options, ILoggerFactory loggerFactory, ILibraryPathProvider pathProvider)
        {
            if (hostingEnv == null)
            {
                throw new ArgumentNullException(nameof(hostingEnv));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _next                = next ?? throw new ArgumentNullException(nameof(next));
            _options             = options.Value;
            _contentTypeProvider = options.Value.ContentTypeProvider ?? new LibraryContentTypeProvider();
            _pathProvider        = pathProvider;
            _prefixUrl           = _options.RequestPath;
            _logger              = loggerFactory?.CreateLogger <LibraryFileMiddleware>() ?? throw new ArgumentNullException(nameof(loggerFactory));
        }
 /// <summary>
 /// Enables static file serving with the given options
 /// </summary>
 /// <param name="app"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IApplicationBuilder UseLibraryFiles(this IApplicationBuilder app, LibraryFileOptions options)
 {
     if (app == null)
     {
         throw new ArgumentNullException(nameof(app));
     }
     if (options == null)
     {
         throw new ArgumentNullException(nameof(options));
     }
     return(app.UseMiddleware <LibraryFileMiddleware>(Options.Create(options)));
 }