< Summary

Information
Class: System.Net.Http.Headers.BaseHeaderParser
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\BaseHeaderParser.cs
Line coverage
100%
Covered lines: 34
Uncovered lines: 0
Coverable lines: 34
Total lines: 84
Line coverage: 100%
Branch coverage
100%
Covered branches: 22
Total branches: 22
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
TryParseValue(...)100%2222100%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\BaseHeaderParser.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;
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace System.Net.Http.Headers
 8{
 9    internal abstract class BaseHeaderParser : HttpHeaderParser
 10    {
 11        protected BaseHeaderParser(bool supportsMultipleValues)
 3612            : base(supportsMultipleValues)
 3613        {
 3614        }
 15
 16        /// <summary>
 17        /// Parses a full header or a segment of a multi-value header.
 18        /// </summary>
 19        /// <param name="value">The header value string to parse.</param>
 20        /// <param name="startIndex">The index to begin parsing at.</param>
 21        /// <param name="storeValue"></param>
 22        /// <param name="parsedValue">The resulting value parsed.</param>
 23        /// <returns>If a value could be parsed, the number of characters used to parse that value. Otherwise, 0.</retur
 24        protected abstract int GetParsedValueLength(string value, int startIndex, object? storeValue,
 25            out object? parsedValue);
 26
 27#pragma warning disable CS8765 // Doesn't match overridden member nullable attribute on out parameter
 28        public sealed override bool TryParseValue(string? value, object? storeValue, ref int index,
 29            out object? parsedValue)
 30#pragma warning restore CS8765
 98221931        {
 98221932            parsedValue = null;
 33
 34            // If multiple values are supported (i.e. list of values), then accept an empty string: The header may
 35            // be added multiple times to the request/response message. E.g.
 36            //  Accept: text/xml; q=1
 37            //  Accept:
 38            //  Accept: text/plain; q=0.2
 98221939            if (string.IsNullOrEmpty(value) || (index == value.Length))
 28040            {
 28041                return SupportsMultipleValues;
 42            }
 43
 44            bool separatorFound;
 98193945            int current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(value, index, SupportsMultipleValues,
 98193946                out separatorFound);
 47
 98193948            if (separatorFound && !SupportsMultipleValues)
 249            {
 250                return false; // leading separators not allowed if we don't support multiple values.
 51            }
 52
 98193753            if (current == value.Length)
 13854            {
 13855                if (SupportsMultipleValues)
 13256                {
 13257                    index = current;
 13258                }
 13859                return SupportsMultipleValues;
 60            }
 61
 98179962            int length = GetParsedValueLength(value, current, storeValue, out object? result);
 63
 98179964            if (length == 0)
 1285665            {
 1285666                return false;
 67            }
 68
 96894369            current += length;
 96894370            current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(value, current, SupportsMultipleValues,
 96894371                out separatorFound);
 72
 73            // If we support multiple values and we've not reached the end of the string, then we must have a separator.
 96894374            if ((separatorFound && !SupportsMultipleValues) || (!separatorFound && (current < value.Length)))
 135675            {
 135676                return false;
 77            }
 78
 96758779            index = current;
 96758780            parsedValue = result!;
 96758781            return true;
 98221982        }
 83    }
 84}