diff --git a/httpx/_urls.py b/httpx/_urls.py index 70486bc9e4..de080de127 100644 --- a/httpx/_urls.py +++ b/httpx/_urls.py @@ -484,7 +484,9 @@ def copy_with(self, **kwargs: typing.Any) -> "URL": # \_/ \______________/\_________/ \_________/ \__/ # | | | | | # scheme authority path query fragment - return URL(self._uri_reference.copy_with(**kwargs).unsplit()) + new_url = URL(self) + new_url._uri_reference = self._uri_reference.copy_with(**kwargs).normalize() + return URL(new_url) def copy_set_param(self, key: str, value: typing.Any = None) -> "URL": return self.copy_with(params=self.params.set(key, value))