-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHttpClientFactory.cs
More file actions
40 lines (33 loc) · 1022 Bytes
/
HttpClientFactory.cs
File metadata and controls
40 lines (33 loc) · 1022 Bytes
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
using DocumentTranslationService.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace DocumentTranslationService
{
public class HttpClientFactory
{
public static HttpClient GetHttpClient()
{
var settings = AppSettingsSetter.Read();
if (settings.UsingProxy == false)
{
return new HttpClient();
}
var proxy = new WebProxy
{
UseDefaultCredentials = settings.ProxyUseDefaultCredentials,
};
if (!string.IsNullOrEmpty(settings.ProxyAddress))
{
proxy.Address = new Uri(settings.ProxyAddress);
}
var httpClientHandler = new HttpClientHandler { Proxy = proxy };
return new HttpClient(handler: httpClientHandler, disposeHandler: true);
}
}
}