< Summary

Information
Class: System.Net.Http.Headers.HttpResponseHeaders
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\HttpResponseHeaders.cs
Line coverage
16%
Covered lines: 9
Uncovered lines: 47
Coverable lines: 56
Total lines: 172
Line coverage: 16%
Branch coverage
14%
Covered branches: 2
Total branches: 14
Branch coverage: 14.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetSpecializedCollection(...)0%440%
.ctor(...)50%22100%
AddHeaders(...)0%220%
IsAllowedHeaderName(...)25%4450%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\Headers\HttpResponseHeaders.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;
 5
 6namespace System.Net.Http.Headers
 7{
 8    public sealed class HttpResponseHeaders : HttpHeaders
 9    {
 10        private const int AcceptRangesSlot = 0;
 11        private const int ProxyAuthenticateSlot = 1;
 12        private const int ServerSlot = 2;
 13        private const int VarySlot = 3;
 14        private const int WwwAuthenticateSlot = 4;
 15        private const int NumCollectionsSlots = 5;
 16
 17        private object[]? _specialCollectionsSlots;
 18        private HttpGeneralHeaders? _generalHeaders;
 19        private readonly bool _containsTrailingHeaders;
 20
 21        #region Response Headers
 22
 23        private T GetSpecializedCollection<T>(int slot, Func<HttpResponseHeaders, T> creationFunc)
 024        {
 25            // 5 properties each lazily allocate a collection to store the value(s) for that property.
 26            // Rather than having a field for each of these, store them untyped in an array that's lazily
 27            // allocated.  Then we only pay for the 45 bytes for those fields when any is actually accessed.
 028            object[] collections = _specialCollectionsSlots ??= new object[NumCollectionsSlots];
 029            return (T)(collections[slot] ??= creationFunc(this)!);
 030        }
 31
 32        public HttpHeaderValueCollection<string> AcceptRanges =>
 033            GetSpecializedCollection(AcceptRangesSlot, static thisRef => new HttpHeaderValueCollection<string>(KnownHead
 34
 35        public TimeSpan? Age
 36        {
 037            get { return HeaderUtilities.GetTimeSpanValue(KnownHeaders.Age.Descriptor, this); }
 038            set { SetOrRemoveParsedValue(KnownHeaders.Age.Descriptor, value); }
 39        }
 40
 41        public EntityTagHeaderValue? ETag
 42        {
 043            get { return (EntityTagHeaderValue?)GetSingleParsedValue(KnownHeaders.ETag.Descriptor); }
 044            set { SetOrRemoveParsedValue(KnownHeaders.ETag.Descriptor, value); }
 45        }
 46
 47        public Uri? Location
 48        {
 049            get { return (Uri?)GetSingleParsedValue(KnownHeaders.Location.Descriptor); }
 050            set { SetOrRemoveParsedValue(KnownHeaders.Location.Descriptor, value); }
 51        }
 52
 53        public HttpHeaderValueCollection<AuthenticationHeaderValue> ProxyAuthenticate =>
 054            GetSpecializedCollection(ProxyAuthenticateSlot, static thisRef => new HttpHeaderValueCollection<Authenticati
 55
 56        public RetryConditionHeaderValue? RetryAfter
 57        {
 058            get { return (RetryConditionHeaderValue?)GetSingleParsedValue(KnownHeaders.RetryAfter.Descriptor); }
 059            set { SetOrRemoveParsedValue(KnownHeaders.RetryAfter.Descriptor, value); }
 60        }
 61
 62        public HttpHeaderValueCollection<ProductInfoHeaderValue> Server =>
 063            GetSpecializedCollection(ServerSlot, static thisRef => new HttpHeaderValueCollection<ProductInfoHeaderValue>
 64
 65        public HttpHeaderValueCollection<string> Vary =>
 066            GetSpecializedCollection(VarySlot, static thisRef => new HttpHeaderValueCollection<string>(KnownHeaders.Vary
 67
 68        public HttpHeaderValueCollection<AuthenticationHeaderValue> WwwAuthenticate =>
 069            GetSpecializedCollection(WwwAuthenticateSlot, static thisRef => new HttpHeaderValueCollection<Authentication
 70
 71        #endregion
 72
 73        #region General Headers
 74
 75        public CacheControlHeaderValue? CacheControl
 76        {
 077            get { return GeneralHeaders.CacheControl; }
 078            set { GeneralHeaders.CacheControl = value; }
 79        }
 80
 81        public HttpHeaderValueCollection<string> Connection
 82        {
 083            get { return GeneralHeaders.Connection; }
 84        }
 85
 86        public bool? ConnectionClose
 87        {
 088            get { return HttpGeneralHeaders.GetConnectionClose(this, _generalHeaders); } // special-cased to avoid forci
 089            set { GeneralHeaders.ConnectionClose = value; }
 90        }
 91
 92        public DateTimeOffset? Date
 93        {
 094            get { return GeneralHeaders.Date; }
 095            set { GeneralHeaders.Date = value; }
 96        }
 97
 98        public HttpHeaderValueCollection<NameValueHeaderValue> Pragma
 99        {
 0100            get { return GeneralHeaders.Pragma; }
 101        }
 102
 103        public HttpHeaderValueCollection<string> Trailer
 104        {
 0105            get { return GeneralHeaders.Trailer; }
 106        }
 107
 108        public HttpHeaderValueCollection<TransferCodingHeaderValue> TransferEncoding
 109        {
 0110            get { return GeneralHeaders.TransferEncoding; }
 111        }
 112
 113        public bool? TransferEncodingChunked
 114        {
 0115            get { return HttpGeneralHeaders.GetTransferEncodingChunked(this, _generalHeaders); } // special-cased to avo
 0116            set { GeneralHeaders.TransferEncodingChunked = value; }
 117        }
 118
 119        public HttpHeaderValueCollection<ProductHeaderValue> Upgrade
 120        {
 0121            get { return GeneralHeaders.Upgrade; }
 122        }
 123
 124        public HttpHeaderValueCollection<ViaHeaderValue> Via
 125        {
 0126            get { return GeneralHeaders.Via; }
 127        }
 128
 129        public HttpHeaderValueCollection<WarningHeaderValue> Warning
 130        {
 0131            get { return GeneralHeaders.Warning; }
 132        }
 133
 134        #endregion
 135
 136        internal HttpResponseHeaders(bool containsTrailingHeaders = false)
 1137            : base(containsTrailingHeaders ? HttpHeaderType.All ^ HttpHeaderType.Request : HttpHeaderType.General | Http
 1138                  HttpHeaderType.Request)
 1139        {
 1140            _containsTrailingHeaders = containsTrailingHeaders;
 1141        }
 142
 0143        internal bool ContainsTrailingHeaders => _containsTrailingHeaders;
 144
 145        internal override void AddHeaders(HttpHeaders sourceHeaders)
 0146        {
 0147            base.AddHeaders(sourceHeaders);
 0148            HttpResponseHeaders? sourceResponseHeaders = sourceHeaders as HttpResponseHeaders;
 0149            Debug.Assert(sourceResponseHeaders != null);
 150
 151            // Copy special values, but do not overwrite
 0152            if (sourceResponseHeaders._generalHeaders != null)
 0153            {
 0154                GeneralHeaders.AddSpecialsFrom(sourceResponseHeaders._generalHeaders);
 0155            }
 0156        }
 157
 158        internal override bool IsAllowedHeaderName(HeaderDescriptor descriptor)
 19123159        {
 19123160            if (!_containsTrailingHeaders)
 19123161                return true;
 162
 0163            KnownHeader? knownHeader = KnownHeaders.TryGetKnownHeader(descriptor.Name);
 0164            if (knownHeader == null)
 0165                return true;
 166
 0167            return (knownHeader.HeaderType & HttpHeaderType.NonTrailing) == 0;
 19123168        }
 169
 0170        private HttpGeneralHeaders GeneralHeaders => _generalHeaders ??= new HttpGeneralHeaders(this);
 171    }
 172}