Пример #1
0
        /// <summary>
        /// Excute the request and response the needes content
        /// <para>Save the response in the Output cach for next requests</para>
        /// </summary>
        /// <param name="context"></param>
        /// <param name="absoluteFiles"></param>
        /// <param name="minify"></param>
        /// <param name="versionHash"></param>
        /// <param name="encodingMgr"></param>
        public void Excute(HttpContext context, string[] absoluteFiles, Minifier minify, int versionHash, EncodingManager encodingMgr)
        {
            context.Response.Write(SR.GetString(SR.CREDIT_STRING));

            List<string> exsitingFiles = new List<string>();
            for (int i = 0; i < absoluteFiles.Length; i++)
            {
                WriteContent(context, GetFileContent(absoluteFiles[i], minify, exsitingFiles));
            }
            SetResponseCacheSettings(context, exsitingFiles.ToArray());
            if (encodingMgr.IsEncodingEnabled)
            {
                encodingMgr.CompressResponse();
                encodingMgr.SetResponseEncodingType();
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the PostReleaseRequestState event.
        /// </summary>
        /// <param name="sender">The object that raised the event (HttpApplication)</param>
        /// <param name="e">The event data</param>
        void OnPostReleaseRequestState(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;

            if (app.Context == null)
                return;

            // This part of the module compress only handlers from type System.Web.UI.Page
            // Other types such JavaScript or CSS files will be compressed in an httpHandelr.
            // Here we check if the current handler if a Page, if so, we compress it.
            if (app.Context.CurrentHandler is System.Web.UI.Page && app.Context.Response != null && Util.IsUIPageContentType(app.Context.Response.ContentType))
            {
                // Check if the path is not excluded.
                if (!settings.IsValidPath(app.Request.AppRelativeCurrentExecutionFilePath))
                    return;

                // Check if the mime type is not ecluded. (Use to exclude pages that generate specific mime type (such image or Excel...))
                if (!settings.IsValidType(app.Response.ContentType))
                    return;

                // Because there is a problem with async postbacks compression, we check here if the current request if an 'MS AJAX' call.
                // If so, we will not compress it.
                if (settings.CompressPage && !(Util.IsMsAjaxRequest(app.Context) && settings.MSAjaxVersion < 3.5))
                {
                    EncodingManager encodingMgr = new EncodingManager(app.Context);

                    if (encodingMgr.IsEncodingEnabled)
                    {
                        encodingMgr.CompressResponse();
                        encodingMgr.SetResponseEncodingType();
                    }
                }

                if (settings.AutoMode)
                {
                    bool processCss = settings.CompressCSS || settings.MinifyContent;
                    bool processJs = settings.CompressJavaScript || settings.MinifyContent;
                    app.Response.Filter = new AutoModeFilterStream(app.Response.Filter,app.Response.ContentEncoding, processJs,processCss);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Handles the PreRequestHandlerExecute event.
        /// The compression moved to this step to catch Server.Transfer operation
        /// </summary>
        /// <param name="sender">The object that raised the event (HttpApplication)</param>
        /// <param name="e">The event data</param>
        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;

            if (app.Context == null || app.Context.Response == null)
                return;

            // This part of the module compress only handlers from type System.Web.UI.Page
            // Other types such JavaScript or CSS files will be compressed in an httpHandelr.
            // Here we check if the current handler if a Page handler, if so, we compress it.
            if (app.Context.CurrentHandler is System.Web.UI.Page && app.Context.Response != null)
            {
                // Check if the path is not excluded.
                if (!settings.IsValidPath(app.Request.AppRelativeCurrentExecutionFilePath))
                    return;

                if (Util.IsToolkitScriptManagerCombiner(app.Request))
                    return;

                if (settings.CompressPage && !Util.IsContainExcludedParamValue(app.Context) && !(Util.IsMsAjaxRequest(app.Context) && settings.MSAjaxVersion < 3.5))
                {
                    EncodingManager encodingMgr = new EncodingManager(app.Context);

                    if (encodingMgr.IsEncodingEnabled)
                    {
                        // Add preferredEncoding to the context.items for use later in the pipeline
                        app.Context.Items.Add("preferredEncoding", encodingMgr.PreferredEncoding);
                        //Add the compression filter
                        encodingMgr.CompressResponse();
                    }
                }

                if (settings.AutoMode && !Util.IsMsAjaxRequest(app.Context))
                {
                    bool processCss = settings.CompressCSS || settings.MinifyContent || settings.CombineCSS;
                    bool processJs = settings.CompressJavaScript || settings.MinifyContent;
                    app.Response.Filter = new AutoModeFilterStream(app.Response.Filter, app.Response.ContentEncoding, processJs, processCss, settings.CombineCSS, settings.CombineHeaderScripts);
                }
            }
        }