<commit_before>﻿// <copyright file="TestHost.cs" company="Fubar Development Junker">
// Copyright (c) <NAME> Junker. All rights reserved.
// </copyright>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;

using FubarDev.WebDavServer.Utils.UAParser;

using Microsoft.AspNetCore.Http;

namespace FubarDev.WebDavServer.Tests.Support
{
    public class TestHost : IWebDavContext
    {
        private readonly Lazy<Uri> _absoluteRequestUrl;

        private readonly Lazy<Uri> _relativeRequestUrl;

        private readonly Lazy<WebDavRequestHeaders> _requestHeaders;

        public TestHost(Uri baseUrl)
        {
            BaseUrl = baseUrl;
            RootUrl = new Uri(baseUrl, "/");
            RequestProtocol = baseUrl.Scheme;
            _absoluteRequestUrl = new Lazy<Uri>(() => RootUrl);
            _relativeRequestUrl = new Lazy<Uri>(() =>
            {
                var requestUrl = RootUrl.MakeRelativeUri(baseUrl);
                if (!requestUrl.OriginalString.StartsWith("/"))
                    return new Uri("/" + requestUrl.OriginalString, UriKind.Relative);
                return requestUrl;
            });
            _requestHeaders = new Lazy<WebDavRequestHeaders>(() => new WebDavRequestHeaders(new List<KeyValuePair<string, IEnumerable<string>>>(), this));
        }

        public TestHost(Uri baseUrl, IHttpContextAccessor httpContextAccessor)
        {
            BaseUrl = baseUrl;
            RootUrl = new Uri(baseUrl, "/");
            RequestProtocol = baseUrl.Scheme;
            _absoluteRequestUrl = new Lazy<Uri>(() => new Uri(RootUrl, httpContextAccessor.HttpContext.Request.Path.ToUriComponent()));
            _relativeRequestUrl = new Lazy<Uri>(() =>
            {
                var requestUrl = httpContextAccessor.HttpContext.Request.Path.ToUriComponent();
                if (!requestUrl.StartsWith("/"))
                    requestUrl = "/" + requestUrl;
                return new Uri(requestUrl, UriKind.Relative);
            });
            _requestHeaders = new Lazy<WebDavRequestHeaders>(() =>
            {
                var request = httpContextAccessor.HttpContext.Request;
                var headerItems = request.Headers.Select(x => new KeyValuePair<string, IEnumerable<string>>(x.Key, x.Value));
                return new WebDavRequestHeaders(headerItems, this);
            });
        }
<commit_msg>Request protocol is always HTTP/1.1 in a test environment<commit_after>﻿// <copyright file="TestHost.cs" company="Fubar Development Junker">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;

using FubarDev.WebDavServer.Utils.UAParser;

using Microsoft.AspNetCore.Http;

namespace FubarDev.WebDavServer.Tests.Support
{
    public class TestHost : IWebDavContext
    {
        private readonly Lazy<Uri> _absoluteRequestUrl;

        private readonly Lazy<Uri> _relativeRequestUrl;

        private readonly Lazy<WebDavRequestHeaders> _requestHeaders;

        public TestHost(Uri baseUrl)
        {
            BaseUrl = baseUrl;
            RootUrl = new Uri(baseUrl, "/");
            RequestProtocol = "HTTP/1.1";
            _absoluteRequestUrl = new Lazy<Uri>(() => RootUrl);
            _relativeRequestUrl = new Lazy<Uri>(() =>
            {
                var requestUrl = RootUrl.MakeRelativeUri(baseUrl);
                if (!requestUrl.OriginalString.StartsWith("/"))
                    return new Uri("/" + requestUrl.OriginalString, UriKind.Relative);
                return requestUrl;
            });
            _requestHeaders = new Lazy<WebDavRequestHeaders>(() => new WebDavRequestHeaders(new List<KeyValuePair<string, IEnumerable<string>>>(), this));
        }

        public TestHost(Uri baseUrl, IHttpContextAccessor httpContextAccessor)
        {
            BaseUrl = baseUrl;
            RootUrl = new Uri(baseUrl, "/");
            RequestProtocol = "HTTP/1.1";
            _absoluteRequestUrl = new Lazy<Uri>(() => new Uri(RootUrl, httpContextAccessor.HttpContext.Request.Path.ToUriComponent()));
            _relativeRequestUrl = new Lazy<Uri>(() =>
            {
                var requestUrl = httpContextAccessor.HttpContext.Request.Path.ToUriComponent();
                if (!requestUrl.StartsWith("/"))
                    requestUrl = "/" + requestUrl;
                return new Uri(requestUrl, UriKind.Relative);
            });
            _requestHeaders = new Lazy<WebDavRequestHeaders>(() =>
            {
                var request = httpContextAccessor.HttpContext.Request;
                var headerItems = request.Headers.Select(x => new KeyValuePair<string, IEnumerable<string>>(x.Key, x.Value));
                return new WebDavRequestHeaders(headerItems, this);
            });
        }

{'fraction_non_alphanumeric': 0.10862881738061078, 'fraction_numerical': 0.0012297601967616314, 'mean_word_length': 2.388888888888889, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6099217', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1256, 'n_words': 267}