< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.HttpRequestMessageProperty
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/Channels/HttpRequestMessageProperty.cs
Line coverage
60%
Covered lines: 14
Uncovered lines: 9
Coverable lines: 23
Total lines: 102
Line coverage: 60.8%
Branch coverage
20%
Covered branches: 2
Total branches: 10
Branch coverage: 20%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
CoreWCF.Channels.IMessageProperty.CreateCopy()100%11100%
.ctor(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/Channels/HttpRequestMessageProperty.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.Net;
 5using CoreWCF.Runtime;
 6using Microsoft.AspNetCore.Http;
 7
 8namespace CoreWCF.Channels
 9{
 10    public sealed class HttpRequestMessageProperty : IMessageProperty
 11    {
 12        private readonly HttpContextBackedProperty _httpContextBackedProperty;
 13
 64814        internal HttpRequestMessageProperty(HttpContext httpContext)
 15        {
 64816            _httpContextBackedProperty = new HttpContextBackedProperty(httpContext);
 64817        }
 18
 19        public const string Name = "httpRequest";
 20
 21        /// <summary>
 22        /// Gets the headers from the underlying HTTP Request.
 23        /// </summary>
 1624        public WebHeaderCollection Headers => _httpContextBackedProperty.Headers;
 25
 26        /// <summary>
 27        /// Gets the method from the underlying HTTP Request.
 28        /// </summary>
 3529        public string Method => _httpContextBackedProperty.Method;
 30
 31        /// <summary>
 32        /// Gets the query string from the underlying HTTP Request.
 33        /// </summary>
 34        /// <remarks>The leading '?' is removed.</remarks>
 035        public string QueryString => _httpContextBackedProperty.QueryString;
 36
 37        /// <summary>
 38        /// The entity body is suppressed is the underlying HTTP request has a zero ContentLength.
 39        /// </summary>
 40        /// <value><c>true</c> if [suppress entity body]; otherwise, <c>false</c>.</value>
 041        public bool SuppressEntityBody => _httpContextBackedProperty.SuppressEntityBody;
 42
 43        IMessageProperty IMessageProperty.CreateCopy()
 44        {
 64845            return this;
 46        }
 47
 48        private class HttpContextBackedProperty
 49        {
 64850            public HttpContextBackedProperty(HttpContext httpContext)
 51            {
 52                Fx.Assert(httpContext != null, "The 'httpResponseMessage' property should never be null.");
 53
 64854                HttpContext = httpContext;
 64855            }
 56
 69657            public HttpContext HttpContext { get; private set; }
 58
 59            private WebHeaderCollection _headers;
 60
 61            public WebHeaderCollection Headers
 62            {
 63                get
 64                {
 1665                    if (_headers == null)
 66                    {
 1367                        _headers = HttpContext.Request.ToWebHeaderCollection();
 68                    }
 69
 1670                    return _headers;
 71                }
 72            }
 73
 3574            public string Method => HttpContext.Request.Method;
 75
 76            public string QueryString
 77            {
 78                get
 79                {
 080                    string query = HttpContext.Request.QueryString.Value;
 081                    return query.Length == 0 ? string.Empty : query.Substring(1);
 82                }
 83            }
 84
 85            public bool SuppressEntityBody
 86            {
 87                get
 88                {
 089                    long? contentLength = HttpContext.Request.ContentLength;
 90
 091                    if (!contentLength.HasValue ||
 092                        (contentLength.HasValue && contentLength.Value > 0))
 93                    {
 094                        return false;
 95                    }
 96
 097                    return true;
 98                }
 99            }
 100        }
 101    }
 102}