Skip to content

Commit

Permalink
Merge pull request #138 from twm/idn-fo-realz
Browse files Browse the repository at this point in the history
Handle Internationalized Domain Names
  • Loading branch information
glyph committed Sep 18, 2016
2 parents 8fe9159 + f4d58e8 commit e0b3ad8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
install_requires = [
"requests >= 2.1.0",
"service_identity >= 14.0.0",
"six"
"six",
"Twisted >= 16.0.0",
]

if PY3:
install_requires.append("Twisted >= 16.0.0")
install_requires.append("pyOpenSSL >= 0.15.1")
else:
install_requires.append("Twisted >= 16.0.0")
install_requires.append("pyOpenSSL >= 0.13")

setup(
Expand Down
3 changes: 2 additions & 1 deletion treq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from twisted.python.components import proxyForInterface
from twisted.python.compat import _PY3, unicode
from twisted.python.filepath import FilePath
from twisted.python.url import URL

from twisted.web.http import urlparse

Expand Down Expand Up @@ -132,7 +133,7 @@ def request(self, method, url, **kwargs):
url = _combine_query_params(url, params)

if isinstance(url, unicode):
url = url.encode('ascii')
url = URL.fromText(url).asURI().asText().encode('ascii')

# Convert headers dictionary to
# twisted raw headers format.
Expand Down
7 changes: 7 additions & 0 deletions treq/test/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
from io import BytesIO

import mock
Expand Down Expand Up @@ -34,6 +35,12 @@ def assertBody(self, expected):
body = self.FileBodyProducer.mock_calls[0][1][0]
self.assertEqual(body.read(), expected)

def test_request_uri_idn(self):
self.client.request('GET', u'http://‽.net')
self.agent.request.assert_called_once_with(
b'GET', b'http://xn--fwg.net',
Headers({b'accept-encoding': [b'gzip']}), None)

def test_request_case_insensitive_methods(self):
self.client.request('gEt', 'http://example.com/')
self.agent.request.assert_called_once_with(
Expand Down

0 comments on commit e0b3ad8

Please sign in to comment.