diff -ur Twisted-8.2.0/twisted/web/http.py Twisted-8.2.0-JY/twisted/web/http.py --- Twisted-8.2.0/twisted/web/http.py 2008-09-16 11:54:00.000000000 -0600 +++ Twisted-8.2.0-JY/twisted/web/http.py 2009-04-22 21:12:43.000000000 -0600 @@ -1015,6 +1015,33 @@ return host.split(':', 1)[0] return self.getHost().host + def getRequestHost(self): + """ + Get the host header that the user passed in to the request, which + may also include the port number. If the host header is absent, + try to fake it using the transport. + + This will either use the Host: header (if it is available) or the + host we are listening on if the header is unavailable. + + @returns: the requested host header + @rtype: C{str} + """ + host = self.getHeader('host') + if host: + # host header is present + return host + else: + # try to fake the host header using the transport + host = self.getHost().host + port = self.getHost().port + if self.isSecure(): + default = 443 + else: + default = 80 + if port != default: + host += ':%d' % port + return host def getHost(self): """Get my originally requesting transport's host. diff -ur Twisted-8.2.0/twisted/web/server.py Twisted-8.2.0-JY/twisted/web/server.py --- Twisted-8.2.0/twisted/web/server.py 2007-12-10 07:08:42.000000000 -0700 +++ Twisted-8.2.0-JY/twisted/web/server.py 2009-04-22 21:12:43.000000000 -0600 @@ -332,19 +332,9 @@ return self.session def _prePathURL(self, prepath): - port = self.getHost().port - if self.isSecure(): - default = 443 - else: - default = 80 - if port == default: - hostport = '' - else: - hostport = ':%d' % port - return 'http%s://%s%s/%s' % ( + return 'http%s://%s/%s' % ( self.isSecure() and 's' or '', - self.getRequestHostname(), - hostport, + self.getRequestHost(), '/'.join([quote(segment, safe='') for segment in prepath])) def prePathURL(self):