Skip to content

Commit

Permalink
fix for #387 (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed May 13, 2021
1 parent f5ca4d4 commit 4fdae2d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion httpretty/core.py
Expand Up @@ -1569,7 +1569,7 @@ def request_callback(request, uri, response_headers):
"""
uri_is_string = isinstance(uri, str)

if uri_is_string and re.search(r'^\w+://[^/]+[.]\w{2,}$', uri):
if uri_is_string and re.search(r'^\w+://[^/]+[.]\w{2,}(:[0-9]+)?$', uri):
uri += '/'

if isinstance(responses, list) and len(responses) > 0:
Expand Down
26 changes: 26 additions & 0 deletions tests/functional/bugfixes/test_387_regex_port.py
@@ -0,0 +1,26 @@
# based on the snippet from https://github.com/gabrielfalcao/HTTPretty/issues/387

import httpretty
import requests
from sure import expect

@httpretty.activate(allow_net_connect=False, verbose=True)
def test_match_with_port_no_slashes():
"Reproduce #387 registering host:port without trailing slash"
httpretty.register_uri(httpretty.GET, 'http://fakeuri.com:8080', body='{"hello":"world"}')
req = requests.get('http://fakeuri.com:8080', timeout=1)
expect(req.status_code).to.equal(200)
expect(req.json()).to.equal({"hello": "world"})


@httpretty.activate(allow_net_connect=False, verbose=True)
def test_match_with_port_trailing_slash():
"Reproduce #387 registering host:port with trailing slash"
httpretty.register_uri(httpretty.GET, 'https://fakeuri.com:443/', body='{"hello":"world"}')
req = requests.get('https://fakeuri.com:443', timeout=1)
expect(req.status_code).to.equal(200)
expect(req.json()).to.equal({"hello": "world"})

req = requests.get('https://fakeuri.com:443/', timeout=1)
expect(req.status_code).to.equal(200)
expect(req.json()).to.equal({"hello": "world"})

0 comments on commit 4fdae2d

Please sign in to comment.