diff --git a/httpx/_client.py b/httpx/_client.py index e1815ff476..a45c110e49 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -208,24 +208,18 @@ def _enforce_trailing_slash(self, url: URL) -> URL: return url.copy_with(raw_path=url.raw_path + b"/") def _get_proxy_map( - self, proxies: ProxyTypes | None, allow_env_proxies: bool + self, proxy: ProxyTypes | None, allow_env_proxies: bool ) -> dict[str, Proxy | None]: - if proxies is None: + if proxy is None: if allow_env_proxies: return { key: None if url is None else Proxy(url=url) for key, url in get_environment_proxies().items() } return {} - if isinstance(proxies, dict): - new_proxies = {} - for key, value in proxies.items(): - proxy = Proxy(url=value) if isinstance(value, (str, URL)) else value - new_proxies[str(key)] = proxy - return new_proxies - else: - proxy = Proxy(url=proxies) if isinstance(proxies, (str, URL)) else proxies - return {"all://": proxy} + + proxy = Proxy(url=proxy) if isinstance(proxy, (str, URL)) else proxy + return {"all://": proxy} @property def timeout(self) -> Timeout: @@ -386,17 +380,6 @@ def _merge_url(self, url: URLTypes) -> URL: return self.base_url.copy_with(raw_path=merge_raw_path) return merge_url - def _merge_cookies(self, cookies: CookieTypes | None = None) -> CookieTypes | None: - """ - Merge a cookies argument together with any cookies on the client, - to create the cookies used for the outgoing request. - """ - if cookies or self.cookies: - merged_cookies = Cookies(self.cookies) - merged_cookies.update(cookies) - return merged_cookies - return cookies - def _merge_headers(self, headers: HeaderTypes | None = None) -> HeaderTypes | None: """ Merge a headers argument together with any headers on the client, @@ -1215,7 +1198,7 @@ def delete( def close(self) -> None: """ - Close transport and proxies. + Close transport and mounts. """ if self._state != ClientState.CLOSED: self._state = ClientState.CLOSED @@ -1916,15 +1899,15 @@ async def delete( async def aclose(self) -> None: """ - Close transport and proxies. + Close transport and mounts. """ if self._state != ClientState.CLOSED: self._state = ClientState.CLOSED await self._transport.aclose() - for proxy in self._mounts.values(): - if proxy is not None: - await proxy.aclose() + for transport in self._mounts.values(): + if transport is not None: + await transport.aclose() async def __aenter__(self: U) -> U: if self._state != ClientState.UNOPENED: diff --git a/tests/client/test_client.py b/tests/client/test_client.py index c39ba8c861..1f0ff2671f 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -167,6 +167,13 @@ def test_put(server): assert response.reason_phrase == "OK" +def test_put_json(server): + with httpx.Client() as client: + response = client.put(server.url, json={"text": "Hello, world!"}) + assert response.status_code == 200 + assert response.reason_phrase == "OK" + + def test_patch(server): with httpx.Client() as client: response = client.patch(server.url, content=b"Hello, world!")