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

Issues about #1025 and #1044 #1088

Merged
merged 8 commits into from
Aug 25, 2016
16 changes: 12 additions & 4 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def ws_connect(self, url, *,
autoping=True,
auth=None,
origin=None,
headers=None):
headers=None,
proxy=None,
proxy_auth=None):
"""Initiate websocket connection."""
return _WSRequestContextManager(
self._ws_connect(url,
Expand All @@ -270,7 +272,9 @@ def ws_connect(self, url, *,
autoping=autoping,
auth=auth,
origin=origin,
headers=headers))
headers=headers,
proxy=proxy,
proxy_auth=proxy_auth))

@asyncio.coroutine
def _ws_connect(self, url, *,
Expand All @@ -280,7 +284,9 @@ def _ws_connect(self, url, *,
autoping=True,
auth=None,
origin=None,
headers=None):
headers=None,
proxy=None,
proxy_auth=None):

sec_key = base64.b64encode(os.urandom(16))

Expand All @@ -306,7 +312,9 @@ def _ws_connect(self, url, *,
# send request
resp = yield from self.get(url, headers=headers,
read_until_eof=False,
auth=auth)
auth=auth,
proxy=proxy,
proxy_auth=proxy_auth)

try:
# check handshake
Expand Down
11 changes: 9 additions & 2 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,17 @@ def update_host(self, url):

# check domain idna encoding
try:
netloc = netloc.encode('idna').decode('utf-8')
host = host.encode('idna').decode('utf-8')
# To show more compact to implement codes, I used 'make_netloc()'.
# I think it would be nicer... than implement all contents.
netloc = self.make_netloc(host, url_parsed.port)
except UnicodeError:
raise ValueError('URL has an invalid label.')

# basic auth info
username, password = url_parsed.username, url_parsed.password
if username:
self.auth = helpers.BasicAuth(username, password or '')
netloc = netloc.split('@', 1)[1]

# Record entire netloc for usage in host header
self.netloc = netloc
Expand All @@ -149,6 +150,12 @@ def update_host(self, url):

self.host, self.port, self.scheme = host, port, scheme

def make_netloc(self, host, port):
ret = host
if port:
ret = ret + ':' + str(port)
return ret

def update_version(self, version):
"""Convert request version to two elements tuple.

Expand Down
27 changes: 27 additions & 0 deletions tests/test_client_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,33 @@ def test_params_update_path_and_url(make_request):
assert req.url == 'http://python.org/?test=foo&test=baz'


def test_gen_netloc_all(make_request):
req = make_request('get',
'https://aiohttp:pwpwpw@' +
'12345678901234567890123456789' +
'012345678901234567890:8080')
assert req.netloc == '12345678901234567890123456789' +\
'012345678901234567890:8080'


def test_gen_netloc_no_port(make_request):
req = make_request('get',
'https://aiohttp:pwpwpw@' +
'12345678901234567890123456789' +
'012345678901234567890/')
assert req.netloc == '12345678901234567890123456789' +\
'012345678901234567890'


def test_gen_notloc_failed(make_request):
with pytest.raises(ValueError) as excinfo:
make_request('get',
'https://aiohttp:pwpwpw@' +
'123456789012345678901234567890123456789' +
'01234567890123456789012345/')
assert excinfo.value.message == "URL has an invalid label."


class TestClientRequest(unittest.TestCase):

def setUp(self):
Expand Down