<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Web2Sharp
{
    class ServeStatic
    {
        public static Dictionary<string, string> ContentTypesByExtension = new Dictionary<string, string>()
        {
            ["txt"]  = "text/plain",
            ["htm"]  = "text/html",
            ["html"] = "text/html",
            ["css"]  = "text/css",
            ["js"]   = "application/javascript",
            ["json"] = "application/json",
            ["jpg"]  = "image/jpeg",
            ["jpeg"] = "image/jpeg",
            ["png"]  = "image/png",
            ["gif"]  = "image/gif",
            ["tif"]  = "image/tiff",
            ["tiff"] = "image/tiff",
            ["bmp"]  = "image/bmp",
            ["svg"]  = "image/svg+xml",
            ["swf"]  = "application/x-shockwave-flash",
            ["flv"]  = "video/x-flv",
            ["pdf"]  = "application/pdf",
        }; 

        public static RawHttpResponse ServeStaticFiles(HttpRequest request, string urlPrefix, string rootDirectory)
        {
            string root = Path.GetFullPath(rootDirectory);
            string relativeFilePath = Utils.MakeRelativePath(request.GetParameterASCII("DOCUMENT_URI"), urlPrefix);
            string filePath = Path.GetFullPath(Path.Combine(rootDirectory, relativeFilePath));
            
            // No ../ allowed! Make sure only files inside the rootDirectory are server.
            if(!filePath.StartsWith(root) || !File.Exists(filePath))
            {
                return new HttpResponse("<h1>404 Not Found</h1>", status: "404 Not Found");
            }

            // Try to find the content type for this file extension
            var extension = Path.GetExtension(filePath).ToLower();
            extension = extension.Replace(".", "");
            string contentType = null;
            ContentTypesByExtension.TryGetValue(extension, out contentType);

            var rawData = File.ReadAllBytes(filePath);<commit_msg>Fixed ServeStatic initialization for C# 5.0<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Web2Sharp
{
    class ServeStatic
    {
        public static Dictionary<string, string> ContentTypesByExtension = new Dictionary<string, string>()
        {
            {"txt", "text/plain"},
            {"htm", "text/html"},
            {"html", "text/html"},
            {"css", "text/css"},
            {"js", "application/javascript"},
            {"json", "application/json"},
            {"jpg", "image/jpeg"},
            {"jpeg", "image/jpeg"},
            {"png", "image/png"},
            {"gif", "image/gif"},
            {"tif", "image/tiff"},
            {"tiff", "image/tiff"},
            {"bmp", "image/bmp"},
            {"svg", "image/svg+xml"},
            {"swf", "application/x-shockwave-flash"},
            {"flv", "video/x-flv"},
            {"pdf", "application/pdf"},
        }; 

        public static RawHttpResponse ServeStaticFiles(HttpRequest request, string urlPrefix, string rootDirectory)
        {
            string root = Path.GetFullPath(rootDirectory);
            string relativeFilePath = Utils.MakeRelativePath(request.GetParameterASCII("DOCUMENT_URI"), urlPrefix);
            string filePath = Path.GetFullPath(Path.Combine(rootDirectory, relativeFilePath));
            
            // No ../ allowed! Make sure only files inside the rootDirectory are server.
            if(!filePath.StartsWith(root) || !File.Exists(filePath))
            {
                return new HttpResponse("<h1>404 Not Found</h1>", status: "404 Not Found");
            }

            // Try to find the content type for this file extension
            var extension = Path.GetExtension(filePath).ToLower();
            extension = extension.Replace(".", "");
            string contentType = null;
            ContentTypesByExtension.TryGetValue(extension, out contentType);

            var rawData = File.ReadAllBytes(filePath);
{'fraction_non_alphanumeric': 0.14014310387367382, 'fraction_numerical': 0.004934616333580064, 'mean_word_length': 2.12326656394453, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2948226', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1065, 'n_words': 248}