Wrong Host header sent when server on different hostname
My entity is https://scott.mn. My server (right now) is http://tent.toxicsli.me. I found that the last step of auth (exchanging code for an access token) was failing because python-tent-client was making the request to http://scott.mn. This change fixed it:
--- tentapp.py.orig 2012-12-06 17:59:36.653636916 -0600
+++ tentapp.py 2012-12-06 17:59:28.529637767 -0600
@@ -210,7 +210,6 @@
# we don't have auth keys yet, so make a non-auth session.
# if authenticate is run later, this session will be replaced with a session that does authentication
headers = dict(DEFAULT_HEADERS)
- headers['Host'] = urlparse(self.entityUrl).netloc
self.session = requests.session(hooks={"pre_request": self._authHook}, headers=headers)
# this list of api roots will be filled in by _discoverAPIurls()
@@ -220,7 +219,6 @@
# now that we've run discovery, the entityUrl might have changed
# so we have to make a new session again.
headers = dict(DEFAULT_HEADERS)
- headers['Host'] = urlparse(self.entityUrl).netloc
self.session = requests.session(hooks={"pre_request": self._authHook}, headers=headers)
Now I'm wondering why the Host header was explicitly set in the first place. Everything seems to work without it, but is there something I'm missing? Why would you explicitly set the Host header rather than leave it up to Requests?
Looks like it came from this commit: https://github.com/longears/python-tent-client/commit/097c82572e15642cddec1dfddfc3557011d8ea1e
I'm not sure why it's there. Doesn't seem like we need to override Requests.