'Change the host and port the request thinks it\'s using.
This method is useful for working with reverse HTTP proxies (e.g.
both Squid and Apache\'s mod_proxy can do this), when the address
the HTTP client is using is different than the one we\'re listening on.
For example, Apache may be listening on https://www.example.com/, and
then forwarding requests to http://localhost:8080/, but we don\'t want
HTML produced by Twisted to say b\'http://localhost:8080/\', they should
say b\'https://www.example.com/\', so we do::
request.setHost(b\'www.example.com\', 443, ssl=1)
@type host: C{bytes}
@param host: The value to which to change the host header.
@type ssl: C{bool}
@param ssl: A flag which, if C{True}, indicates that the request is
considered secure (if C{True}, L{isSecure} will return C{True}).'

def setHost(self, host, port, ssl=0):

    self._forceSSL = ssl
    if self.isSecure():
        default = 443
    else:
        default = 80
    if (port == default):
        hostHeader = host
    else:
        hostHeader = ((host + ':') + intToBytes(port))
    self.requestHeaders.setRawHeaders('host', [hostHeader])
    self.host = address.IPv4Address('TCP', host, port)
