HTTPretty icon indicating copy to clipboard operation
HTTPretty copied to clipboard

Specifying a non-standard port in request URI

Open tokeefe opened this issue 9 years ago • 3 comments

I've noticed an issue with regex matching when the incoming HTTP request specifies a non-standard port. Related to #94 perhaps

#!/usr/bin/env python

import re
import httpretty
import requests

httpretty.HTTPretty.allow_net_connect = False
httpretty.enable()

httpretty.register_uri(httpretty.GET, re.compile("/bar"), body="Hello, World!")

# bad
try:
  requests.get("http://foo.io:8080/bar")
except httpretty.errors.UnmockedError, e:
  print e.message #No mocking was registered, and real connections are not allowed

# good
r = requests.get("http://foo.io:80/bar")
print r.content

# also good
r = requests.get("http://foo.io/bar")
print r.content

tokeefe avatar Jun 05 '15 17:06 tokeefe

Did you ever get a resolution to this? Also seeing this error but in my instance im not specifying a port.

PClmnt avatar Jun 25 '18 15:06 PClmnt

This currenly is not supported because HTTPretty can only infer what TCP ports when the given matcher is a string, this behavior was chosen because there is no reliable way to infer what TCP needs to be mocked from the regex object.

I'll add an option to pass the expected port onto register_uri

gabrielfalcao avatar Mar 11 '20 01:03 gabrielfalcao

Hey, can I work on this issue?
I saw that when we give httpretty.register_uri port in the url parameter it works (it's string parameter). and I looking for the function that mock the response, where is it? how the library return custom response?

barziv avatar Nov 01 '23 18:11 barziv