< Summary

Information
Class: System.Net.Http.HttpAuthority
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpAuthority.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 34
Coverable lines: 34
Total lines: 70
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%220%
Equals(...)0%440%
Equals(...)0%220%
GetHashCode()100%110%
ToString()0%220%
op_Equality(...)0%220%
op_Inequality(...)100%110%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpAuthority.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace System.Net.Http
 8{
 9
 10    internal sealed class HttpAuthority : IEquatable<HttpAuthority>
 11    {
 12        // ALPN Protocol Name should also be part of an authority, but we are special-casing for HTTP/3, so this can be 
 13        // public string AlpnProtocolName { get; }
 14
 015        public string IdnHost { get; }
 016        public string HostValue { get; }
 017        public int Port { get; }
 18
 019        public HttpAuthority(string host, int port)
 020        {
 021            Debug.Assert(host != null);
 22
 23            // This is very rarely called, but could be optimized to avoid the URI-specific stuff by bringing in DomainN
 024            var builder = new UriBuilder(Uri.UriSchemeHttp, host, port);
 025            Uri uri = builder.Uri;
 26
 027            if (uri.HostNameType == UriHostNameType.IPv6)
 028            {
 29                // This includes brackets for IPv6 and ScopeId for IPv6 LLA so Connect works.
 030                IdnHost = $"[{uri.IdnHost}]";
 31                // This is bracket enclosed IPv6 without ScopeID for LLA
 032                HostValue = uri.Host;
 033            }
 34            else
 035            {
 36                // IPv4 address, dns or puny encoded name
 037                HostValue = IdnHost = uri.IdnHost;
 038            }
 039            Port = port;
 040        }
 41
 42        public bool Equals([NotNullWhen(true)] HttpAuthority? other)
 043        {
 044            return other != null && string.Equals(IdnHost, other.IdnHost) && Port == other.Port;
 045        }
 46
 47        public override bool Equals([NotNullWhen(true)] object? obj)
 048        {
 049            return obj is HttpAuthority other && Equals(other);
 050        }
 51
 52        public override int GetHashCode()
 053        {
 054            return HashCode.Combine(IdnHost, Port);
 055        }
 56
 57        // For diagnostics
 58        public override string ToString()
 059        {
 060            return IdnHost != null ? $"{IdnHost}:{Port}" : "<empty>";
 061        }
 62
 63        public static bool operator ==(HttpAuthority? left, HttpAuthority? right)
 064        {
 065            return left is null ? right is null : left.Equals(right);
 066        }
 67        public static bool operator !=(HttpAuthority? left, HttpAuthority? right)
 068            => !(left == right);
 69    }
 70}