-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#423 Users will have to create new ProxyConfig object to configure a …
…Proxy
- Loading branch information
Showing
16 changed files
with
2,001 additions
and
763 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Net; | ||
|
||
namespace Tweetinvi | ||
{ | ||
public interface IProxyConfig : IWebProxy | ||
{ | ||
Uri Address { get; } | ||
} | ||
|
||
public class ProxyConfig : IProxyConfig | ||
{ | ||
private Uri _proxyAddress; | ||
private NetworkCredential _networkCredentials; | ||
|
||
public ProxyConfig(Uri proxyAddress, NetworkCredential credentials = null) | ||
{ | ||
_proxyAddress = proxyAddress; | ||
Credentials = credentials; | ||
} | ||
|
||
public ProxyConfig(string url, NetworkCredential credentials = null) : this(new Uri(url), credentials) | ||
{ | ||
} | ||
|
||
public ProxyConfig(IProxyConfig proxyConfig) | ||
{ | ||
if (proxyConfig != null) | ||
{ | ||
_proxyAddress = proxyConfig.Address; | ||
|
||
var networkCredentials = proxyConfig.Credentials as NetworkCredential; | ||
if (networkCredentials != null) | ||
{ | ||
Credentials = new NetworkCredential(networkCredentials.UserName, networkCredentials.Password, networkCredentials.Domain); | ||
} | ||
} | ||
} | ||
|
||
public ICredentials Credentials | ||
{ | ||
get { return _networkCredentials; } | ||
set | ||
{ | ||
var isCompatibleWithTweetinvi = value == null || value is NetworkCredential; | ||
if (!isCompatibleWithTweetinvi) | ||
{ | ||
throw new Exception("Tweetinvi proxy credentials can only use System.Net.NetworkCredential"); | ||
} | ||
|
||
_networkCredentials = (NetworkCredential)value; | ||
} | ||
} | ||
|
||
public Uri Address | ||
{ | ||
get { return _proxyAddress; } | ||
} | ||
|
||
public Uri GetProxy(Uri destination) | ||
{ | ||
return _proxyAddress; | ||
} | ||
|
||
public bool IsBypassed(Uri host) | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.