public void AddCompression() { HttpRequestBase request = Context.Request; HttpResponseBase response = Context.Response; //if debug is on, then don't compress if (!Context.IsDebuggingEnabled) { //check if this request should be compressed based on the mime type and path var m = GetSupportedPath(); if (IsSupportedMimeType() && m != null) { var cType = Context.GetClientCompression(); Context.AddCompressionResponseHeader(cType); if (cType == CompressionType.deflate) { response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress); } else if (cType == CompressionType.gzip) { response.Filter = new GZipStream(response.Filter, CompressionMode.Compress); } } } }
internal static void PerformCompression(HttpContextBase context) { var cType = context.GetClientCompression(); context.AddCompressionResponseHeader(cType); if (cType == CompressionType.deflate) { context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress); } else if (cType == CompressionType.gzip) { context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress); } }
private byte[] ProcessRequestInternal(HttpContextBase context, string fileset, ClientDependencyType type, int version, byte[] outputBytes, OutputCachedPage page, out bool success) { //get the compression type supported var clientCompression = context.GetClientCompression(); var x1 = ClientDependencySettings.Instance; if (x1 == null) { throw new Exception("x1"); } var x2 = x1.DefaultFileMapProvider; if (x2 == null) { throw new Exception("x2"); } //get the map to the composite file for this file set, if it exists. var map = ClientDependencySettings.Instance.DefaultFileMapProvider.GetCompositeFile(fileset, version, clientCompression.ToString()); string compositeFileName = ""; if (map != null && map.HasFileBytes) { ProcessFromFile(context, map, out compositeFileName, out outputBytes); } else { lock (Lock) { //check again... if (map != null && map.HasFileBytes) { //there's files there now, so process them ProcessFromFile(context, map, out compositeFileName, out outputBytes); } else { List <CompositeFileDefinition> fileDefinitions; byte[] fileBytes; if (ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.UrlType == CompositeUrlType.MappedId) { //need to try to find the map by it's id/version (not compression) var filePaths = ClientDependencySettings.Instance.DefaultFileMapProvider.GetDependentFiles(fileset, version); if (filePaths == null) { success = false; ClientDependencySettings.Instance.Logger.Error("no map was found for the dependency key: " + fileset + " ,CompositeUrlType.MappedId requires that a map is found", null); return(null); } var filePathArray = filePaths.ToArray(); // sanity check/fix for file type type = ValidateTypeFromFileNames(context, type, filePathArray); //combine files and get the definition types of them (internal vs external resources) fileBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider .CombineFiles(filePathArray, context, type, out fileDefinitions); } else { //need to do the combining, etc... and save the file map fileBytes = GetCombinedFiles(context, fileset, type, out fileDefinitions); } if (fileDefinitions.Count == 0) { //nothing was processed success = false; return(null); } //compress data outputBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.CompressBytes(clientCompression, fileBytes); context.AddCompressionResponseHeader(clientCompression); //save combined file var compositeFile = ClientDependencySettings.Instance .DefaultCompositeFileProcessingProvider .SaveCompositeFile(outputBytes, type, context.Server); if (compositeFile != null) { compositeFileName = compositeFile.FullName; if (!string.IsNullOrEmpty(compositeFileName)) { //Update the XML file map ClientDependencySettings.Instance.DefaultFileMapProvider.CreateUpdateMap(fileset, clientCompression.ToString(), #if !Net35 fileDefinitions.Select(x => new BasicFile(type) { FilePath = x.Uri }), #else fileDefinitions.Select(x => (IClientDependencyFile) new BasicFile(type) { FilePath = x.Uri }), #endif compositeFileName, version); } } } } } //set our caching params SetCaching(context, compositeFileName, fileset, clientCompression, page); success = true; return(outputBytes); }
internal byte[] ProcessRequestInternal(HttpContextBase context, string fileset, ClientDependencyType type, int version, byte[] outputBytes, OutputCachedPage page) { //get the compression type supported var clientCompression = context.GetClientCompression(); var x1 = ClientDependencySettings.Instance; if (x1 == null) { throw new Exception("x1"); } var x2 = x1.DefaultFileMapProvider; if (x2 == null) { throw new Exception("x2"); } //get the map to the composite file for this file set, if it exists. var map = ClientDependencySettings.Instance.DefaultFileMapProvider.GetCompositeFile(fileset, version, clientCompression.ToString()); string compositeFileName = ""; if (map != null && map.HasFileBytes) { ProcessFromFile(context, map, out compositeFileName, out outputBytes); } else { lock (Lock) { //check again... if (map != null && map.HasFileBytes) { //there's files there now, so process them ProcessFromFile(context, map, out compositeFileName, out outputBytes); } else { List <CompositeFileDefinition> fileDefinitions; byte[] fileBytes; if (ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.UrlType == CompositeUrlType.MappedId) { //need to try to find the map by it's id/version (not compression) var filePaths = ClientDependencySettings.Instance.DefaultFileMapProvider.GetDependentFiles(fileset, version); if (filePaths == null) { if (context.IsDebuggingEnabled || dnnConfig.IsDebugMode()) { throw new KeyNotFoundException("no map was found for the dependency key: " + fileset + " ,CompositeUrlType.MappedId requires that a map is found"); } throw new HttpException(404, "File not found"); } //combine files and get the definition types of them (internal vs external resources) fileBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider .CombineFiles(filePaths.ToArray(), context, type, out fileDefinitions); } else { //need to do the combining, etc... and save the file map fileBytes = GetCombinedFiles(context, fileset, type, out fileDefinitions); } //compress data outputBytes = ClientDependencySettings.Instance.DefaultCompositeFileProcessingProvider.CompressBytes(clientCompression, fileBytes); context.AddCompressionResponseHeader(clientCompression); //save combined file var compositeFile = ClientDependencySettings.Instance .DefaultCompositeFileProcessingProvider .SaveCompositeFile(outputBytes, type, context.Server); if (compositeFile != null) { compositeFileName = compositeFile.FullName; if (!string.IsNullOrEmpty(compositeFileName)) { //Update the XML file map ClientDependencySettings.Instance.DefaultFileMapProvider.CreateUpdateMap(fileset, clientCompression.ToString(), fileDefinitions.Select(x => new BasicFile(type) { FilePath = x.Uri }), compositeFileName, //TODO: We should probably use the passed in version param? ClientDependencySettings.Instance.Version); } } } } } //set our caching params SetCaching(context, compositeFileName, fileset, clientCompression, page); return(outputBytes); }