Ticket #3845: prepath.2.patch

File prepath.2.patch, 2.2 KB (added by jamesyonan, 11 years ago)

This patch fixes the issue.

  • twisted/web/http.py

    diff -ur Twisted-8.2.0/twisted/web/http.py Twisted-8.2.0-JY/twisted/web/http.py
    old new  
    10151015            return host.split(':', 1)[0]
    10161016        return self.getHost().host
    10171017
     1018    def getRequestHost(self):
     1019        """
     1020        Get the host header that the user passed in to the request, which
     1021        may also include the port number.  If the host header is absent,
     1022        try to fake it using the transport.
     1023
     1024        This will either use the Host: header (if it is available) or the
     1025        host we are listening on if the header is unavailable.
     1026
     1027        @returns: the requested host header
     1028        @rtype: C{str}
     1029        """
     1030        host = self.getHeader('host')
     1031        if host:
     1032            # host header is present
     1033            return host
     1034        else:
     1035            # try to fake the host header using the transport
     1036            host = self.getHost().host
     1037            port = self.getHost().port
     1038            if self.isSecure():
     1039                default = 443
     1040            else:
     1041                default = 80
     1042            if port != default:
     1043                host += ':%d' % port
     1044            return host
    10181045
    10191046    def getHost(self):
    10201047        """Get my originally requesting transport's host.
  • twisted/web/server.py

    diff -ur Twisted-8.2.0/twisted/web/server.py Twisted-8.2.0-JY/twisted/web/server.py
    old new  
    332332        return self.session
    333333
    334334    def _prePathURL(self, prepath):
    335         port = self.getHost().port
    336         if self.isSecure():
    337             default = 443
    338         else:
    339             default = 80
    340         if port == default:
    341             hostport = ''
    342         else:
    343             hostport = ':%d' % port
    344         return 'http%s://%s%s/%s' % (
     335        return 'http%s://%s/%s' % (
    345336            self.isSecure() and 's' or '',
    346             self.getRequestHostname(),
    347             hostport,
     337            self.getRequestHost(),
    348338            '/'.join([quote(segment, safe='') for segment in prepath]))
    349339
    350340    def prePathURL(self):