This repository was archived by the owner on Dec 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathServiceFacadeHttpClientProvider.cs
More file actions
47 lines (39 loc) · 1.61 KB
/
ServiceFacadeHttpClientProvider.cs
File metadata and controls
47 lines (39 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace LoRaWan.NetworkServer
{
using LoRaTools.CommonAPI;
using LoRaWan.Shared;
using System;
using System.Net;
using System.Net.Http;
/// <summary>
/// Default implementation for <see cref="IServiceFacadeHttpClientProvider"/>.
/// </summary>
public class ServiceFacadeHttpClientProvider : IServiceFacadeHttpClientProvider
{
private readonly NetworkServerConfiguration configuration;
private readonly ApiVersion expectedFunctionVersion;
private readonly Lazy<HttpClient> httpClient;
public ServiceFacadeHttpClientProvider(NetworkServerConfiguration configuration, ApiVersion expectedFunctionVersion)
{
this.configuration = configuration;
this.expectedFunctionVersion = expectedFunctionVersion;
this.httpClient = new Lazy<HttpClient>(this.CreateHttpClient);
}
public HttpClient GetHttpClient() => this.httpClient.Value;
HttpClient CreateHttpClient()
{
using var handler = new ServiceFacadeHttpClientHandler(this.expectedFunctionVersion);
if (!string.IsNullOrEmpty(this.configuration.HttpsProxy))
{
var webProxy = new WebProxy(
new Uri(this.configuration.HttpsProxy),
BypassOnLocal: false);
handler.Proxy = webProxy;
handler.UseProxy = true;
}
return new HttpClient(handler);
}
}
}