Allow users to opt-in to proxies (#888)

* Allow users to opt-in to proxies

* Allow opting in to proxies on the WebSocket
This commit is contained in:
Christopher F
2017-12-07 16:47:01 -05:00
committed by GitHub
parent 39b5d0e74c
commit 678a7238e6
4 changed files with 36 additions and 22 deletions

View File

@@ -22,7 +22,7 @@ namespace Discord.Net.Rest
private CancellationToken _cancelToken;
private bool _isDisposed;
public DefaultRestClient(string baseUrl)
public DefaultRestClient(string baseUrl, bool useProxy = false)
{
_baseUrl = baseUrl;
@@ -30,7 +30,7 @@ namespace Discord.Net.Rest
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
UseCookies = false,
UseProxy = false
UseProxy = useProxy,
});
SetHeader("accept-encoding", "gzip, deflate");

View File

@@ -4,16 +4,21 @@ namespace Discord.Net.Rest
{
public static class DefaultRestClientProvider
{
public static readonly RestClientProvider Instance = url =>
public static readonly RestClientProvider Instance = Create();
public static RestClientProvider Create(bool useProxy = false)
{
try
return url =>
{
return new DefaultRestClient(url);
}
catch (PlatformNotSupportedException ex)
{
throw new PlatformNotSupportedException("The default RestClientProvider is not supported on this platform.", ex);
}
};
try
{
return new DefaultRestClient(url, useProxy);
}
catch (PlatformNotSupportedException ex)
{
throw new PlatformNotSupportedException("The default RestClientProvider is not supported on this platform.", ex);
}
};
}
}
}