| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. See License.txt in the project root for license information. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Threading.Tasks; |
| | 6 | | using System.Net.Http; |
| | 7 | | using System.Threading; |
| | 8 | |
|
| | 9 | | namespace KeyVault.TestFramework |
| | 10 | | { |
| | 11 | | public class TestHttpMessageHandler : DelegatingHandler |
| | 12 | | { |
| | 13 | | protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, |
| | 14 | | CancellationToken cancellationToken) |
| | 15 | | { |
| 4 | 16 | | var requestUri = request.RequestUri; |
| 4 | 17 | | var authority = string.Empty; |
| 4 | 18 | | var targetUri = requestUri; |
| | 19 | |
|
| | 20 | | // NOTE: The KmsNetworkUrl setting is purely for development testing on the |
| | 21 | | // Microsoft Azure Development Fabric and should not be used outside that environment. |
| 4 | 22 | | string networkUrl = TestConfigurationManager.TryGetEnvironmentOrAppSetting("KmsNetworkUrl"); |
| | 23 | |
|
| 4 | 24 | | if (!string.IsNullOrEmpty(networkUrl)) |
| | 25 | | { |
| 0 | 26 | | authority = targetUri.Authority; |
| 0 | 27 | | targetUri = new Uri(new Uri(networkUrl), targetUri.PathAndQuery); |
| | 28 | |
|
| 0 | 29 | | request.Headers.Add("Host", authority); |
| 0 | 30 | | request.RequestUri = targetUri; |
| | 31 | | } |
| | 32 | |
|
| 4 | 33 | | return base.SendAsync(request, cancellationToken).ContinueWith<HttpResponseMessage>(response => |
| 4 | 34 | | { |
| 8 | 35 | | return response.Result; |
| 4 | 36 | | }); |
| | 37 | | } |
| | 38 | |
|
| | 39 | | } |
| | 40 | | } |