< Summary

Information
Class: System.Net.Http.DelegatingHandler
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\DelegatingHandler.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 50
Coverable lines: 50
Total lines: 99
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
.ctor(...)100%110%
Send(...)100%110%
SendAsync(...)100%110%
Dispose(...)0%660%
CheckDisposedOrStarted()0%220%
SetOperationStarted()0%440%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\DelegatingHandler.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.Collections.Generic;
 6using System.Diagnostics.CodeAnalysis;
 7using System.Text;
 8using System.Threading;
 9using System.Threading.Tasks;
 10
 11namespace System.Net.Http
 12{
 13    public abstract class DelegatingHandler : HttpMessageHandler
 14    {
 15        private HttpMessageHandler? _innerHandler;
 16        private volatile bool _operationStarted;
 17        private volatile bool _disposed;
 18
 19        [DisallowNull]
 20        public HttpMessageHandler? InnerHandler
 21        {
 22            get
 023            {
 024                return _innerHandler;
 025            }
 26            set
 027            {
 028                ArgumentNullException.ThrowIfNull(value);
 029                CheckDisposedOrStarted();
 30
 031                if (NetEventSource.Log.IsEnabled()) NetEventSource.Associate(this, value);
 032                _innerHandler = value;
 033            }
 34        }
 35
 036        protected DelegatingHandler()
 037        {
 038        }
 39
 040        protected DelegatingHandler(HttpMessageHandler innerHandler)
 041        {
 042            InnerHandler = innerHandler;
 043        }
 44
 45        protected internal override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationT
 046        {
 047            ArgumentNullException.ThrowIfNull(request);
 48
 049            SetOperationStarted();
 050            return _innerHandler!.Send(request, cancellationToken);
 051        }
 52
 53        protected internal override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ca
 054        {
 055            ArgumentNullException.ThrowIfNull(request);
 56
 057            SetOperationStarted();
 058            return _innerHandler!.SendAsync(request, cancellationToken);
 059        }
 60
 61        protected override void Dispose(bool disposing)
 062        {
 063            if (disposing && !_disposed)
 064            {
 065                _disposed = true;
 066                _innerHandler?.Dispose();
 067            }
 68
 069            base.Dispose(disposing);
 070        }
 71
 72        private void CheckDisposedOrStarted()
 073        {
 074            ObjectDisposedException.ThrowIf(_disposed, this);
 75
 076            if (_operationStarted)
 077            {
 078                throw new InvalidOperationException(SR.net_http_operation_started);
 79            }
 080        }
 81
 82        private void SetOperationStarted()
 083        {
 084            ObjectDisposedException.ThrowIf(_disposed, this);
 85
 086            if (_innerHandler == null)
 087            {
 088                throw new InvalidOperationException(SR.net_http_handler_not_assigned);
 89            }
 90            // This method flags the handler instances as "active". I.e. we executed at least one request (or are
 91            // in the process of doing so). This information is used to lock-down all property setters. Once a
 92            // Send/SendAsync operation started, no property can be changed.
 093            if (!_operationStarted)
 094            {
 095                _operationStarted = true;
 096            }
 097        }
 98    }
 99}