From e3c495a32c63d8aa7f1bcf3b7b27ee1a0ff428e1 Mon Sep 17 00:00:00 2001 From: lebr0nli Date: Thu, 21 Apr 2022 14:22:38 +0800 Subject: [PATCH] Patch `copy_with` --- httpx/_urls.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/httpx/_urls.py b/httpx/_urls.py index 70486bc9e4..f6788e5568 100644 --- a/httpx/_urls.py +++ b/httpx/_urls.py @@ -484,7 +484,11 @@ 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) + if new_url.is_absolute_url: + new_url._uri_reference = new_url._uri_reference.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))