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

namespace MiniHttp.Utilities
{
	public class ServerUrlMapper : IUrlMapper
	{
		private readonly DirectoryInfo _webRoot;

		public ServerUrlMapper(DirectoryInfo webRoot)
		{
			_webRoot = webRoot;
		}

		public FileInfo MapUrlToFile(Uri url)
		{
			return new FileInfo(Path.Combine(_webRoot.FullName, url.LocalPath.Substring(1)));
		}

		public DirectoryInfo MapUrlToDirectory(Uri url)
		{
			return new DirectoryInfo(Path.Combine(_webRoot.FullName, url.LocalPath.Substring(1)));
		}

		public Uri MapFileToUrl(FileSystemInfo file, Uri baseUri = null)
		{
			if (!file.FullName.StartsWith(_webRoot.FullName))
				throw new InvalidOperationException("File path must refer to a path in the webroot");

			if (baseUri == null)
				return new Uri(file.FullName.Substring(_webRoot.FullName.Length), UriKind.Relative);

			return new Uri(baseUri, file.FullName.Substring(_webRoot.FullName.Length));
		}
	}
}<commit_msg>- fixed a bug in the server URL mapper resolving the URL of the webroot<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MiniHttp.Utilities
{
	public class ServerUrlMapper : IUrlMapper
	{
		private readonly DirectoryInfo _webRoot;

		public ServerUrlMapper(DirectoryInfo webRoot)
		{
			_webRoot = webRoot;
		}

		public FileInfo MapUrlToFile(Uri url)
		{
			return new FileInfo(Path.Combine(_webRoot.FullName, url.LocalPath.Substring(1)));
		}

		public DirectoryInfo MapUrlToDirectory(Uri url)
		{
			return new DirectoryInfo(Path.Combine(_webRoot.FullName, url.LocalPath.Substring(1)));
		}

		public Uri MapFileToUrl(FileSystemInfo file, Uri baseUri = null)
		{
			if (!file.FullName.StartsWith(_webRoot.FullName))
				throw new InvalidOperationException("File path must refer to a path in the webroot");

            var path = file.FullName.Substring(_webRoot.FullName.Length);
            if (file.Attributes.HasFlag(FileAttributes.Directory))
		        path = String.Format("{0}/", path);

			if (baseUri == null)
                return new Uri(path, UriKind.Relative);

            return new Uri(baseUri, path);
		}
	}
}
{'fraction_non_alphanumeric': 0.09861668897813476, 'fraction_numerical': 0.0022311468094600626, 'mean_word_length': 4.154022988505747, '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': '2545860', 'n_tokens_mistral': 774, 'n_tokens_neox': 687, 'n_words': 168}