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

Handle session proxies host and port #35

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion signalr/transports/_ws_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import sys

import gevent
from string import lower
import re

if sys.version_info[0] < 3:
from urlparse import urlparse, urlunparse
Expand Down Expand Up @@ -32,10 +34,19 @@ def __get_ws_url_from(url):
def start(self):
ws_url = self.__get_ws_url_from(self._get_url('connect'))

proxy_dict = {}
if hasattr(self._session, 'proxies'):
target_scheme = lower(ws_url).split(':')[0] if ':' in ws_url else ''
if target_scheme in self._session.proxies:
rgx = '(?P<scheme>[^:]+)://((?P<user>[^:]+):(?P<password>[^@]+)@)?(?P<host>[^/:]+)(:(?P<port>\d+))?/?(?P<path>.*)'
m = re.search(rgx, self._session.proxies[target_scheme])
proxy_dict = {'http_proxy_host': m.group('host'), 'http_proxy_port': int(m.group('port'))}

self.ws = create_connection(ws_url,
header=self.__get_headers(),
cookie=self.__get_cookie_str(),
enable_multithread=True)
enable_multithread=True,
**proxy_dict)
self._session.get(self._get_url('start'))

def _receive():
Expand Down