< Summary

Line coverage
66%
Covered lines: 20
Uncovered lines: 10
Coverable lines: 30
Total lines: 57
Line coverage: 66.6%
Branch coverage
50%
Covered branches: 6
Total branches: 12
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor()100%11100%
GetParsedValueLength(...)50%121261.53%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderParser.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;
 6
 7namespace System.Net.Http.Headers
 8{
 9    internal sealed class CacheControlHeaderParser : BaseHeaderParser
 10    {
 111        internal static readonly CacheControlHeaderParser Parser = new CacheControlHeaderParser();
 12
 13        // The Cache-Control header is special: It is a header supporting a list of values, but we represent the list
 14        // as _one_ instance of CacheControlHeaderValue. I.e we set 'SupportsMultipleValues' to 'true' since it is
 15        // OK to have multiple Cache-Control headers in a request/response message. However, after parsing all
 16        // Cache-Control headers, only one instance of CacheControlHeaderValue is created (if all headers contain valid
 17        // values, otherwise we may have multiple strings containing the invalid values).
 18        private CacheControlHeaderParser()
 119            : base(true)
 120        {
 121        }
 22
 23        protected override int GetParsedValueLength(string value, int startIndex, object? storeValue,
 24            out object? parsedValue)
 156825        {
 156826            CacheControlHeaderValue? temp = null;
 156827            bool isInvalidValue = true;
 156828            if (storeValue is List<object> list)
 029            {
 030                foreach (object item in list)
 031                {
 032                    if (item is not HttpHeaders.InvalidValue)
 033                    {
 034                        isInvalidValue = false;
 035                        temp = item as CacheControlHeaderValue;
 036                        break;
 37                    }
 038                }
 039            }
 40            else
 156841            {
 156842                if (storeValue is not HttpHeaders.InvalidValue)
 156843                {
 156844                    isInvalidValue = false;
 156845                    temp = storeValue as CacheControlHeaderValue;
 156846                }
 156847            }
 156848            Debug.Assert(isInvalidValue || storeValue == null || temp != null, "'storeValue' is not of type CacheControl
 49
 156850            int resultLength = CacheControlHeaderValue.GetCacheControlLength(value, startIndex, temp, out temp);
 51
 156852            parsedValue = temp;
 156853            return resultLength;
 156854        }
 55    }
 56}
 57