< Summary

Class:Azure.Core.HttpHeader
Assembly:Azure.Core
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\HttpHeader.cs
Covered lines:19
Uncovered lines:18
Coverable lines:37
Total lines:170
Line coverage:51.3% (19 of 37)
Covered branches:3
Total branches:6
Branch coverage:50% (3 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-80%50%
get_Name()-100%100%
get_Value()-100%100%
GetHashCode()-100%100%
Equals(...)-0%0%
ToString()-0%100%
Equals(...)-100%100%
get_Date()-100%100%
get_XMsDate()-100%100%
get_ContentType()-100%100%
get_ContentLength()-100%100%
get_ETag()-100%100%
get_XMsRequestId()-100%100%
get_UserAgent()-100%100%
get_Accept()-0%100%
get_Authorization()-100%100%
get_Range()-0%100%
get_XMsRange()-0%100%
get_IfMatch()-0%100%
get_IfNoneMatch()-0%100%
get_IfModifiedSince()-0%100%
get_IfUnmodifiedSince()-0%100%
get_Referer()-0%100%
get_Host()-0%100%
.cctor()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core\src\HttpHeader.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5
 6namespace Azure.Core
 7{
 8    /// <summary>
 9    /// Represents an HTTP header.
 10    /// </summary>
 11    public readonly struct HttpHeader : IEquatable<HttpHeader>
 12    {
 13        /// <summary>
 14        /// Creates a new instance of <see cref="HttpHeader"/> with provided name and value.
 15        /// </summary>
 16        /// <param name="name">The header name.</param>
 17        /// <param name="value">The header value.</param>
 18        public HttpHeader(string name, string value)
 19        {
 1379620            if (string.IsNullOrEmpty(name))
 21            {
 022                throw new ArgumentException($"{nameof(name)} shouldn't be null or empty", nameof(name));
 23            }
 24
 1379625            Name = name;
 1379626            Value = value;
 1379627        }
 28
 29        /// <summary>
 30        /// Gets header name.
 31        /// </summary>
 2671832        public string Name { get; }
 33
 34        /// <summary>
 35        /// Gets header value. If the header has multiple values they would be joined with a comma. To get separate valu
 36        /// </summary>
 1346437        public string Value { get; }
 38
 39        /// <inheritdoc/>
 40        public override int GetHashCode()
 41        {
 442            var hashCode = new HashCodeBuilder();
 443            hashCode.Add(Name, StringComparer.OrdinalIgnoreCase);
 444            hashCode.Add(Value);
 445            return hashCode.ToHashCode();
 46        }
 47
 48        /// <inheritdoc/>
 49        public override bool Equals(object? obj)
 50        {
 051            if (obj is HttpHeader header)
 52            {
 053                return Equals(header);
 54            }
 055            return false;
 56        }
 57
 58        /// <inheritdoc/>
 059        public override string ToString() => $"{Name}:{Value}";
 60
 61        /// <inheritdoc/>
 62        public bool Equals(HttpHeader other)
 63        {
 73464            return string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) && Value.Equals(other.Value, Stri
 65        }
 66
 67#pragma warning disable CA1034 // Nested types should not be visible
 68        /// <summary>
 69        /// Contains names of commonly used headers.
 70        /// </summary>
 71        public static class Names
 72#pragma warning restore CA1034 // Nested types should not be visible
 73        {
 74            /// <summary>
 75            /// Returns. <code>"Date"</code>
 76            /// </summary>
 877            public static string Date => "Date";
 78            /// <summary>
 79            /// Returns. <code>"x-ms-date"</code>
 80            /// </summary>
 481            public static string XMsDate => "x-ms-date";
 82            /// <summary>
 83            /// Returns. <code>"Content-Type"</code>
 84            /// </summary>
 424885            public static string ContentType => "Content-Type";
 86            /// <summary>
 87            /// Returns. <code>"Content-Length"</code>
 88            /// </summary>
 289            public static string ContentLength => "Content-Length";
 90            /// <summary>
 91            /// Returns. <code>"ETag"</code>
 92            /// </summary>
 293            public static string ETag => "ETag";
 94            /// <summary>
 95            /// Returns. <code>"x-ms-request-id"</code>
 96            /// </summary>
 1697            public static string XMsRequestId => "x-ms-request-id";
 98            /// <summary>
 99            /// Returns. <code>"User-Agent"</code>
 100            /// </summary>
 1642101            public static string UserAgent => "User-Agent";
 102            /// <summary>
 103            /// Returns. <code>"Accept"</code>
 104            /// </summary>
 0105            public static string Accept => "Accept";
 106            /// <summary>
 107            /// Returns. <code>"Authorization"</code>
 108            /// </summary>
 520109            public static string Authorization => "Authorization";
 110            /// <summary>
 111            /// Returns. <code>"Range"</code>
 112            /// </summary>
 0113            public static string Range => "Range";
 114            /// <summary>
 115            /// Returns. <code>"x-ms-range"</code>
 116            /// </summary>
 0117            public static string XMsRange => "x-ms-range";
 118            /// <summary>
 119            /// Returns. <code>"If-Match"</code>
 120            /// </summary>
 0121            public static string IfMatch => "If-Match";
 122            /// <summary>
 123            /// Returns. <code>"If-None-Match"</code>
 124            /// </summary>
 0125            public static string IfNoneMatch => "If-None-Match";
 126            /// <summary>
 127            /// Returns. <code>"If-Modified-Since"</code>
 128            /// </summary>
 0129            public static string IfModifiedSince => "If-Modified-Since";
 130            /// <summary>
 131            /// Returns. <code>"If-Unmodified-Since"</code>
 132            /// </summary>
 0133            public static string IfUnmodifiedSince => "If-Unmodified-Since";
 134
 0135            internal static string Referer => "Referer";
 0136            internal static string Host => "Host";
 137        }
 138
 139#pragma warning disable CA1034 // Nested types should not be visible
 140#pragma warning disable CA1724 // Type name conflicts with standard namespace
 141        /// <summary>
 142        /// Commonly defined header values.
 143        /// </summary>
 144        public static class Common
 145#pragma warning restore CA1034 // Nested types should not be visible
 146#pragma warning restore CA1724 // Type name conflicts with standard namespace
 147        {
 148            private const string ApplicationJson = "application/json";
 149            private const string ApplicationOctetStream = "application/octet-stream";
 150            private const string ApplicationFormUrlEncoded = "application/x-www-form-urlencoded";
 151
 152            /// <summary>
 153            /// Returns header with name "ContentType" and value "application/json".
 154            /// </summary>
 0155            public static readonly HttpHeader JsonContentType = new HttpHeader(Names.ContentType, ApplicationJson);
 156            /// <summary>
 157            /// Returns header with name "Accept" and value "application/json".
 158            /// </summary>
 0159            public static readonly HttpHeader JsonAccept = new HttpHeader(Names.Accept, ApplicationJson);
 160            /// <summary>
 161            /// Returns header with name "ContentType" and value "application/octet-stream".
 162            /// </summary>
 0163            public static readonly HttpHeader OctetStreamContentType = new HttpHeader(Names.ContentType, ApplicationOcte
 164            /// <summary>
 165            /// Returns header with name "ContentType" and value "application/x-www-form-urlencoded".
 166            /// </summary>
 0167            public static readonly HttpHeader FormUrlEncodedContentType = new HttpHeader(Names.ContentType, ApplicationF
 168        }
 169    }
 170}