Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageSharpMiddleware"/> class.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline</param>
        /// <param name="options">The middleware configuration options</param>
        /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers</param>
        /// <param name="uriParser">An <see cref="IUriParser"/> instance used to parse URI's for commands</param>
        /// <param name="resolvers">A collection of <see cref="IImageResolver"/> instances used to resolve images</param>
        /// <param name="processors">A collection of <see cref="IImageWebProcessor"/> instances used to process images</param>
        /// <param name="cache">An <see cref="IImageCache"/> instance used for caching images</param>
        public ImageSharpMiddleware(
            RequestDelegate next,
            IOptions <ImageSharpMiddlewareOptions> options,
            ILoggerFactory loggerFactory,
            IUriParser uriParser,
            IEnumerable <IImageResolver> resolvers,
            IEnumerable <IImageWebProcessor> processors,
            IImageCache cache)
        {
            Guard.NotNull(next, nameof(next));
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(uriParser, nameof(uriParser));
            Guard.NotNull(resolvers, nameof(resolvers));
            Guard.NotNull(processors, nameof(processors));
            Guard.NotNull(cache, nameof(cache));

            this.next       = next;
            this.options    = options.Value;
            this.uriParser  = uriParser;
            this.resolvers  = resolvers;
            this.processors = processors;
            this.cache      = cache;

            var commands = new List <string>();

            foreach (IImageWebProcessor processor in this.processors)
            {
                commands.AddRange(processor.Commands);
            }

            this.knownCommands = commands;

            this.logger = loggerFactory.CreateLogger <ImageSharpMiddleware>();
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageSharpMiddleware"/> class.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="options">The middleware configuration options.</param>
        /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
        /// <param name="requestParser">An <see cref="IRequestParser"/> instance used to parse image requests for commands.</param>
        /// <param name="resolvers">A collection of <see cref="IImageProvider"/> instances used to resolve images.</param>
        /// <param name="processors">A collection of <see cref="IImageWebProcessor"/> instances used to process images.</param>
        /// <param name="cache">An <see cref="IImageCache"/> instance used for caching images.</param>
        /// <param name="cacheHash">An <see cref="ICacheHash"/>instance used for calculating cached file names.</param>
        /// <param name="commandParser">The command parser</param>
        /// <param name="formatUtilities">Contains various format helper methods based on the current configuration.</param>
        public ImageSharpMiddleware(
            RequestDelegate next,
            IOptions <ImageSharpMiddlewareOptions> options,
            ILoggerFactory loggerFactory,
            IRequestParser requestParser,
            IEnumerable <IImageProvider> resolvers,
            IEnumerable <IImageWebProcessor> processors,
            IImageCache cache,
            ICacheHash cacheHash,
            CommandParser commandParser,
            FormatUtilities formatUtilities)
        {
            Guard.NotNull(next, nameof(next));
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(requestParser, nameof(requestParser));
            Guard.NotNull(resolvers, nameof(resolvers));
            Guard.NotNull(processors, nameof(processors));
            Guard.NotNull(cache, nameof(cache));
            Guard.NotNull(cacheHash, nameof(cacheHash));
            Guard.NotNull(commandParser, nameof(commandParser));
            Guard.NotNull(formatUtilities, nameof(formatUtilities));

            this.next          = next;
            this.options       = options.Value;
            this.requestParser = requestParser;
            this.providers     = resolvers as IImageProvider[] ?? resolvers.ToArray();
            this.processors    = processors as IImageWebProcessor[] ?? processors.ToArray();
            this.cache         = cache;
            this.cacheHash     = cacheHash;
            this.commandParser = commandParser;
            this.parserCulture = this.options.UseInvariantParsingCulture
                ? CultureInfo.InvariantCulture
                : CultureInfo.CurrentCulture;

            var commands = new HashSet <string>();

            foreach (IImageWebProcessor processor in this.processors)
            {
                foreach (string command in processor.Commands)
                {
                    commands.Add(command);
                }
            }

            this.knownCommands = commands;

            this.logger          = loggerFactory.CreateLogger <ImageSharpMiddleware>();
            this.formatUtilities = formatUtilities;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageSharpMiddleware"/> class.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="options">The middleware configuration options.</param>
        /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
        /// <param name="memoryAllocator">An <see cref="MemoryAllocator"/> instance used to allocate arrays transporting encoded image data.</param>
        /// <param name="requestParser">An <see cref="IRequestParser"/> instance used to parse image requests for commands.</param>
        /// <param name="resolvers">A collection of <see cref="IImageProvider"/> instances used to resolve images.</param>
        /// <param name="processors">A collection of <see cref="IImageWebProcessor"/> instances used to process images.</param>
        /// <param name="cache">An <see cref="IImageCache"/> instance used for caching images.</param>
        /// <param name="cacheHash">An <see cref="ICacheHash"/>instance used for calculating cached file names.</param>
        /// <param name="formatUtilities">Contains various format helper methods based on the current configuration.</param>
        public ImageSharpMiddleware(
            RequestDelegate next,
            IOptions <ImageSharpMiddlewareOptions> options,
            ILoggerFactory loggerFactory,
            MemoryAllocator memoryAllocator,
            IRequestParser requestParser,
            IEnumerable <IImageProvider> resolvers,
            IEnumerable <IImageWebProcessor> processors,
            IImageCache cache,
            ICacheHash cacheHash,
            FormatUtilities formatUtilities)
        {
            Guard.NotNull(next, nameof(next));
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(memoryAllocator, nameof(memoryAllocator));
            Guard.NotNull(requestParser, nameof(requestParser));
            Guard.NotNull(resolvers, nameof(resolvers));
            Guard.NotNull(processors, nameof(processors));
            Guard.NotNull(cache, nameof(cache));
            Guard.NotNull(cacheHash, nameof(cacheHash));
            Guard.NotNull(AsyncLock, nameof(AsyncLock));

            this.next            = next;
            this.options         = options.Value;
            this.memoryAllocator = memoryAllocator;
            this.requestParser   = requestParser;
            this.providers       = resolvers as IImageProvider[] ?? resolvers.ToArray();
            this.processors      = processors as IImageWebProcessor[] ?? processors.ToArray();
            this.cache           = cache;
            this.cacheHash       = cacheHash;

            var commands = new HashSet <string>();

            foreach (IImageWebProcessor processor in this.processors)
            {
                foreach (string command in processor.Commands)
                {
                    commands.Add(command);
                }
            }

            this.knownCommands = commands;

            this.logger          = loggerFactory.CreateLogger <ImageSharpMiddleware>();
            this.formatUtilities = formatUtilities;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageSharpMiddleware"/> class.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="options">The middleware configuration options.</param>
        /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
        /// <param name="memoryAllocator">An <see cref="MemoryAllocator"/> instance used to allocate arrays transporting encoded image data.</param>
        /// <param name="requestParser">An <see cref="IRequestParser"/> instance used to parse image requests for commands.</param>
        /// <param name="resolvers">A collection of <see cref="IImageProvider"/> instances used to resolve images.</param>
        /// <param name="processors">A collection of <see cref="IImageWebProcessor"/> instances used to process images.</param>
        /// <param name="cache">An <see cref="IImageCache"/> instance used for caching images.</param>
        /// <param name="cacheHash">An <see cref="ICacheHash"/>instance used for calculating cached file names.</param>
        /// <param name="asyncKeyLock">An <see cref="IAsyncKeyLock"/> instance used for providing locking during processing.</param>
        public ImageSharpMiddleware(
            RequestDelegate next,
            IOptions <ImageSharpMiddlewareOptions> options,
            ILoggerFactory loggerFactory,
            MemoryAllocator memoryAllocator,
            IRequestParser requestParser,
            IEnumerable <IImageProvider> resolvers,
            IEnumerable <IImageWebProcessor> processors,
            IImageCache cache,
            ICacheHash cacheHash,
            IAsyncKeyLock asyncKeyLock)
        {
            Guard.NotNull(next, nameof(next));
            Guard.NotNull(options, nameof(options));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(memoryAllocator, nameof(memoryAllocator));
            Guard.NotNull(requestParser, nameof(requestParser));
            Guard.NotNull(resolvers, nameof(resolvers));
            Guard.NotNull(processors, nameof(processors));
            Guard.NotNull(cache, nameof(cache));
            Guard.NotNull(cache, nameof(cacheHash));
            Guard.NotNull(asyncKeyLock, nameof(asyncKeyLock));

            this.next            = next;
            this.options         = options.Value;
            this.memoryAllocator = memoryAllocator;
            this.requestParser   = requestParser;
            this.resolvers       = resolvers;
            this.processors      = processors;
            this.cache           = cache;
            this.cacheHash       = cacheHash;
            this.asyncKeyLock    = asyncKeyLock;

            var commands = new List <string>();

            foreach (IImageWebProcessor processor in this.processors)
            {
                commands.AddRange(processor.Commands);
            }

            this.knownCommands = commands;

            this.logger = loggerFactory.CreateLogger <ImageSharpMiddleware>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageContext"/> struct.
        /// </summary>
        /// <param name="context">The current HTTP request context</param>
        /// <param name="options">The middleware options</param>
        public ImageContext(HttpContext context, ImageSharpMiddlewareOptions options)
        {
            this.context = context;
            this.request = context.Request;
            this.response = context.Response;

            this.requestHeaders = context.Request.GetTypedHeaders();
            this.responseHeaders = context.Response.GetTypedHeaders();

            this.options = options;

            this.fileLastModified = DateTimeOffset.MinValue;
            this.fileLength = 0;
            this.fileEtag = null;

            this.ifMatchState = PreconditionState.Unspecified;
            this.ifNoneMatchState = PreconditionState.Unspecified;
            this.ifModifiedSinceState = PreconditionState.Unspecified;
            this.ifUnmodifiedSinceState = PreconditionState.Unspecified;
        }