< Summary

Class:Azure.Storage.StorageRequestValidationPipelinePolicy
Assembly:Azure.Storage.Blobs
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\StorageRequestValidationPipelinePolicy.cs
Covered lines:8
Uncovered lines:1
Coverable lines:9
Total lines:43
Line coverage:88.8% (8 of 9)
Covered branches:7
Total branches:8
Branch coverage:87.5% (7 of 8)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
OnReceivedResponse(...)-83.33%87.5%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\StorageRequestValidationPipelinePolicy.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Linq;
 6using Azure.Core;
 7using Azure.Core.Pipeline;
 8
 9namespace Azure.Storage
 10{
 11    /// <summary>
 12    /// Pipeline policy to verify x-ms-client-request-id and x-ms-client-return-request-id
 13    /// headers that are echoed back from a request match.
 14    /// </summary>
 15    internal class StorageRequestValidationPipelinePolicy : HttpPipelineSynchronousPolicy
 16    {
 17        private readonly ClientDiagnostics _clientDiagnostics;
 18
 19        /// <summary>
 20        /// Create a new StorageRequestValidationPipelinePolicy
 21        /// </summary>
 474022        public StorageRequestValidationPipelinePolicy(ClientOptions options)
 23        {
 474024            _clientDiagnostics = new ClientDiagnostics(options);
 474025        }
 26
 27        /// <summary>
 28        /// Verify x-ms-client-request-id and x-ms-client-return-request-id headers matches as
 29        /// x-ms-client-return-request-id is an echo of x-mis-client-request-id.
 30        /// </summary>
 31        /// <param name="message">The message that was sent</param>
 32        public override void OnReceivedResponse(HttpMessage message)
 33        {
 2198034            if (message.HasResponse &&
 2198035                message.Request.Headers.TryGetValue(Constants.HeaderNames.ClientRequestId, out var original) &&
 2198036                message.Response.Headers.TryGetValues(Constants.HeaderNames.ClientRequestId, out var echo) &&
 2198037                !String.Equals(original, echo.First(), StringComparison.OrdinalIgnoreCase))
 38            {
 039                throw Errors.ClientRequestIdMismatch(_clientDiagnostics, message.Response, echo.First(), original);
 40            }
 2198041        }
 42    }
 43}

Methods/Properties

.ctor(...)
OnReceivedResponse(...)