Skip to content

Commit

Permalink
Merge pull request #42 from cdent/bug/41
Browse files Browse the repository at this point in the history
Correctly handler a url argument to interceptor with no port
  • Loading branch information
cdent committed Sep 13, 2016
2 parents 1a3ba19 + cd1b492 commit f1a3c4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions test/test_interceptor.py
Expand Up @@ -45,6 +45,19 @@ def test_interceptor_instance():
assert interceptor.url == 'http://%s:%s/foobar' % (hostname, port)


def test_intercept_by_url_no_port():
# Test for https://github.com/cdent/wsgi-intercept/issues/41
hostname = str(uuid4())
url = 'http://%s/foobar' % hostname
interceptor = Httplib2Interceptor(app=app, url=url)
assert isinstance(interceptor, Interceptor)
assert interceptor.app == app
assert interceptor.host == hostname
assert interceptor.port == 80
assert interceptor.script_name == '/foobar'
assert interceptor.url == url


# http_lib

def test_httpclient_interceptor_host():
Expand Down
6 changes: 5 additions & 1 deletion wsgi_intercept/interceptor.py
Expand Up @@ -66,8 +66,12 @@ def _url_from_primitives(self):
None, None))

def _init_from_url(self, url):
port = None
parsed_url = urlparse.urlsplit(url)
host, port = parsed_url.netloc.split(':')
if ':' in parsed_url.netloc:
host, port = parsed_url.netloc.split(':')
else:
host = parsed_url.netloc
if not port:
if parsed_url.scheme == 'https':
port = 443
Expand Down

0 comments on commit f1a3c4a

Please sign in to comment.