< Summary

Information
Class: System.Net.Http.HPack.HeaderField
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\Common\src\System\Net\Http\aspnetcore\Http2\Hpack\HeaderField.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 53
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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(...)100%110%
GetLength(...)100%110%
ToString()0%220%

File(s)

D:\runner\runtime\src\libraries\Common\src\System\Net\Http\aspnetcore\Http2\Hpack\HeaderField.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.Text;
 6
 7namespace System.Net.Http.HPack
 8{
 9    internal readonly struct HeaderField
 10    {
 11        // http://httpwg.org/specs/rfc7541.html#rfc.section.4.1
 12        public const int RfcOverhead = 32;
 13
 14        public HeaderField(int? staticTableIndex, ReadOnlySpan<byte> name, ReadOnlySpan<byte> value)
 015        {
 16            // Store the static table index (if there is one) for the header field.
 17            // ASP.NET Core has a fast path that sets a header value using the static table index instead of the name.
 018            StaticTableIndex = staticTableIndex;
 19
 020            Debug.Assert(name.Length > 0);
 21
 22            // TODO: We're allocating here on every new table entry.
 23            // That means a poorly-behaved server could cause us to allocate repeatedly.
 24            // We should revisit our allocation strategy here so we don't need to allocate per entry
 25            // and we have a cap to how much allocation can happen per dynamic table
 26            // (without limiting the number of table entries a server can provide within the table size limit).
 027            Name = name.ToArray();
 028            Value = value.ToArray();
 029        }
 30
 031        public int? StaticTableIndex { get; }
 32
 033        public byte[] Name { get; }
 34
 035        public byte[] Value { get; }
 36
 037        public int Length => GetLength(Name.Length, Value.Length);
 38
 039        public static int GetLength(int nameLength, int valueLength) => nameLength + valueLength + RfcOverhead;
 40
 41        public override string ToString()
 042        {
 043            if (Name != null)
 044            {
 045                return Encoding.Latin1.GetString(Name) + ": " + Encoding.Latin1.GetString(Value);
 46            }
 47            else
 048            {
 049                return "<empty>";
 50            }
 051        }
 52    }
 53}