Browse Source

Allow users to opt-in to proxies

pull/888/head
Christopher F 7 years ago
parent
commit
eb285d09aa
2 changed files with 16 additions and 11 deletions
  1. +2
    -2
      src/Discord.Net.Rest/Net/DefaultRestClient.cs
  2. +14
    -9
      src/Discord.Net.Rest/Net/DefaultRestClientProvider.cs

+ 2
- 2
src/Discord.Net.Rest/Net/DefaultRestClient.cs View File

@@ -22,7 +22,7 @@ namespace Discord.Net.Rest
private CancellationToken _cancelToken; private CancellationToken _cancelToken;
private bool _isDisposed; private bool _isDisposed;


public DefaultRestClient(string baseUrl)
public DefaultRestClient(string baseUrl, bool useProxy = false)
{ {
_baseUrl = baseUrl; _baseUrl = baseUrl;


@@ -30,7 +30,7 @@ namespace Discord.Net.Rest
{ {
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
UseCookies = false, UseCookies = false,
UseProxy = false
UseProxy = useProxy,
}); });
SetHeader("accept-encoding", "gzip, deflate"); SetHeader("accept-encoding", "gzip, deflate");




+ 14
- 9
src/Discord.Net.Rest/Net/DefaultRestClientProvider.cs View File

@@ -4,16 +4,21 @@ namespace Discord.Net.Rest
{ {
public static class DefaultRestClientProvider 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 new DefaultRestClient(url);
}
catch (PlatformNotSupportedException ex)
return url =>
{ {
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);
}
};
}
} }
} }

Loading…
Cancel
Save