Skip to content

Commit

Permalink
Issues about #1025 and #1044 (#1088)
Browse files Browse the repository at this point in the history
* Implement proxy support for ClientSession.ws_connect
#1025 Maybe.. Done..
I didn't check by Test mock....
But you said this would beeee OK... Hopefully ^^

This is my first commit.

* Client can not handle hostnames with 63 bytes when a port is given in the url #1044

I handled by reconstructing url string.
And I used function make_netlog in client_reqrep.py

* Client can not handle hostnames with 63 bytes when a port is given in the url #1044

I handled by reconstructing url string.
And I used function make_netlog in client_reqrep.py

* Client can not handle hostnames with 63 bytes when a port is given in the url #1044

#last Message##############################
I handled by reconstructing url string.
And I used function make_netlog in client_reqrep.py
#########################################

I added missing test functions.
It would verify by these methods

* Client can not handle hostnames with 63 bytes when a port is given in the url #1044

#last Message##############################
I handled by reconstructing url string.
And I used function make_netlog in client_reqrep.py
#########################################

I added missing test functions.
It would verify by these methods

* Fix the code format.
They all checked by flake8

* Fix the code format. @ client_reqrep.py
They all checked by flake8
  • Loading branch information
Taekyoon authored and asvetlov committed Aug 25, 2016
1 parent d63ae81 commit 1a64fa7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
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

0 comments on commit 1a64fa7

Please sign in to comment.