Describes proxy settings to be used with a driver instance.
| 67 | /// Describes proxy settings to be used with a driver instance. |
| 68 | /// </summary> |
| 69 | public class Proxy |
| 70 | { |
| 71 | private ProxyKind proxyKind = ProxyKind.Unspecified; |
| 72 | private bool isAutoDetect; |
| 73 | private string? httpProxyLocation; |
| 74 | private string? proxyAutoConfigUrl; |
| 75 | private string? sslProxyLocation; |
| 76 | private string? socksProxyLocation; |
| 77 | private string? socksUserName; |
| 78 | private string? socksPassword; |
| 79 | private int? socksVersion; |
| 80 | private readonly List<string> noProxyAddresses = new List<string>(); |
| 81 | |
| 82 | /// <summary> |
| 83 | /// Initializes a new instance of the <see cref="Proxy"/> class. |
| 84 | /// </summary> |
| 85 | public Proxy() |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | /// <summary> |
| 90 | /// Initializes a new instance of the <see cref="Proxy"/> class with the given proxy settings. |
| 91 | /// </summary> |
| 92 | /// <param name="settings">A dictionary of settings to use with the proxy.</param> |
| 93 | /// <exception cref="ArgumentNullException">If <paramref name="settings"/> is <see langword="null"/>.</exception> |
| 94 | /// <exception cref="ArgumentException">If The "noProxy" value is a list with a <see langword="null"/> element.</exception> |
| 95 | public Proxy(Dictionary<string, object> settings) |
| 96 | { |
| 97 | if (settings == null) |
| 98 | { |
| 99 | throw new ArgumentNullException(nameof(settings), "settings dictionary cannot be null"); |
| 100 | } |
| 101 | |
| 102 | if (settings.TryGetValue("proxyType", out object? proxyTypeObj) && proxyTypeObj?.ToString() is string proxyType) |
| 103 | { |
| 104 | // Special-case "PAC" since that is the correct serialization. |
| 105 | if (proxyType.Equals("pac", StringComparison.InvariantCultureIgnoreCase)) |
| 106 | { |
| 107 | this.Kind = ProxyKind.ProxyAutoConfigure; |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | ProxyKind rawType = (ProxyKind)Enum.Parse(typeof(ProxyKind), proxyType, ignoreCase: true); |
| 112 | this.Kind = rawType; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (settings.TryGetValue("httpProxy", out object? httpProxyObj) && httpProxyObj?.ToString() is string httpProxy) |
| 117 | { |
| 118 | this.HttpProxy = httpProxy; |
| 119 | } |
| 120 | |
| 121 | if (settings.TryGetValue("noProxy", out object? noProxy) && noProxy != null) |
| 122 | { |
| 123 | List<string> bypassAddresses = new List<string>(); |
| 124 | if (noProxy is string addressesAsString) |
| 125 | { |
| 126 | bypassAddresses.AddRange(addressesAsString.Split(';')); |
nothing calls this directly
no test coverage detected