CookieTypes,
HeaderTypes,
QueryParamTypes,
- RawURL,
RequestContent,
RequestData,
RequestFiles,
def __init__(
self,
method: typing.Union[str, bytes],
- url: typing.Union["URL", str, RawURL],
+ url: typing.Union["URL", str],
*,
params: typing.Optional[QueryParamTypes] = None,
headers: typing.Optional[HeaderTypes] = None,
import rfc3986.exceptions
from ._exceptions import InvalidURL
-from ._types import PrimitiveData, QueryParamTypes, RawURL, URLTypes
+from ._types import PrimitiveData, QueryParamTypes, URLTypes
from ._utils import primitive_value_to_str
"""
def __init__(
- self, url: typing.Union["URL", str, RawURL] = "", **kwargs: typing.Any
+ self, url: typing.Union["URL", str] = "", **kwargs: typing.Any
) -> None:
- if isinstance(url, (str, tuple)):
- if isinstance(url, tuple):
- raw_scheme, raw_host, port, raw_path = url
- scheme = raw_scheme.decode("ascii")
- host = raw_host.decode("ascii")
- if host and ":" in host and host[0] != "[":
- # it's an IPv6 address, so it should be enclosed in "[" and "]"
- # ref: https://tools.ietf.org/html/rfc2732#section-2
- # ref: https://tools.ietf.org/html/rfc3986#section-3.2.2
- host = f"[{host}]"
- port_str = "" if port is None else f":{port}"
- path = raw_path.decode("ascii")
- url = f"{scheme}://{host}{port_str}{path}"
-
+ if isinstance(url, str):
try:
self._uri_reference = rfc3986.iri_reference(url).encode()
except rfc3986.exceptions.InvalidAuthority as exc:
"""
return unquote(self._uri_reference.fragment or "")
- @property
- def raw(self) -> RawURL:
- """
- The URL in the raw representation used by the low level
- transport API. See `BaseTransport.handle_request`.
-
- Provides the (scheme, host, port, target) for the outgoing request.
- """
- return (
- self.raw_scheme,
- self.raw_host,
- self.port,
- self.raw_path,
- )
-
@property
def is_absolute_url(self) -> bool:
"""
Given a URL string, return the origin in the raw tuple format that
`httpcore` uses for it's representation.
"""
- scheme, host, port = httpx.URL(url).raw[:3]
- return httpcore.URL(scheme=scheme, host=host, port=port, target="/")
+ u = httpx.URL(url)
+ return httpcore.URL(scheme=u.raw_scheme, host=u.raw_host, port=u.port, target="/")
@pytest.mark.parametrize(
assert str(url) == "http://[::ffff:192.168.0.1]:1234"
-@pytest.mark.parametrize("host", [b"[::ffff:192.168.0.1]", b"::ffff:192.168.0.1"])
+@pytest.mark.parametrize("host", ["[::ffff:192.168.0.1]", "::ffff:192.168.0.1"])
def test_ipv6_url_from_raw_url(host):
- raw_url = (b"https", host, 443, b"/")
- url = httpx.URL(raw_url)
+ url = httpx.URL(scheme="https", host=host, port=443, path="/")
assert url.host == "::ffff:192.168.0.1"
assert url.netloc == b"[::ffff:192.168.0.1]"