<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;

namespace Sdl.Web.Mvc
{
    /// <summary>
    /// Module to redirect requests for version of static files which no longer exist on disk to the root assets folder
    /// When a request for a static file comes into IIS, it first checks if it exists on disk, and if so, serves it normally
    /// If it does not exist, it enters the ASP.NET pipeline, where this module will pick it up and redirect it
    /// </summary>
    public class StaticRedirectModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(this.BeginRequest);
        }

        private void BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            var url = context.Request.Url.AbsolutePath;
            var versionLessUrl = Configuration.RemoveVersionFromPath(url);
            if (url != versionLessUrl)
            {
                Log.Debug("Redirecting request for non-existent versioned static file {0} to {1}", url, versionLessUrl);
                context.Response.Redirect(versionLessUrl);
            }
        }

        public void Dispose()
        {
            //do nothing
        }
    }
}
<commit_msg>Changed static redirect module to do a Server.TransferRequest rather than Response.Redirect, so browser caches are properly busted for versioned static files<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;

namespace Sdl.Web.Mvc
{
    /// <summary>
    /// Module to redirect requests for version of static files which no longer exist on disk to the root assets folder
    /// When a request for a static file comes into IIS, it first checks if it exists on disk, and if so, serves it normally
    /// If it does not exist, it enters the ASP.NET pipeline, where this module will pick it up and redirect it
    /// </summary>
    public class StaticRedirectModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(this.BeginRequest);
        }

        private void BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            var url = context.Request.Url.AbsolutePath;
            var versionLessUrl = Configuration.RemoveVersionFromPath(url);
            if (url != versionLessUrl)
            {
                Log.Debug("Redirecting request for non-existent versioned static file {0} to {1}", url, versionLessUrl);
                context.Server.TransferRequest(versionLessUrl);
            }
        }

        public void Dispose()
        {
            //do nothing
        }
    }
}

{'fraction_non_alphanumeric': 0.07524815882164586, 'fraction_numerical': 0.001280819724623759, 'mean_word_length': 2.429198682766191, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4220889', 'n_tokens_mistral': 767, 'n_tokens_neox': 754, 'n_words': 284}