/
HttpEnvironmentProxy.Windows.cs
45 lines (36 loc) · 1.55 KB
/
HttpEnvironmentProxy.Windows.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
namespace System.Net.Http
{
internal sealed partial class HttpEnvironmentProxy : IWebProxy
{
public static bool TryCreate([NotNullWhen(true)] out IWebProxy? proxy)
{
// Get environment variables. Protocol specific take precedence over
// general all_*. On Windows, environment variables are case insensitive.
Uri? httpProxy = null;
if (Environment.GetEnvironmentVariable(EnvCGI) == null)
{
httpProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpProxyUC));
}
Uri? httpsProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpsProxyUC));
if (httpProxy == null || httpsProxy == null)
{
Uri? allProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvAllProxyUC));
httpProxy ??= allProxy;
httpsProxy ??= allProxy;
}
// Do not instantiate if nothing is set.
// Caller may pick some other proxy type.
if (httpProxy == null && httpsProxy == null)
{
proxy = null;
return false;
}
string? noProxy = Environment.GetEnvironmentVariable(EnvNoProxyUC);
proxy = new HttpEnvironmentProxy(httpProxy, httpsProxy, noProxy);
return true;
}
}
}