Comment 2 for bug 1604608

Revision history for this message
LaMont Jones (lamont) wrote :

getRequestHostname() has similar problems, which this addresses:

    def new_getRequestHostname(self):
        host = self.getHeader(b'host')
        if host:
            if host.startswith(b'['):
                if host.find(b']') < host.rfind(b':'):
                    return host[:host.rfind(b':')]
                else:
                    return host
        host = self.getHost().host
        try:
            ip = IPAddress(host.decode("idna"))
        except AddrFormatError:
            # If we could not convert the hostname to an IPAddress, assume that
            # it is a hostname.
            return networkString(host)
        if ip.version == 4:
            return networkString(host)
        else:
            return networkString(b'[' + host + b']')