I believe that I’ve encountered a bug with setting the Host
header within the http client. When setting headers={'Host': 'python.org'}
on a conn.request()
call such as conn.request('GET', 'http://enjuvjj7xheyd.x.pipedream.net/a', headers={'Host': 'python.org'})
the “host” received by the server is listed as enjuvjj7xheyd.x.pipedream.net
when I would expect the host to be listed as “python.org”.
The code snippet below can reproduce the issue when run on python 3.11.1 (from the Docker image python:latest
when run as docker run -it --volume $(pwd):/var/tmp python:latest /bin/bash
with the code snippet below mounted into the Docker container.
#!/usr/bin/env python3
import http.client
# you will want to replace the hostname URL used below in order to test
conn = http.client.HTTPConnection('enjuvjj7xheyd.x.pipedream.net')
conn.set_debuglevel(1)
conn.request('GET', 'http://enjuvjj7xheyd.x.pipedream.net/a', headers={'Host': 'python.org'})
response = conn.getresponse()
If this should be a bug I’m happy to post to Issues · python/cpython · GitHub or if this isn’t I’m happy to do some further testing.