| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using Azure.Core.Pipeline; |
| | 5 | | using Microsoft.Identity.Client; |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using System.Linq; |
| | 9 | | using System.Net.Http; |
| | 10 | | using System.Text; |
| | 11 | | using System.Threading; |
| | 12 | | using System.Threading.Tasks; |
| | 13 | | using Azure.Core; |
| | 14 | |
|
| | 15 | | namespace Azure.Identity |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// This class is an HttpClient factory which creates an HttpClient which delegates it's transport to an HttpPipelin |
| | 19 | | /// </summary> |
| | 20 | | internal class HttpPipelineClientFactory : IMsalHttpClientFactory |
| | 21 | | { |
| | 22 | | private readonly HttpPipeline _pipeline; |
| | 23 | |
|
| 136 | 24 | | public HttpPipelineClientFactory(HttpPipeline pipeline) |
| | 25 | | { |
| 136 | 26 | | _pipeline = pipeline; |
| 136 | 27 | | } |
| | 28 | |
|
| | 29 | | public HttpClient GetHttpClient() |
| | 30 | | { |
| 216 | 31 | | return new HttpClient(new PipelineHttpMessageHandler(_pipeline)); |
| | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// An HttpMessageHandler which delegates SendAsync to a specified HttpPipeline. |
| | 36 | | /// </summary> |
| | 37 | | private class PipelineHttpMessageHandler : HttpMessageHandler |
| | 38 | | { |
| | 39 | | private readonly HttpPipeline _pipeline; |
| | 40 | |
|
| 216 | 41 | | public PipelineHttpMessageHandler(HttpPipeline pipeline) |
| | 42 | | { |
| 216 | 43 | | _pipeline = pipeline; |
| 216 | 44 | | } |
| | 45 | |
|
| | 46 | | protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken c |
| | 47 | | { |
| 216 | 48 | | Request pipelineRequest = await request.ToPipelineRequestAsync(_pipeline).ConfigureAwait(false); |
| | 49 | |
|
| 216 | 50 | | Response pipelineResponse = await _pipeline.SendRequestAsync(pipelineRequest, cancellationToken).Configu |
| | 51 | |
|
| 208 | 52 | | return pipelineResponse.ToHttpResponseMessage(); |
| 208 | 53 | | } |
| | 54 | | } |
| | 55 | | } |
| | 56 | | } |