Enabling setting of SOCKS proxy version in .NET
@@ -78,6 +78,7 @@ public class Proxy
private string socksProxyLocation;
private string socksUserName;
private string socksPassword;
+ private int? socksVersion;
private List<string> noProxyAddresses = new List<string>();
/// <summary>
@@ -162,6 +163,11 @@ public Proxy(Dictionary<string, object> settings)
this.SocksPassword = settings["socksPassword"].ToString();
}
+ if (settings.ContainsKey("socksVersion"))
+ {
+ this.SocksVersion = (int)settings["socksVersion"];
+ }
+
if (settings.ContainsKey("autodetect"))
{
this.IsAutoDetect = (bool)settings["autodetect"];
@@ -375,6 +381,38 @@ public string SocksUserName
}
}
+ /// <summary>
+ /// Gets or sets the value of the protocol version for the SOCKS proxy.
+ /// Value can be <see langword="null"/> if not set.
+ /// </summary>
+ [JsonProperty("socksVersion", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore)]
+ public int? SocksVersion
+ {
+ get
+ {
+ return this.socksVersion;
+ }
+
+ set
+ {
+ if (value == null)
+ {
+ this.socksVersion = value;
+ }
+ else
+ {
+ if (value.Value <= 0)
+ {
+ throw new ArgumentException("SocksVersion must be a positive integer");
+ }
+
+ this.VerifyProxyTypeCompatilibily(ProxyKind.Manual);
+ this.proxyKind = ProxyKind.Manual;
+ this.socksVersion = value;
+ }
+ }
+ }
+
/// <summary>
/// Gets or sets the value of password for the SOCKS proxy.
/// </summary>
@@ -491,6 +529,11 @@ public void AddBypassAddresses(IEnumerable<string> addressesToAdd)
if (!string.IsNullOrEmpty(this.socksProxyLocation))
{
+ if (!this.socksVersion.HasValue)
+ {
+ throw new InvalidOperationException("Must have a version value set (usually 4 or 5) when specifying a SOCKS proxy");
+ }
+
string socksAuth = string.Empty;
if (!string.IsNullOrEmpty(this.socksUserName) && !string.IsNullOrEmpty(this.socksPassword))
{
@@ -500,6 +543,7 @@ public void AddBypassAddresses(IEnumerable<string> addressesToAdd)
}
serializedDictionary["socksProxy"] = socksAuth + this.socksProxyLocation;
+ serializedDictionary["socksVersion"] = this.socksVersion.Value;
}
if (this.noProxyAddresses.Count > 0)
