< Summary

Information
Class: System.Net.Http.Headers.CacheControlHeaderParser
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\CacheControlHeaderParser.cs
Line coverage
66%
Covered lines: 20
Uncovered lines: 10
Coverable lines: 30
Total lines: 56
Line coverage: 66.6%
Branch coverage
58%
Covered branches: 7
Total branches: 12
Branch coverage: 58.3%
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(...)58.33%121261.53%

File(s)

D:\runner\runtime\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)
 513425        {
 513426            CacheControlHeaderValue? temp = null;
 513427            bool isInvalidValue = true;
 513428            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
 513441            {
 513442                if (storeValue is not HttpHeaders.InvalidValue)
 513443                {
 513444                    isInvalidValue = false;
 513445                    temp = storeValue as CacheControlHeaderValue;
 513446                }
 513447            }
 513448            Debug.Assert(isInvalidValue || storeValue == null || temp != null, "'storeValue' is not of type CacheControl
 49
 513450            int resultLength = CacheControlHeaderValue.GetCacheControlLength(value, startIndex, temp, out temp);
 51
 513452            parsedValue = temp;
 513453            return resultLength;
 513454        }
 55    }
 56}