Ticket #5475 defect new
twisted.web.server.Request does not honor Host HTTP headers
| Reported by: | orestis | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | web | Keywords: | |
| Cc: | jknight | Branch: | |
| Author: | Launchpad Bug: |
Description (last modified by exarkun) (diff)
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:
-
home/richard/lib/Twisted/trunk/twisted/web/server.py
342 342 return self.session 343 343 344 344 def _prePathURL(self, prepath): 345 port = self.getHost().port346 345 if self.isSecure(): 347 346 default = 443 348 347 else: 349 348 default = 80 349 350 # There won't always be a hostheader, but if it's present, try and find 351 # the port number from it. 352 hostheader = self.getHeader('host') 353 if hostheader: 354 hostheader = hostheader.split(":", 1) 355 if len(hostheader) == 2: 356 port = int(hostheader[1]) 357 else: 358 port = default 359 else: 360 port = self.getHost().port 361 350 362 if port == default: 351 363 hostport = '' 352 364 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.
