Skip to content

Commit

Permalink
Reimplement proxy chains
Browse files Browse the repository at this point in the history
  • Loading branch information
romis2012 committed Oct 2, 2023
1 parent e42542f commit 73865ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions aiohttp_socks/connector.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import socket
import typing
from typing import Iterable
from asyncio import BaseTransport, StreamWriter
from typing import Iterable

from aiohttp import TCPConnector
from aiohttp.abc import AbstractResolver
from aiohttp.client_proto import ResponseHandler
from python_socks import ProxyType, parse_proxy_url
from python_socks.async_.asyncio.v2 import Proxy
from python_socks.async_.asyncio.v2 import ProxyChain


class NoResolver(AbstractResolver):
Expand Down Expand Up @@ -38,7 +37,7 @@ def patch_stream(stream):
Fix issue https://github.com/romis2012/aiohttp-socks/issues/27
"""
stream.writer.__class__ = RepairedStreamWriter
while hasattr(stream, '_inner'):
while hasattr(stream, '_inner'): # pragma: no cover
stream = stream._inner # noqa
stream.writer.__class__ = RepairedStreamWriter

Expand Down Expand Up @@ -68,7 +67,7 @@ def __init__(

# noinspection PyMethodOverriding
async def _wrap_create_connection(self, protocol_factory, host, port, *, ssl, **kwargs):
proxy = Proxy.create(
proxy = Proxy(
proxy_type=self._proxy_type,
host=self._proxy_host,
port=self._proxy_port,
Expand Down Expand Up @@ -132,19 +131,19 @@ def __init__(self, proxy_infos: Iterable[ProxyInfo], **kwargs):

# noinspection PyMethodOverriding
async def _wrap_create_connection(self, protocol_factory, host, port, *, ssl, **kwargs):
proxies = []
forward = None
proxy = None
for info in self._proxy_infos:
proxy = Proxy.create(
proxy = Proxy(
proxy_type=info.proxy_type,
host=info.host,
port=info.port,
username=info.username,
password=info.password,
rdns=info.rdns,
forward=forward,
)
proxies.append(proxy)

proxy = ProxyChain(proxies)
forward = proxy

connect_timeout = None

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def get_long_description():
keywords='asyncio aiohttp socks socks5 socks4 http proxy',
install_requires=[
'aiohttp>=2.3.2',
'python-socks[asyncio]>=2.0.0,<3.0.0',
'python-socks[asyncio]>=2.4.3,<3.0.0',
],
)

0 comments on commit 73865ba

Please sign in to comment.