<commit_before>﻿using System;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Signatory.Extensions;
using Signatory.Framework;

namespace Signatory
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            ValueProviderFactories.Factories.Add(new CookieValueProviderFactory());

            MvcHandler.DisableMvcResponseHeader = true;

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

        public override string GetVaryByCustomString(HttpContext context, string arg) 
        {
            switch (arg) 
            {
                case "IsRepoCollaborator":
                    var collabs = context.GetCollaborators();

                    if (collabs == null)
                        return false.ToString();

                    var result = collabs.Any(c => c.Equals(User.Identity.Name, StringComparison.InvariantCultureIgnoreCase)).ToString();
                    return result;
                default:
                    return base.GetVaryByCustomString(context, arg);
            }
        }

        protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
        {
            var httpRuntime = sender as HttpApplication;

            if (httpRuntime != null)
                httpRuntime.Context.Response.Headers.Remove("Server");
        } 
    }
}<commit_msg>Add Strict-Transport-Security header and http->https redirect<commit_after>﻿using System;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Signatory.Extensions;
using Signatory.Framework;

namespace Signatory
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            ValueProviderFactories.Factories.Add(new CookieValueProviderFactory());

            MvcHandler.DisableMvcResponseHeader = true;

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

        public override string GetVaryByCustomString(HttpContext context, string arg) 
        {
            switch (arg) 
            {
                case "IsRepoCollaborator":
                    var collabs = context.GetCollaborators();

                    if (collabs == null)
                        return false.ToString();

                    var result = collabs.Any(c => c.Equals(User.Identity.Name, StringComparison.InvariantCultureIgnoreCase)).ToString();
                    return result;
                default:
                    return base.GetVaryByCustomString(context, arg);
            }
        }

        protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
        {
            var httpRuntime = sender as HttpApplication;

            if (httpRuntime != null)
                httpRuntime.Context.Response.Headers.Remove("Server");
        }

        protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            switch (Request.Url.Scheme)
            {
                case "https":
                    Response.AddHeader("Strict-Transport-Security", "max-age=3600"); // one hour
                    break;
                case "http":
                    var path = "https://" + Request.Url.Host + Request.Url.PathAndQuery;
                    Response.Status = "301 Moved Permanently";
                    Response.AddHeader("Location", path);
                    break;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08383096003674782, 'fraction_numerical': 0.005741846577859439, 'mean_word_length': 2.0306193458594293, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 1, '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': '3844589', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1037, 'n_words': 220}