<commit_before>﻿namespace Zone.UmbracoPersonalisationGroups.Criteria.Country
{
    using System.Collections.Generic;
    using System.Web;

    public class HttpContextIpProvider : IIpProvider
    {
        public string GetIp()
        {
            var ip = GetIpFromHttpContext();
            if (ip == "::1")
            {
                ip = "127.0.0.1";
            }

            return ip;
        }

        private string GetIpFromHttpContext()
        {
            var httpContext = HttpContext.Current;
            var variables = GetServerVariablesForPublicIpDetection();

            foreach (var variable in variables)
            {
                if (IsServerVariableForClientIpAvailableAndNotSetToAPrivateIp(httpContext, variable))
                {
                    return httpContext.Request.ServerVariables[variable];
                }
            }

            return string.Empty;
        }

        private IEnumerable<string> GetServerVariablesForPublicIpDetection()
        {
            return new string[]<commit_msg>Adds a check for port number in IP to country lookup<commit_after>﻿namespace Zone.UmbracoPersonalisationGroups.Criteria.Country
{
    using System.Collections.Generic;
    using System.Web;

    public class HttpContextIpProvider : IIpProvider
    {
        public string GetIp()
        {
            var ip = GetIpFromHttpContext();
            if (ip == "::1")
            {
                ip = "127.0.0.1";
            }

            return ip;
        }

        private string GetIpFromHttpContext()
        {
            var httpContext = HttpContext.Current;
            var variables = GetServerVariablesForPublicIpDetection();

            foreach (var variable in variables)
            {
                if (IsServerVariableForClientIpAvailableAndNotSetToAPrivateIp(httpContext, variable))
                {
                    return RemovePortNumberFromIp(httpContext.Request.ServerVariables[variable]);
                }
            }

            return string.Empty;
        }

        private string RemovePortNumberFromIp(string ip)
        {
            if (ip.Contains(":"))
            {
                ip = ip.Substring(0, ip.IndexOf(":"));
            }

            return ip;
        }

        private IEnumerable<string> GetServerVariablesForPublicIpDetection()
        {
            return new string[]
{'fraction_non_alphanumeric': 0.07676174496644295, 'fraction_numerical': 0.006291946308724832, 'mean_word_length': 1.620879120879121, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6649720', 'n_tokens_mistral': 599, 'n_tokens_neox': 565, 'n_words': 120}