|
1 |
| -// <copyright file="Proxy.cs" company="WebDriver Committers"> |
| 1 | +// <copyright file="Proxy.cs" company="WebDriver Committers"> |
2 | 2 | // Licensed to the Software Freedom Conservancy (SFC) under one
|
3 | 3 | // or more contributor license agreements. See the NOTICE file
|
4 | 4 | // distributed with this work for additional information
|
@@ -79,6 +79,7 @@ public class Proxy
|
79 | 79 | private string socksProxyLocation;
|
80 | 80 | private string socksUserName;
|
81 | 81 | private string socksPassword;
|
| 82 | + private List<string> noProxyAddresses = new List<string>(); |
82 | 83 |
|
83 | 84 | /// <summary>
|
84 | 85 | /// Initializes a new instance of the <see cref="Proxy"/> class.
|
@@ -250,19 +251,23 @@ public string HttpProxy
|
250 | 251 | /// <summary>
|
251 | 252 | /// Gets or sets the value for bypass proxy addresses.
|
252 | 253 | /// </summary>
|
| 254 | + [Obsolete("Add addresses to bypass with the proxy by using the AddBypassAddress method.")] |
253 | 255 | [JsonProperty("noProxy", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore)]
|
254 | 256 | public string NoProxy
|
255 | 257 | {
|
256 | 258 | get
|
257 | 259 | {
|
258 |
| - return this.noProxy; |
| 260 | + if (this.noProxyAddresses.Count == 0) |
| 261 | + { |
| 262 | + return null; |
| 263 | + } |
| 264 | + |
| 265 | + return string.Join(";", this.noProxyAddresses); |
259 | 266 | }
|
260 | 267 |
|
261 | 268 | set
|
262 | 269 | {
|
263 |
| - this.VerifyProxyTypeCompatilibily(ProxyKind.Manual); |
264 |
| - this.proxyKind = ProxyKind.Manual; |
265 |
| - this.noProxy = value; |
| 270 | + this.AddBypassAddress(value); |
266 | 271 | }
|
267 | 272 | }
|
268 | 273 |
|
@@ -361,6 +366,104 @@ public string SocksPassword
|
361 | 366 | }
|
362 | 367 | }
|
363 | 368 |
|
| 369 | + /// <summary> |
| 370 | + /// Adds a single address to the list of addresses against which the proxy will not be used. |
| 371 | + /// </summary> |
| 372 | + /// <param name="address">The address to add.</param> |
| 373 | + public void AddBypassAddress(string address) |
| 374 | + { |
| 375 | + if (string.IsNullOrEmpty(address)) |
| 376 | + { |
| 377 | + throw new ArgumentException("address must not be null or empty", "address"); |
| 378 | + } |
| 379 | + |
| 380 | + this.AddBypassAddresses(address); |
| 381 | + } |
| 382 | + |
| 383 | + /// <summary> |
| 384 | + /// Adds addresses to the list of addresses against which the proxy will not be used. |
| 385 | + /// </summary> |
| 386 | + /// <param name="addressesToAdd">An array of addresses to add.</param> |
| 387 | + public void AddBypassAddresses(params string[] addressesToAdd) |
| 388 | + { |
| 389 | + this.AddBypassAddresses(new List<string>(addressesToAdd)); |
| 390 | + } |
| 391 | + |
| 392 | + /// <summary> |
| 393 | + /// Adds addresses to the list of addresses against which the proxy will not be used. |
| 394 | + /// </summary> |
| 395 | + /// <param name="addressesToAdd">An <see cref="IEnumerable{T}"/> object of arguments to add.</param> |
| 396 | + public void AddBypassAddresses(IEnumerable<string> addressesToAdd) |
| 397 | + { |
| 398 | + if (addressesToAdd == null) |
| 399 | + { |
| 400 | + throw new ArgumentNullException("addressesToAdd", "addressesToAdd must not be null"); |
| 401 | + } |
| 402 | + |
| 403 | + this.VerifyProxyTypeCompatilibily(ProxyKind.Manual); |
| 404 | + this.proxyKind = ProxyKind.Manual; |
| 405 | + this.noProxyAddresses.AddRange(addressesToAdd); |
| 406 | + } |
| 407 | + |
| 408 | + /// <summary> |
| 409 | + /// Returns a dictionary suitable for serializing to the W3C Specification |
| 410 | + /// dialect of the wire protocol. |
| 411 | + /// </summary> |
| 412 | + /// <returns>A dictionary suitable for serializing to the W3C Specification |
| 413 | + /// dialect of the wire protocol.</returns> |
| 414 | + internal Dictionary<string, object> ToCapability() |
| 415 | + { |
| 416 | + Dictionary<string, object> serializedDictionary = null; |
| 417 | + if (this.proxyKind != ProxyKind.Unspecified) |
| 418 | + { |
| 419 | + serializedDictionary = new Dictionary<string, object>(); |
| 420 | + if (this.proxyKind == ProxyKind.ProxyAutoConfigure) |
| 421 | + { |
| 422 | + serializedDictionary["proxyType"] = "pac"; |
| 423 | + } |
| 424 | + else |
| 425 | + { |
| 426 | + serializedDictionary["proxyType"] = this.proxyKind.ToString().ToLowerInvariant(); |
| 427 | + } |
| 428 | + |
| 429 | + if (!string.IsNullOrEmpty(this.httpProxyLocation)) |
| 430 | + { |
| 431 | + serializedDictionary["httpProxy"] = this.httpProxyLocation; |
| 432 | + } |
| 433 | + |
| 434 | + if (!string.IsNullOrEmpty(this.sslProxyLocation)) |
| 435 | + { |
| 436 | + serializedDictionary["sslProxy"] = this.sslProxyLocation; |
| 437 | + } |
| 438 | + |
| 439 | + if (!string.IsNullOrEmpty(this.ftpProxyLocation)) |
| 440 | + { |
| 441 | + serializedDictionary["ftpProxy"] = this.ftpProxyLocation; |
| 442 | + } |
| 443 | + |
| 444 | + if (!string.IsNullOrEmpty(this.socksProxyLocation)) |
| 445 | + { |
| 446 | + string socksAuth = string.Empty; |
| 447 | + if (!string.IsNullOrEmpty(this.socksUserName) && !string.IsNullOrEmpty(this.socksPassword)) |
| 448 | + { |
| 449 | + // TODO: this is probably inaccurate as to how this is supposed |
| 450 | + // to look. |
| 451 | + socksAuth = this.socksUserName + ":" + this.socksPassword + "@"; |
| 452 | + } |
| 453 | + |
| 454 | + serializedDictionary["socksProxy"] = socksAuth + this.socksProxyLocation; |
| 455 | + } |
| 456 | + |
| 457 | + if (this.noProxyAddresses.Count > 0) |
| 458 | + { |
| 459 | + List<object> addressList = new List<object>(this.noProxyAddresses); |
| 460 | + serializedDictionary["noProxy"] = addressList; |
| 461 | + } |
| 462 | + } |
| 463 | + |
| 464 | + return serializedDictionary; |
| 465 | + } |
| 466 | + |
364 | 467 | private void VerifyProxyTypeCompatilibily(ProxyKind compatibleProxy)
|
365 | 468 | {
|
366 | 469 | if (this.proxyKind != ProxyKind.Unspecified && this.proxyKind != compatibleProxy)
|
|
0 commit comments