id,summary,reporter,owner,description,type,status,priority,milestone,component,resolution,keywords,cc,branch,branch_author,launchpad_bug
5475,twisted.web.server.Request does not honor Host HTTP headers,orestis,,"When a twisted web server is placed behind a proxy, requests should honor the proxy-set Host: header in order to set the hostname and port at _prePathURL.

Current behavior picks up the correct hostname, but use the internal listening port, instead of the proxy-used listening port. In my particular instance, this breaks an athena-powered service when placed behind a proxy.

A patch is floating on the twisted-web mailing list:  http://twistedmatrix.com/pipermail/twisted-web/2005-December/002241.html

Pasted here for reference, original author Richard Wall:


{{{
#!diff
Index: /home/richard/lib/Twisted/trunk/twisted/web/server.py
===================================================================
--- /home/richard/lib/Twisted/trunk/twisted/web/server.py	(revision 15343)
+++ /home/richard/lib/Twisted/trunk/twisted/web/server.py	(working copy)
@@ -342,11 +342,23 @@
         return self.session
 
     def _prePathURL(self, prepath):
-        port = self.getHost().port
         if self.isSecure():
             default = 443
         else:
             default = 80
+        
+        # There won't always be a hostheader, but if it's present, try and find 
+        # the port number from it.
+        hostheader = self.getHeader('host')
+        if hostheader:
+            hostheader = hostheader.split("":"", 1)
+            if len(hostheader) == 2:
+                port = int(hostheader[1])
+            else:
+                port = default
+        else:
+            port = self.getHost().port
+            
         if port == default:
             hostport = ''
         else:
}}}

The current twisted literature suggests using a VHostMonsterResource, but this feels clunky. If it covers any additional use-cases that using Host: doesn't, it should explain so in the documentation.
",defect,new,normal,,web,,,jknight,,,
