/// <summary>
        /// Processes the response and sets a XML minification response filter
        /// </summary>
        /// <param name="sender">The source of the event (HTTP application)</param>
        /// <param name="e">An System.EventArgs that contains no event data</param>
        private void ProcessResponse(object sender, EventArgs e)
        {
            if (!_configuration.IsMinificationEnabled())
            {
                return;
            }

            IMarkupMinificationManager minificationManager =
                _minificationManager ?? GetDefaultMinificationManager();
            HttpContext  context    = ((HttpApplication)sender).Context;
            HttpRequest  request    = context.Request;
            HttpResponse response   = context.Response;
            Encoding     encoding   = response.ContentEncoding;
            string       mediaType  = response.ContentType;
            string       currentUrl = request.RawUrl;

            if (request.HttpMethod == "GET" && response.StatusCode == 200 &&
                context.CurrentHandler != null &&
                minificationManager.IsSupportedMediaType(mediaType) &&
                minificationManager.IsProcessablePage(currentUrl))
            {
                response.Filter = new MarkupMinificationFilterStream(new HttpResponseWrapper(response),
                                                                     _configuration, minificationManager, currentUrl, encoding);
            }
        }
Esempio n. 2
0
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if (!_configuration.IsMinificationEnabled())
            {
                return;
            }

            IMarkupMinificationManager minificationManager =
                _minificationManager ?? GetDefaultMinificationManager();
            HttpContextBase  context    = filterContext.HttpContext;
            HttpRequestBase  request    = context.Request;
            HttpResponseBase response   = context.Response;
            Encoding         encoding   = response.ContentEncoding;
            string           httpMethod = request.HttpMethod;
            string           mediaType  = response.ContentType;
            string           currentUrl = request.RawUrl;

            if (response.Filter != null && response.StatusCode == 200 &&
                minificationManager.IsSupportedHttpMethod(httpMethod) &&
                minificationManager.IsSupportedMediaType(mediaType) &&
                minificationManager.IsProcessablePage(currentUrl))
            {
                response.Filter = new MarkupMinificationFilterStream(response, _configuration,
                                                                     minificationManager, currentUrl, encoding);
            }
        }