'Returns the HTTP host using the environment or request headers.'

def get_host(self):

    if ('HTTP_X_FORWARDED_HOST' in self.META):
        host = self.META['HTTP_X_FORWARDED_HOST']
    elif ('HTTP_HOST' in self.META):
        host = self.META['HTTP_HOST']
    else:
        host = self.META['SERVER_NAME']
        server_port = str(self.META['SERVER_PORT'])
        if (server_port != ((self.is_secure() and '443') or '80')):
            host = ('%s:%s' % (host, server_port))
    return host
