Skip to content

Commit

Permalink
Add proxy_ssl parameter #37
Browse files Browse the repository at this point in the history
  • Loading branch information
romis2012 committed Feb 21, 2023
1 parent 6d1236e commit 1fafaf3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion aiohttp_socks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = 'aiohttp-socks'
__version__ = '0.7.1'
__version__ = '0.8.0'

from python_socks import (
ProxyError,
Expand Down
35 changes: 24 additions & 11 deletions aiohttp_socks/connector.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import socket
import typing
from typing import Iterable
from asyncio import BaseTransport

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
Expand Down Expand Up @@ -35,6 +37,7 @@ def __init__(
username=None,
password=None,
rdns=None,
proxy_ssl=None,
**kwargs,
):
kwargs['resolver'] = NoResolver()
Expand All @@ -46,6 +49,7 @@ def __init__(
self._proxy_username = username
self._proxy_password = password
self._rdns = rdns
self._proxy_ssl = proxy_ssl

# noinspection PyMethodOverriding
async def _wrap_create_connection(self, protocol_factory, host, port, *, ssl, **kwargs):
Expand All @@ -56,7 +60,7 @@ async def _wrap_create_connection(self, protocol_factory, host, port, *, ssl, **
username=self._proxy_username,
password=self._proxy_password,
rdns=self._rdns,
loop=self._loop,
proxy_ssl=self._proxy_ssl,
)

connect_timeout = None
Expand All @@ -66,14 +70,17 @@ async def _wrap_create_connection(self, protocol_factory, host, port, *, ssl, **
connect_timeout = getattr(timeout, 'sock_connect', None)

stream = await proxy.connect(
dest_host=host, dest_port=port, dest_ssl=ssl, timeout=connect_timeout
dest_host=host,
dest_port=port,
dest_ssl=ssl,
timeout=connect_timeout,
)

transport = stream.writer.transport
protocol = protocol_factory()
transport: BaseTransport = stream.writer.transport
protocol: ResponseHandler = protocol_factory()

transport.set_protocol(protocol)
protocol.transport = transport
protocol.connection_made(transport)

return transport, protocol

Expand Down Expand Up @@ -117,7 +124,6 @@ async def _wrap_create_connection(self, protocol_factory, host, port, *, ssl, **
username=info.username,
password=info.password,
rdns=info.rdns,
loop=self._loop,
)
proxies.append(proxy)

Expand All @@ -130,14 +136,17 @@ async def _wrap_create_connection(self, protocol_factory, host, port, *, ssl, **
connect_timeout = getattr(timeout, 'sock_connect', None)

stream = await proxy.connect(
dest_host=host, dest_port=port, dest_ssl=ssl, timeout=connect_timeout
dest_host=host,
dest_port=port,
dest_ssl=ssl,
timeout=connect_timeout,
)

transport = stream.writer.transport
protocol = protocol_factory()
transport: BaseTransport = stream.writer.transport
protocol: ResponseHandler = protocol_factory()

transport.set_protocol(protocol)
protocol.transport = transport
protocol.connection_made(transport)

return transport, protocol

Expand All @@ -147,7 +156,11 @@ def from_urls(cls, urls: Iterable[str], **kwargs):
for url in urls:
proxy_type, host, port, username, password = parse_proxy_url(url)
proxy_info = ProxyInfo(
proxy_type=proxy_type, host=host, port=port, username=username, password=password
proxy_type=proxy_type,
host=host,
port=port,
username=username,
password=password,
)
infos.append(proxy_info)

Expand Down

0 comments on commit 1fafaf3

Please sign in to comment.