Skip to content

Wrong Host header sent when server on different hostname #47

@graue

Description

@graue

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions