<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Hosting;

namespace AppMetrics.WebUtils
{
	public static class WebUtil
	{
		public static void CheckIpAddress()
		{
			var request = HttpContext.Current.Request;
			if (!request.IsLocal)
			{
				var response = HttpContext.Current.Response;
				response.Write("Access from this IP address is not allowed");
				response.Status = "401 Unauthorized";
				response.StatusCode = 401;
				response.End();
				throw new UnauthorizedAccessException();
			}
		}

		public static string AppDataPath
		{
			get
			{
				var res = ResolvePath("~/App_Data");
				return res;
			}
		}

		public static string ResolvePath(string val)
		{
			if (val.Contains(':')) // an absolute path
				return val;

			if (val.StartsWith("~")) // site path
				return GetWebAppPath() + val.Substring(1);

			if (val.StartsWith(".")) // relative path
				return Path.GetFullPath(GetWebAppPath() + "\\" + val);

			throw new ArgumentException();
		}

		public static void TryEnableCompression(HttpContext context)
		{
			var acceptEncoding = context.Request.Headers["Accept-Encoding"];
			if (!string.IsNullOrEmpty(acceptEncoding))
			{
				acceptEncoding = acceptEncoding.ToLower();

				var response = context.Response;
				var prevUncompressedStream = response.Filter;

				if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
				{
					response.Filter = new DeflateStream(prevUncompressedStream, CompressionMode.Compress);
					response.AppendHeader("Content-Encoding", "deflate");
				}
				else if (acceptEncoding.Contains("gzip"))
				{
					response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress);
					response.AppendHeader("Content-Encoding", "gzip");
				}
			}
		}

		public static string GetWebAppPath()
		{
			var location = Assembly.GetExecutingAssembly().CodeBase;
			location = (new Uri(location)).LocalPath;
			var res = Path.GetDirectoryName(location) + "\\";
			res = Path.GetFullPath(res + "..");
			return res;
		}
	}
}<commit_msg>bugfix<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Hosting;

namespace AppMetrics.WebUtils
{
	public static class WebUtil
	{
		public static void CheckIpAddress()
		{
			var request = HttpContext.Current.Request;
			if (!request.IsLocal)
			{
				var response = HttpContext.Current.Response;
				response.Write("Access from this IP address is not allowed");
				response.Status = "401 Unauthorized";
				response.StatusCode = 401;
				response.End();
				throw new UnauthorizedAccessException();
			}
		}

		public static string AppDataPath
		{
			get
			{
				var res = ResolvePath("~/App_Data");
				return res;
			}
		}

		public static string ResolvePath(string val)
		{
			if (val.Contains(':')) // an absolute path
				return val;

			if (val.StartsWith("~")) // site path
				return Path.GetFullPath(GetWebAppPath() + val.Substring(1));

			if (val.StartsWith(".")) // relative path
				return Path.GetFullPath(GetWebAppPath() + "\\" + val);

			throw new ArgumentException();
		}

		public static void TryEnableCompression(HttpContext context)
		{
			var acceptEncoding = context.Request.Headers["Accept-Encoding"];
			if (!string.IsNullOrEmpty(acceptEncoding))
			{
				acceptEncoding = acceptEncoding.ToLower();

				var response = context.Response;
				var prevUncompressedStream = response.Filter;

				if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
				{
					response.Filter = new DeflateStream(prevUncompressedStream, CompressionMode.Compress);
					response.AppendHeader("Content-Encoding", "deflate");
				}
				else if (acceptEncoding.Contains("gzip"))
				{
					response.Filter = new GZipStream(prevUncompressedStream, CompressionMode.Compress);
					response.AppendHeader("Content-Encoding", "gzip");
				}
			}
		}

		public static string GetWebAppPath()
		{
			var location = Assembly.GetExecutingAssembly().CodeBase;
			location = (new Uri(location)).LocalPath;
			var res = Path.GetDirectoryName(location) + "\\";
			res = Path.GetFullPath(res + "..");
			return res;
		}
	}
}
{'fraction_non_alphanumeric': 0.11905293723475542, 'fraction_numerical': 0.003127094036184945, 'mean_word_length': 3.1309963099630997, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4913360', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1304, 'n_words': 286}