def redirect(self, url, permanent=False):
        """Sends a redirect to the given (optionally relative) URL."""
        if self._headers_written:
            raise Exception("Cannot redirect after headers have been written")
        self.set_status(301 if permanent else 302)
        # Remove whitespace
        url = re.sub(r"[\x00-\x20]+", "", str(url))
        self.set_header("Location", urlparse.urljoin(self.request.uri, url))
        self.finish()
Sends a redirect to the given (optionally relative) URL.
recipes/Python/576906_Python_3_WSGI_Server/recipe-576906.py