< Summary

Information
Class: System.Net.Http.Headers.TransferCodingHeaderValue
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\TransferCodingHeaderValue.cs
Line coverage
48%
Covered lines: 40
Uncovered lines: 42
Coverable lines: 82
Total lines: 145
Line coverage: 48.7%
Branch coverage
55%
Covered branches: 11
Total branches: 20
Branch coverage: 55%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%110%
.ctor(...)100%110%
Parse(...)100%110%
TryParse(...)0%220%
GetTransferCodingLength(...)83.33%121293.54%
ToString()100%11100%
Equals(...)0%440%
GetHashCode()100%110%
System.ICloneable.Clone()100%110%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\TransferCodingHeaderValue.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.Collections.Generic;
 5using System.Diagnostics;
 6using System.Diagnostics.CodeAnalysis;
 7using System.IO;
 8using System.Text;
 9
 10namespace System.Net.Http.Headers
 11{
 12    public class TransferCodingHeaderValue : ICloneable
 13    {
 14        // Use UnvalidatedObjectCollection<T> since we may have multiple parameters with the same name.
 15        private UnvalidatedObjectCollection<NameValueHeaderValue>? _parameters;
 1583216        private string _value = null!; // empty constructor only used internally and value set with non null
 17
 018        public string Value => _value;
 19
 658220        public ICollection<NameValueHeaderValue> Parameters => _parameters ??= new UnvalidatedObjectCollection<NameValue
 21
 1583222        internal TransferCodingHeaderValue()
 1583223        {
 1583224        }
 25
 026        protected TransferCodingHeaderValue(TransferCodingHeaderValue source)
 027        {
 028            Debug.Assert(source != null);
 29
 030            _value = source._value;
 031            _parameters = source._parameters.Clone();
 032        }
 33
 034        public TransferCodingHeaderValue(string value)
 035        {
 036            HeaderUtilities.CheckValidToken(value);
 037            _value = value;
 038        }
 39
 40        public static TransferCodingHeaderValue Parse(string input)
 041        {
 042            int index = 0;
 043            return (TransferCodingHeaderValue)TransferCodingHeaderParser.SingleValueParser.ParseValue(
 044                input, null, ref index);
 045        }
 46
 47        public static bool TryParse([NotNullWhen(true)] string? input, [NotNullWhen(true)] out TransferCodingHeaderValue
 048        {
 049            int index = 0;
 050            parsedValue = null;
 51
 052            if (TransferCodingHeaderParser.SingleValueParser.TryParseValue(input, null, ref index, out object? output))
 053            {
 054                parsedValue = (TransferCodingHeaderValue)output!;
 055                return true;
 56            }
 057            return false;
 058        }
 59
 60        internal static int GetTransferCodingLength(string input, int startIndex,
 61            Func<TransferCodingHeaderValue> transferCodingCreator, out TransferCodingHeaderValue? parsedValue)
 1588862        {
 1588863            Debug.Assert(transferCodingCreator != null);
 1588864            Debug.Assert(startIndex >= 0);
 65
 1588866            parsedValue = null;
 67
 1588868            if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
 069            {
 070                return 0;
 71            }
 72
 73            // Caller must remove leading whitespace. If not, we'll return 0.
 1588874            int valueLength = HttpRuleParser.GetTokenLength(input, startIndex);
 75
 1588876            if (valueLength == 0)
 5677            {
 5678                return 0;
 79            }
 80
 1583281            string value = input.Substring(startIndex, valueLength);
 1583282            int current = startIndex + valueLength;
 1583283            current += HttpRuleParser.GetWhitespaceLength(input, current);
 84            TransferCodingHeaderValue transferCodingHeader;
 85
 86            // If we're not done and we have a parameter delimiter, then we have a list of parameters.
 1583287            if ((current < input.Length) && (input[current] == ';'))
 658288            {
 658289                transferCodingHeader = transferCodingCreator();
 658290                transferCodingHeader._value = value;
 91
 658292                current++; // skip delimiter.
 658293                int parameterLength = NameValueHeaderValue.GetNameValueListLength(input, current, ';',
 658294                    (UnvalidatedObjectCollection<NameValueHeaderValue>)transferCodingHeader.Parameters);
 95
 658296                if (parameterLength == 0)
 16497                {
 16498                    return 0;
 99                }
 100
 6418101                parsedValue = transferCodingHeader;
 6418102                return current + parameterLength - startIndex;
 103            }
 104
 105            // We have a transfer coding without parameters.
 9250106            transferCodingHeader = transferCodingCreator();
 9250107            transferCodingHeader._value = value;
 9250108            parsedValue = transferCodingHeader;
 9250109            return current - startIndex;
 15888110        }
 111
 112        public override string ToString()
 21150113        {
 21150114            StringBuilder sb = StringBuilderCache.Acquire();
 21150115            sb.Append(_value);
 21150116            NameValueHeaderValue.ToString(_parameters, ';', true, sb);
 21150117            return StringBuilderCache.GetStringAndRelease(sb);
 21150118        }
 119
 120        public override bool Equals([NotNullWhen(true)] object? obj)
 0121        {
 0122            TransferCodingHeaderValue? other = obj as TransferCodingHeaderValue;
 123
 0124            if (other == null)
 0125            {
 0126                return false;
 127            }
 128
 0129            return string.Equals(_value, other._value, StringComparison.OrdinalIgnoreCase) &&
 0130                HeaderUtilities.AreEqualCollections(_parameters, other._parameters);
 0131        }
 132
 133        public override int GetHashCode()
 0134        {
 135            // The value string is case-insensitive.
 0136            return StringComparer.OrdinalIgnoreCase.GetHashCode(_value) ^ NameValueHeaderValue.GetHashCode(_parameters);
 0137        }
 138
 139        // Implement ICloneable explicitly to allow derived types to "override" the implementation.
 140        object ICloneable.Clone()
 0141        {
 0142            return new TransferCodingHeaderValue(this);
 0143        }
 144    }
 145}