From: Tom Christie Date: Fri, 20 Dec 2019 10:46:35 +0000 (+0000) Subject: params argument on URL should merge, not replace. (#653) X-Git-Tag: 0.9.5~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74e5115b86871a2a48fffa998ec1fb8fd0d70474;p=thirdparty%2Fhttpx.git params argument on URL should merge, not replace. (#653) --- diff --git a/httpx/models.py b/httpx/models.py index ad3599b7..fc938c3e 100644 --- a/httpx/models.py +++ b/httpx/models.py @@ -90,9 +90,14 @@ class URL: if self.is_absolute_url: self._uri_reference = self._uri_reference.normalize() - # Add any query parameters. + # Add any query parameters, merging with any in the URL if needed. if params: - query_string = str(QueryParams(params)) + if self._uri_reference.query: + url_params = QueryParams(self._uri_reference.query) + url_params.update(params) + query_string = str(url_params) + else: + query_string = str(QueryParams(params)) self._uri_reference = self._uri_reference.copy_with(query=query_string) # Enforce absolute URLs by default. diff --git a/tests/models/test_url.py b/tests/models/test_url.py index 1415ee91..491d0a4b 100644 --- a/tests/models/test_url.py +++ b/tests/models/test_url.py @@ -89,7 +89,7 @@ def test_url_params(): assert str(url) == "https://example.org:123/path/to/somewhere?a=123" url = URL("https://example.org:123/path/to/somewhere?b=456", params={"a": "123"}) - assert str(url) == "https://example.org:123/path/to/somewhere?a=123" + assert str(url) == "https://example.org:123/path/to/somewhere?b=456&a=123" def test_url_join():