gabrielfalcao / gabrielfalcao/HTTPretty

Fails to match hostname with different case

Open
#369 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
2.2k
Forks
285
PR merge metrics
No merged PRs in 30d

Description

A request sent with [Python's `http.client.HTTPConnection`](https://docs.python.org/3/library/http.client.html) is not mocked by HTTPretty.

(Python version 3.7.2; HTTPretty version 0.9.5)

Example (fragment; see the attached file for a full working example):
[test_http_client.py.txt](https://github.com/gabrielfalcao/HTTPretty/files/2769919/test_http_client.py.txt)

```python
uri = urllib.parse.urlunsplit(url_parts)
responses = [
httpretty.Response(
status=http.client.OK,
body="Lorem ipsum, dolor sit amet.",
),
]
httpretty.register_uri(httpretty.PUT, uri, responses=responses)

connection = http.client.HTTPConnection(url_parts.netloc)
connection.putrequest("PUT", uri)
connection.putheader("Connection", "close")
body_bytes = body.encode("utf-8")
connection.putheader("Content-Length", len(body_bytes))
connection.endheaders()
connection.send(body_bytes)
response = connection.getresponse()
```

The code fails when attempting to begin the request:

```
Traceback (most recent call last):
File "test_http_client.py", line 35, in send_fake_put_request
connection.endheaders()
File "/usr/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1016, in _send_output
self.send(msg)
File "/usr/lib/python3.7/http/client.py", line 956, in send
self.connect()
File "/usr/lib/python3.7/http/client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.7/socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
```

The HTTPretty library evidently has not intercepted the HTTPConnection calls that send the HTTP request. This seems to be a failure to mock the request correctly.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.