def url(self) -> str: """ The URL string, constructed from the request's URL components. """ if self.first_line_format == "authority": return f"{self.host}:{self.port}" return url.unparse(self.scheme, self.host, self.port, self.path)
def url(self) -> str: """ The full URL string, constructed from `Request.scheme`, `Request.host`, `Request.port` and `Request.path`. Settings this property updates these attributes as well. """ if self.first_line_format == "authority": return f"{self.host}:{self.port}" return url.unparse(self.scheme, self.host, self.port, self.path)
def pretty_url(self) -> str: """ Like :py:attr:`url`, but using :py:attr:`pretty_host` instead of :py:attr:`host`. """ if self.first_line_format == "authority": return self.authority host_header = self.host_header if not host_header: return self.url pretty_host, pretty_port = url.parse_authority(host_header, check=False) pretty_port = pretty_port or url.default_port(self.scheme) or 443 return url.unparse(self.scheme, pretty_host, pretty_port, self.path)
def test_unparse(): assert url.unparse("http", "foo.com", 99, "") == "http://foo.com:99" assert url.unparse("http", "foo.com", 80, "/bar") == "http://foo.com/bar" assert url.unparse("https", "foo.com", 80, "") == "https://foo.com:80" assert url.unparse("https", "foo.com", 443, "") == "https://foo.com"
def url(self) -> str: return unparse(self.scheme, self.netloc, self.port, self.full_path)
def test_unparse(): assert url.unparse("http", "foo.com", 99, "") == "http://foo.com:99" assert url.unparse("http", "foo.com", 80, "/bar") == "http://foo.com/bar" assert url.unparse("https", "foo.com", 80, "") == "https://foo.com:80" assert url.unparse("https", "foo.com", 443, "") == "https://foo.com"