Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport Graham's http proxy changes to the release_0.6 branch #224

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions receptor/connection/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import aiohttp
import aiohttp.web
import asyncio
from aiohttp.helpers import proxies_from_env
from urllib.parse import urlparse

from .base import Transport, log_ssl_detail

Expand Down Expand Up @@ -37,8 +39,19 @@ async def connect(

worker = factory()
try:
async with aiohttp.ClientSession().ws_connect(uri, ssl=ssl_context,
headers=ws_extra_headers, heartbeat=ws_heartbeat) as ws:
proxy_scheme = {'ws': 'http', 'wss': 'https'}[urlparse(uri).scheme]
proxies = proxies_from_env()
if proxy_scheme in proxies:
proxy = proxies[proxy_scheme].proxy
proxy_auth = proxies[proxy_scheme].proxy_auth
else:
proxy = None
proxy_auth = None
async with aiohttp.ClientSession().ws_connect(
uri, ssl=ssl_context, headers=ws_extra_headers,
heartbeat=ws_heartbeat,
proxy=proxy, proxy_auth=proxy_auth
) as ws:
log_ssl_detail(ws)
t = WebSocket(ws)
await worker.client(t)
Expand Down