<commit_before>﻿// ==========================================================================
//  Squidex Headless CMS
// ==========================================================================
//  Copyright (c) Squidex UG (haftungsbeschraenkt)
//  All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;

namespace Squidex.Pipeline
{
    public class CleanupHostMiddleware
    {
        private readonly RequestDelegate next;

        public CleanupHostMiddleware(RequestDelegate next)
        {
            this.next = next;
        }

        public Task Invoke(HttpContext context)
        {
            var request = context.Request;

            if (request.Host.HasValue && (HasHttpsPort(request) || HasHttpPort(request)))
            {
                request.Host = new HostString(request.Host.Host);
            }

            return next(context);
        }

        private static bool HasHttpPort(HttpRequest request)
        {
            return request.Protocol == "http" && request.Host.Port == 80;
        }

        private static bool HasHttpsPort(HttpRequest request)
        {
            return request.Protocol == "https" && request.Host.Port == 443;
        }
    }
}<commit_msg>Fix host cleaner.<commit_after>﻿// ==========================================================================
//  Squidex Headless CMS
// ==========================================================================
//  Copyright (c) Squidex UG (haftungsbeschraenkt)
//  All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;

namespace Squidex.Pipeline
{
    public class CleanupHostMiddleware
    {
        private readonly RequestDelegate next;

        public CleanupHostMiddleware(RequestDelegate next)
        {
            this.next = next;
        }

        public Task Invoke(HttpContext context)
        {
            var request = context.Request;

            if (request.Host.HasValue && (HasHttpsPort(request) || HasHttpPort(request)))
            {
                request.Host = new HostString(request.Host.Host);
            }

            return next(context);
        }

        private static bool HasHttpPort(HttpRequest request)
        {
            return request.Scheme == "http" && request.Host.Port == 80;
        }

        private static bool HasHttpsPort(HttpRequest request)
        {
            return request.Scheme == "https" && request.Host.Port == 443;
        }
    }
}
{'fraction_non_alphanumeric': 0.2442379182156134, 'fraction_numerical': 0.0037174721189591076, 'mean_word_length': 2.578457446808511, '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': '3945510', 'n_tokens_mistral': 668, 'n_tokens_neox': 613, 'n_words': 144}