Ejemplo n.º 1
0
        private static Stream CreateCompressStream(FileStream stream, string encoding)
        {
            if (encoding == "gzip")
            {
                return(new GZipStream(stream, CompressionMode.Compress));
            }

            DebugThrow.IfNotEqual("deflate", encoding);
            return(new DeflateStream(stream, CompressionMode.Compress));
        }
Ejemplo n.º 2
0
        internal static IImageData Create(IUrlResolver urlResolver, MagickFormatInfo formatInfo)
        {
            IFileUrlResolver fileUrlResolver = urlResolver as IFileUrlResolver;

            if (fileUrlResolver != null)
            {
                return(new FileImageData(fileUrlResolver.FileName, formatInfo));
            }

            IStreamUrlResolver streamUrlResolver = urlResolver as IStreamUrlResolver;

            DebugThrow.IfNull(streamUrlResolver);
            return(new StreamImageData(streamUrlResolver, formatInfo));
        }
Ejemplo n.º 3
0
        protected override string GetFileName(HttpContext context)
        {
            DebugThrow.IfNull(nameof(context), context);

            string encoding = GetEncoding(context.Request);

            if (string.IsNullOrEmpty(encoding))
            {
                return(null);
            }

            string cacheFileName = GetCacheFileName("Compressed", encoding, ImageData.FormatInfo.Format);

            if (!CanUseCache(cacheFileName))
            {
                CreateCompressedFile(encoding, cacheFileName);
            }

            context.Response.AppendHeader("Content-Encoding", encoding);
            context.Response.AppendHeader("Vary", "Accept-Encoding");

            return(cacheFileName);
        }