Fix the proxy support for aiohttp>=1.4.
This commit is contained in:
parent
eb673ec2af
commit
0d21e83b7f
@ -80,8 +80,11 @@ class Client:
|
|||||||
The `event loop`_ to use for asynchronous operations. Defaults to ``None``,
|
The `event loop`_ to use for asynchronous operations. Defaults to ``None``,
|
||||||
in which case the default event loop is used via ``asyncio.get_event_loop()``.
|
in which case the default event loop is used via ``asyncio.get_event_loop()``.
|
||||||
connector : aiohttp.BaseConnector
|
connector : aiohttp.BaseConnector
|
||||||
The `connector`_ to use for connection pooling. Useful for proxies, e.g.
|
The `connector`_ to use for connection pooling.
|
||||||
with a `ProxyConnector`_.
|
proxy : Optional[str]
|
||||||
|
Proxy URL.
|
||||||
|
proxy_auth : Optional[aiohttp.BasicAuth]
|
||||||
|
An object that represents proxy HTTP Basic Authorization.
|
||||||
shard_id : Optional[int]
|
shard_id : Optional[int]
|
||||||
Integer starting at 0 and less than shard_count.
|
Integer starting at 0 and less than shard_count.
|
||||||
shard_count : Optional[int]
|
shard_count : Optional[int]
|
||||||
@ -116,7 +119,9 @@ class Client:
|
|||||||
self.shard_count = options.get('shard_count')
|
self.shard_count = options.get('shard_count')
|
||||||
|
|
||||||
connector = options.pop('connector', None)
|
connector = options.pop('connector', None)
|
||||||
self.http = HTTPClient(connector, loop=self.loop)
|
proxy = options.pop('proxy', None)
|
||||||
|
proxy_auth = options.pop('proxy_auth', None)
|
||||||
|
self.http = HTTPClient(connector, proxy=proxy, proxy_auth=proxy_auth, loop=self.loop)
|
||||||
|
|
||||||
self._connection = ConnectionState(dispatch=self.dispatch, chunker=self._chunker,
|
self._connection = ConnectionState(dispatch=self.dispatch, chunker=self._chunker,
|
||||||
syncer=self._syncer, http=self.http, loop=self.loop, **options)
|
syncer=self._syncer, http=self.http, loop=self.loop, **options)
|
||||||
|
@ -88,7 +88,7 @@ class HTTPClient:
|
|||||||
SUCCESS_LOG = '{method} {url} has received {text}'
|
SUCCESS_LOG = '{method} {url} has received {text}'
|
||||||
REQUEST_LOG = '{method} {url} with {json} has returned {status}'
|
REQUEST_LOG = '{method} {url} with {json} has returned {status}'
|
||||||
|
|
||||||
def __init__(self, connector=None, *, loop=None):
|
def __init__(self, connector=None, *, proxy=None, proxy_auth=None, loop=None):
|
||||||
self.loop = asyncio.get_event_loop() if loop is None else loop
|
self.loop = asyncio.get_event_loop() if loop is None else loop
|
||||||
self.connector = connector
|
self.connector = connector
|
||||||
self._session = aiohttp.ClientSession(connector=connector, loop=self.loop)
|
self._session = aiohttp.ClientSession(connector=connector, loop=self.loop)
|
||||||
@ -97,6 +97,8 @@ class HTTPClient:
|
|||||||
self._global_over.set()
|
self._global_over.set()
|
||||||
self.token = None
|
self.token = None
|
||||||
self.bot_token = False
|
self.bot_token = False
|
||||||
|
self.proxy = proxy
|
||||||
|
self.proxy_auth = proxy_auth
|
||||||
|
|
||||||
user_agent = 'DiscordBot (https://github.com/Rapptz/discord.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}'
|
user_agent = 'DiscordBot (https://github.com/Rapptz/discord.py {0}) Python/{1[0]}.{1[1]} aiohttp/{2}'
|
||||||
self.user_agent = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
|
self.user_agent = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
|
||||||
@ -135,6 +137,12 @@ class HTTPClient:
|
|||||||
|
|
||||||
kwargs['headers'] = headers
|
kwargs['headers'] = headers
|
||||||
|
|
||||||
|
# Proxy support
|
||||||
|
if self.proxy is not None:
|
||||||
|
kwargs['proxy'] = self.proxy
|
||||||
|
if self.proxy_auth is not None:
|
||||||
|
kwargs['proxy_auth'] = self.proxy_auth
|
||||||
|
|
||||||
if not self._global_over.is_set():
|
if not self._global_over.is_set():
|
||||||
# wait until the global lock is complete
|
# wait until the global lock is complete
|
||||||
yield from self._global_over.wait()
|
yield from self._global_over.wait()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user