We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
When using proxy the request downgrades to HTTP/1
Using the following code

```
client = httpx.Client(http2=True, proxies=proxies)
 response = client.get('https://www.truepeoplesearch.com/results?name=John', headers=headers)
response.http_version
```

It appears that it returns HTTP/1

but if I were to make the same request without proxy, it shows HTTP/2


Version of HTTPX being used.
```
Name: httpx
Version: 0.21.1
Summary: The next generation HTTP client.
Home-page: https://github.com/encode/httpx
Author: Tom Christie
Author-email: tom@tomchristie.com
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `httpx/_transports/default.py`
Content:
```
1 """
2 Custom transports, with nicely configured defaults.
3 
4 The following additional keyword arguments are currently supported by httpcore...
5 
6 * uds: str
7 * local_address: str
8 * retries: int
9 
10 Example usages...
11 
12 # Disable HTTP/2 on a single specific domain.
13 mounts = {
14     "all://": httpx.HTTPTransport(http2=True),
15     "all://*example.org": httpx.HTTPTransport()
16 }
17 
18 # Using advanced httpcore configuration, with connection retries.
19 transport = httpx.HTTPTransport(retries=1)
20 client = httpx.Client(transport=transport)
21 
22 # Using advanced httpcore configuration, with unix domain sockets.
23 transport = httpx.HTTPTransport(uds="socket.uds")
24 client = httpx.Client(transport=transport)
25 """
26 import contextlib
27 import typing
28 from types import TracebackType
29 
30 import httpcore
31 
32 from .._config import DEFAULT_LIMITS, Limits, Proxy, create_ssl_context
33 from .._exceptions import (
34     ConnectError,
35     ConnectTimeout,
36     LocalProtocolError,
37     NetworkError,
38     PoolTimeout,
39     ProtocolError,
40     ProxyError,
41     ReadError,
42     ReadTimeout,
43     RemoteProtocolError,
44     TimeoutException,
45     UnsupportedProtocol,
46     WriteError,
47     WriteTimeout,
48 )
49 from .._models import Request, Response
50 from .._types import AsyncByteStream, CertTypes, SyncByteStream, VerifyTypes
51 from .base import AsyncBaseTransport, BaseTransport
52 
53 T = typing.TypeVar("T", bound="HTTPTransport")
54 A = typing.TypeVar("A", bound="AsyncHTTPTransport")
55 
56 
57 @contextlib.contextmanager
58 def map_httpcore_exceptions() -> typing.Iterator[None]:
59     try:
60         yield
61     except Exception as exc:  # noqa: PIE-786
62         mapped_exc = None
63 
64         for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
65             if not isinstance(exc, from_exc):
66                 continue
67             # We want to map to the most specific exception we can find.
68             # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
69             # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
70             if mapped_exc is None or issubclass(to_exc, mapped_exc):
71                 mapped_exc = to_exc
72 
73         if mapped_exc is None:  # pragma: nocover
74             raise
75 
76         message = str(exc)
77         raise mapped_exc(message) from exc
78 
79 
80 HTTPCORE_EXC_MAP = {
81     httpcore.TimeoutException: TimeoutException,
82     httpcore.ConnectTimeout: ConnectTimeout,
83     httpcore.ReadTimeout: ReadTimeout,
84     httpcore.WriteTimeout: WriteTimeout,
85     httpcore.PoolTimeout: PoolTimeout,
86     httpcore.NetworkError: NetworkError,
87     httpcore.ConnectError: ConnectError,
88     httpcore.ReadError: ReadError,
89     httpcore.WriteError: WriteError,
90     httpcore.ProxyError: ProxyError,
91     httpcore.UnsupportedProtocol: UnsupportedProtocol,
92     httpcore.ProtocolError: ProtocolError,
93     httpcore.LocalProtocolError: LocalProtocolError,
94     httpcore.RemoteProtocolError: RemoteProtocolError,
95 }
96 
97 
98 class ResponseStream(SyncByteStream):
99     def __init__(self, httpcore_stream: typing.Iterable[bytes]):
100         self._httpcore_stream = httpcore_stream
101 
102     def __iter__(self) -> typing.Iterator[bytes]:
103         with map_httpcore_exceptions():
104             for part in self._httpcore_stream:
105                 yield part
106 
107     def close(self) -> None:
108         if hasattr(self._httpcore_stream, "close"):
109             self._httpcore_stream.close()  # type: ignore
110 
111 
112 class HTTPTransport(BaseTransport):
113     def __init__(
114         self,
115         verify: VerifyTypes = True,
116         cert: CertTypes = None,
117         http1: bool = True,
118         http2: bool = False,
119         limits: Limits = DEFAULT_LIMITS,
120         trust_env: bool = True,
121         proxy: Proxy = None,
122         uds: str = None,
123         local_address: str = None,
124         retries: int = 0,
125     ) -> None:
126         ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
127 
128         if proxy is None:
129             self._pool = httpcore.ConnectionPool(
130                 ssl_context=ssl_context,
131                 max_connections=limits.max_connections,
132                 max_keepalive_connections=limits.max_keepalive_connections,
133                 keepalive_expiry=limits.keepalive_expiry,
134                 http1=http1,
135                 http2=http2,
136                 uds=uds,
137                 local_address=local_address,
138                 retries=retries,
139             )
140         else:
141             self._pool = httpcore.HTTPProxy(
142                 proxy_url=httpcore.URL(
143                     scheme=proxy.url.raw_scheme,
144                     host=proxy.url.raw_host,
145                     port=proxy.url.port,
146                     target=proxy.url.raw_path,
147                 ),
148                 proxy_headers=proxy.headers.raw,
149                 ssl_context=ssl_context,
150                 max_connections=limits.max_connections,
151                 max_keepalive_connections=limits.max_keepalive_connections,
152                 keepalive_expiry=limits.keepalive_expiry,
153             )
154 
155     def __enter__(self: T) -> T:  # Use generics for subclass support.
156         self._pool.__enter__()
157         return self
158 
159     def __exit__(
160         self,
161         exc_type: typing.Type[BaseException] = None,
162         exc_value: BaseException = None,
163         traceback: TracebackType = None,
164     ) -> None:
165         with map_httpcore_exceptions():
166             self._pool.__exit__(exc_type, exc_value, traceback)
167 
168     def handle_request(
169         self,
170         request: Request,
171     ) -> Response:
172         assert isinstance(request.stream, SyncByteStream)
173 
174         req = httpcore.Request(
175             method=request.method,
176             url=httpcore.URL(
177                 scheme=request.url.raw_scheme,
178                 host=request.url.raw_host,
179                 port=request.url.port,
180                 target=request.url.raw_path,
181             ),
182             headers=request.headers.raw,
183             content=request.stream,
184             extensions=request.extensions,
185         )
186         with map_httpcore_exceptions():
187             resp = self._pool.handle_request(req)
188 
189         assert isinstance(resp.stream, typing.Iterable)
190 
191         return Response(
192             status_code=resp.status,
193             headers=resp.headers,
194             stream=ResponseStream(resp.stream),
195             extensions=resp.extensions,
196         )
197 
198     def close(self) -> None:
199         self._pool.close()
200 
201 
202 class AsyncResponseStream(AsyncByteStream):
203     def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]):
204         self._httpcore_stream = httpcore_stream
205 
206     async def __aiter__(self) -> typing.AsyncIterator[bytes]:
207         with map_httpcore_exceptions():
208             async for part in self._httpcore_stream:
209                 yield part
210 
211     async def aclose(self) -> None:
212         if hasattr(self._httpcore_stream, "aclose"):
213             await self._httpcore_stream.aclose()  # type: ignore
214 
215 
216 class AsyncHTTPTransport(AsyncBaseTransport):
217     def __init__(
218         self,
219         verify: VerifyTypes = True,
220         cert: CertTypes = None,
221         http1: bool = True,
222         http2: bool = False,
223         limits: Limits = DEFAULT_LIMITS,
224         trust_env: bool = True,
225         proxy: Proxy = None,
226         uds: str = None,
227         local_address: str = None,
228         retries: int = 0,
229     ) -> None:
230         ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
231 
232         if proxy is None:
233             self._pool = httpcore.AsyncConnectionPool(
234                 ssl_context=ssl_context,
235                 max_connections=limits.max_connections,
236                 max_keepalive_connections=limits.max_keepalive_connections,
237                 keepalive_expiry=limits.keepalive_expiry,
238                 http1=http1,
239                 http2=http2,
240                 uds=uds,
241                 local_address=local_address,
242                 retries=retries,
243             )
244         else:
245             self._pool = httpcore.AsyncHTTPProxy(
246                 proxy_url=httpcore.URL(
247                     scheme=proxy.url.raw_scheme,
248                     host=proxy.url.raw_host,
249                     port=proxy.url.port,
250                     target=proxy.url.raw_path,
251                 ),
252                 proxy_headers=proxy.headers.raw,
253                 ssl_context=ssl_context,
254                 max_connections=limits.max_connections,
255                 max_keepalive_connections=limits.max_keepalive_connections,
256                 keepalive_expiry=limits.keepalive_expiry,
257             )
258 
259     async def __aenter__(self: A) -> A:  # Use generics for subclass support.
260         await self._pool.__aenter__()
261         return self
262 
263     async def __aexit__(
264         self,
265         exc_type: typing.Type[BaseException] = None,
266         exc_value: BaseException = None,
267         traceback: TracebackType = None,
268     ) -> None:
269         with map_httpcore_exceptions():
270             await self._pool.__aexit__(exc_type, exc_value, traceback)
271 
272     async def handle_async_request(
273         self,
274         request: Request,
275     ) -> Response:
276         assert isinstance(request.stream, AsyncByteStream)
277 
278         req = httpcore.Request(
279             method=request.method,
280             url=httpcore.URL(
281                 scheme=request.url.raw_scheme,
282                 host=request.url.raw_host,
283                 port=request.url.port,
284                 target=request.url.raw_path,
285             ),
286             headers=request.headers.raw,
287             content=request.stream,
288             extensions=request.extensions,
289         )
290         with map_httpcore_exceptions():
291             resp = await self._pool.handle_async_request(req)
292 
293         assert isinstance(resp.stream, typing.AsyncIterable)
294 
295         return Response(
296             status_code=resp.status,
297             headers=resp.headers,
298             stream=AsyncResponseStream(resp.stream),
299             extensions=resp.extensions,
300         )
301 
302     async def aclose(self) -> None:
303         await self._pool.aclose()
304
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/httpx/_transports/default.py b/httpx/_transports/default.py
--- a/httpx/_transports/default.py
+++ b/httpx/_transports/default.py
@@ -138,19 +138,36 @@
                 retries=retries,
             )
         else:
-            self._pool = httpcore.HTTPProxy(
-                proxy_url=httpcore.URL(
-                    scheme=proxy.url.raw_scheme,
-                    host=proxy.url.raw_host,
-                    port=proxy.url.port,
-                    target=proxy.url.raw_path,
-                ),
-                proxy_headers=proxy.headers.raw,
-                ssl_context=ssl_context,
-                max_connections=limits.max_connections,
-                max_keepalive_connections=limits.max_keepalive_connections,
-                keepalive_expiry=limits.keepalive_expiry,
-            )
+            try:
+                self._pool = httpcore.HTTPProxy(
+                    proxy_url=httpcore.URL(
+                        scheme=proxy.url.raw_scheme,
+                        host=proxy.url.raw_host,
+                        port=proxy.url.port,
+                        target=proxy.url.raw_path,
+                    ),
+                    proxy_headers=proxy.headers.raw,
+                    ssl_context=ssl_context,
+                    max_connections=limits.max_connections,
+                    max_keepalive_connections=limits.max_keepalive_connections,
+                    keepalive_expiry=limits.keepalive_expiry,
+                    http1=http1,
+                    http2=http2,
+                )
+            except TypeError:  # pragma: nocover
+                self._pool = httpcore.HTTPProxy(
+                    proxy_url=httpcore.URL(
+                        scheme=proxy.url.raw_scheme,
+                        host=proxy.url.raw_host,
+                        port=proxy.url.port,
+                        target=proxy.url.raw_path,
+                    ),
+                    proxy_headers=proxy.headers.raw,
+                    ssl_context=ssl_context,
+                    max_connections=limits.max_connections,
+                    max_keepalive_connections=limits.max_keepalive_connections,
+                    keepalive_expiry=limits.keepalive_expiry,
+                )
 
     def __enter__(self: T) -> T:  # Use generics for subclass support.
         self._pool.__enter__()

{"golden_diff": "diff --git a/httpx/_transports/default.py b/httpx/_transports/default.py\n--- a/httpx/_transports/default.py\n+++ b/httpx/_transports/default.py\n@@ -138,19 +138,36 @@\n                 retries=retries,\n             )\n         else:\n-            self._pool = httpcore.HTTPProxy(\n-                proxy_url=httpcore.URL(\n-                    scheme=proxy.url.raw_scheme,\n-                    host=proxy.url.raw_host,\n-                    port=proxy.url.port,\n-                    target=proxy.url.raw_path,\n-                ),\n-                proxy_headers=proxy.headers.raw,\n-                ssl_context=ssl_context,\n-                max_connections=limits.max_connections,\n-                max_keepalive_connections=limits.max_keepalive_connections,\n-                keepalive_expiry=limits.keepalive_expiry,\n-            )\n+            try:\n+                self._pool = httpcore.HTTPProxy(\n+                    proxy_url=httpcore.URL(\n+                        scheme=proxy.url.raw_scheme,\n+                        host=proxy.url.raw_host,\n+                        port=proxy.url.port,\n+                        target=proxy.url.raw_path,\n+                    ),\n+                    proxy_headers=proxy.headers.raw,\n+                    ssl_context=ssl_context,\n+                    max_connections=limits.max_connections,\n+                    max_keepalive_connections=limits.max_keepalive_connections,\n+                    keepalive_expiry=limits.keepalive_expiry,\n+                    http1=http1,\n+                    http2=http2,\n+                )\n+            except TypeError:  # pragma: nocover\n+                self._pool = httpcore.HTTPProxy(\n+                    proxy_url=httpcore.URL(\n+                        scheme=proxy.url.raw_scheme,\n+                        host=proxy.url.raw_host,\n+                        port=proxy.url.port,\n+                        target=proxy.url.raw_path,\n+                    ),\n+                    proxy_headers=proxy.headers.raw,\n+                    ssl_context=ssl_context,\n+                    max_connections=limits.max_connections,\n+                    max_keepalive_connections=limits.max_keepalive_connections,\n+                    keepalive_expiry=limits.keepalive_expiry,\n+                )\n \n     def __enter__(self: T) -> T:  # Use generics for subclass support.\n         self._pool.__enter__()\n", "issue": "When using proxy the request downgrades to HTTP/1\nUsing the following code\r\n\r\n```\r\nclient = httpx.Client(http2=True, proxies=proxies)\r\n response = client.get('https://www.truepeoplesearch.com/results?name=John', headers=headers)\r\nresponse.http_version\r\n```\r\n\r\nIt appears that it returns HTTP/1\r\n\r\nbut if I were to make the same request without proxy, it shows HTTP/2\r\n\r\n\r\nVersion of HTTPX being used.\r\n```\r\nName: httpx\r\nVersion: 0.21.1\r\nSummary: The next generation HTTP client.\r\nHome-page: https://github.com/encode/httpx\r\nAuthor: Tom Christie\r\nAuthor-email: tom@tomchristie.com\r\n```\n", "before_files": [{"content": "\"\"\"\nCustom transports, with nicely configured defaults.\n\nThe following additional keyword arguments are currently supported by httpcore...\n\n* uds: str\n* local_address: str\n* retries: int\n\nExample usages...\n\n# Disable HTTP/2 on a single specific domain.\nmounts = {\n    \"all://\": httpx.HTTPTransport(http2=True),\n    \"all://*example.org\": httpx.HTTPTransport()\n}\n\n# Using advanced httpcore configuration, with connection retries.\ntransport = httpx.HTTPTransport(retries=1)\nclient = httpx.Client(transport=transport)\n\n# Using advanced httpcore configuration, with unix domain sockets.\ntransport = httpx.HTTPTransport(uds=\"socket.uds\")\nclient = httpx.Client(transport=transport)\n\"\"\"\nimport contextlib\nimport typing\nfrom types import TracebackType\n\nimport httpcore\n\nfrom .._config import DEFAULT_LIMITS, Limits, Proxy, create_ssl_context\nfrom .._exceptions import (\n    ConnectError,\n    ConnectTimeout,\n    LocalProtocolError,\n    NetworkError,\n    PoolTimeout,\n    ProtocolError,\n    ProxyError,\n    ReadError,\n    ReadTimeout,\n    RemoteProtocolError,\n    TimeoutException,\n    UnsupportedProtocol,\n    WriteError,\n    WriteTimeout,\n)\nfrom .._models import Request, Response\nfrom .._types import AsyncByteStream, CertTypes, SyncByteStream, VerifyTypes\nfrom .base import AsyncBaseTransport, BaseTransport\n\nT = typing.TypeVar(\"T\", bound=\"HTTPTransport\")\nA = typing.TypeVar(\"A\", bound=\"AsyncHTTPTransport\")\n\n\n@contextlib.contextmanager\ndef map_httpcore_exceptions() -> typing.Iterator[None]:\n    try:\n        yield\n    except Exception as exc:  # noqa: PIE-786\n        mapped_exc = None\n\n        for from_exc, to_exc in HTTPCORE_EXC_MAP.items():\n            if not isinstance(exc, from_exc):\n                continue\n            # We want to map to the most specific exception we can find.\n            # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n            # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n            if mapped_exc is None or issubclass(to_exc, mapped_exc):\n                mapped_exc = to_exc\n\n        if mapped_exc is None:  # pragma: nocover\n            raise\n\n        message = str(exc)\n        raise mapped_exc(message) from exc\n\n\nHTTPCORE_EXC_MAP = {\n    httpcore.TimeoutException: TimeoutException,\n    httpcore.ConnectTimeout: ConnectTimeout,\n    httpcore.ReadTimeout: ReadTimeout,\n    httpcore.WriteTimeout: WriteTimeout,\n    httpcore.PoolTimeout: PoolTimeout,\n    httpcore.NetworkError: NetworkError,\n    httpcore.ConnectError: ConnectError,\n    httpcore.ReadError: ReadError,\n    httpcore.WriteError: WriteError,\n    httpcore.ProxyError: ProxyError,\n    httpcore.UnsupportedProtocol: UnsupportedProtocol,\n    httpcore.ProtocolError: ProtocolError,\n    httpcore.LocalProtocolError: LocalProtocolError,\n    httpcore.RemoteProtocolError: RemoteProtocolError,\n}\n\n\nclass ResponseStream(SyncByteStream):\n    def __init__(self, httpcore_stream: typing.Iterable[bytes]):\n        self._httpcore_stream = httpcore_stream\n\n    def __iter__(self) -> typing.Iterator[bytes]:\n        with map_httpcore_exceptions():\n            for part in self._httpcore_stream:\n                yield part\n\n    def close(self) -> None:\n        if hasattr(self._httpcore_stream, \"close\"):\n            self._httpcore_stream.close()  # type: ignore\n\n\nclass HTTPTransport(BaseTransport):\n    def __init__(\n        self,\n        verify: VerifyTypes = True,\n        cert: CertTypes = None,\n        http1: bool = True,\n        http2: bool = False,\n        limits: Limits = DEFAULT_LIMITS,\n        trust_env: bool = True,\n        proxy: Proxy = None,\n        uds: str = None,\n        local_address: str = None,\n        retries: int = 0,\n    ) -> None:\n        ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)\n\n        if proxy is None:\n            self._pool = httpcore.ConnectionPool(\n                ssl_context=ssl_context,\n                max_connections=limits.max_connections,\n                max_keepalive_connections=limits.max_keepalive_connections,\n                keepalive_expiry=limits.keepalive_expiry,\n                http1=http1,\n                http2=http2,\n                uds=uds,\n                local_address=local_address,\n                retries=retries,\n            )\n        else:\n            self._pool = httpcore.HTTPProxy(\n                proxy_url=httpcore.URL(\n                    scheme=proxy.url.raw_scheme,\n                    host=proxy.url.raw_host,\n                    port=proxy.url.port,\n                    target=proxy.url.raw_path,\n                ),\n                proxy_headers=proxy.headers.raw,\n                ssl_context=ssl_context,\n                max_connections=limits.max_connections,\n                max_keepalive_connections=limits.max_keepalive_connections,\n                keepalive_expiry=limits.keepalive_expiry,\n            )\n\n    def __enter__(self: T) -> T:  # Use generics for subclass support.\n        self._pool.__enter__()\n        return self\n\n    def __exit__(\n        self,\n        exc_type: typing.Type[BaseException] = None,\n        exc_value: BaseException = None,\n        traceback: TracebackType = None,\n    ) -> None:\n        with map_httpcore_exceptions():\n            self._pool.__exit__(exc_type, exc_value, traceback)\n\n    def handle_request(\n        self,\n        request: Request,\n    ) -> Response:\n        assert isinstance(request.stream, SyncByteStream)\n\n        req = httpcore.Request(\n            method=request.method,\n            url=httpcore.URL(\n                scheme=request.url.raw_scheme,\n                host=request.url.raw_host,\n                port=request.url.port,\n                target=request.url.raw_path,\n            ),\n            headers=request.headers.raw,\n            content=request.stream,\n            extensions=request.extensions,\n        )\n        with map_httpcore_exceptions():\n            resp = self._pool.handle_request(req)\n\n        assert isinstance(resp.stream, typing.Iterable)\n\n        return Response(\n            status_code=resp.status,\n            headers=resp.headers,\n            stream=ResponseStream(resp.stream),\n            extensions=resp.extensions,\n        )\n\n    def close(self) -> None:\n        self._pool.close()\n\n\nclass AsyncResponseStream(AsyncByteStream):\n    def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]):\n        self._httpcore_stream = httpcore_stream\n\n    async def __aiter__(self) -> typing.AsyncIterator[bytes]:\n        with map_httpcore_exceptions():\n            async for part in self._httpcore_stream:\n                yield part\n\n    async def aclose(self) -> None:\n        if hasattr(self._httpcore_stream, \"aclose\"):\n            await self._httpcore_stream.aclose()  # type: ignore\n\n\nclass AsyncHTTPTransport(AsyncBaseTransport):\n    def __init__(\n        self,\n        verify: VerifyTypes = True,\n        cert: CertTypes = None,\n        http1: bool = True,\n        http2: bool = False,\n        limits: Limits = DEFAULT_LIMITS,\n        trust_env: bool = True,\n        proxy: Proxy = None,\n        uds: str = None,\n        local_address: str = None,\n        retries: int = 0,\n    ) -> None:\n        ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)\n\n        if proxy is None:\n            self._pool = httpcore.AsyncConnectionPool(\n                ssl_context=ssl_context,\n                max_connections=limits.max_connections,\n                max_keepalive_connections=limits.max_keepalive_connections,\n                keepalive_expiry=limits.keepalive_expiry,\n                http1=http1,\n                http2=http2,\n                uds=uds,\n                local_address=local_address,\n                retries=retries,\n            )\n        else:\n            self._pool = httpcore.AsyncHTTPProxy(\n                proxy_url=httpcore.URL(\n                    scheme=proxy.url.raw_scheme,\n                    host=proxy.url.raw_host,\n                    port=proxy.url.port,\n                    target=proxy.url.raw_path,\n                ),\n                proxy_headers=proxy.headers.raw,\n                ssl_context=ssl_context,\n                max_connections=limits.max_connections,\n                max_keepalive_connections=limits.max_keepalive_connections,\n                keepalive_expiry=limits.keepalive_expiry,\n            )\n\n    async def __aenter__(self: A) -> A:  # Use generics for subclass support.\n        await self._pool.__aenter__()\n        return self\n\n    async def __aexit__(\n        self,\n        exc_type: typing.Type[BaseException] = None,\n        exc_value: BaseException = None,\n        traceback: TracebackType = None,\n    ) -> None:\n        with map_httpcore_exceptions():\n            await self._pool.__aexit__(exc_type, exc_value, traceback)\n\n    async def handle_async_request(\n        self,\n        request: Request,\n    ) -> Response:\n        assert isinstance(request.stream, AsyncByteStream)\n\n        req = httpcore.Request(\n            method=request.method,\n            url=httpcore.URL(\n                scheme=request.url.raw_scheme,\n                host=request.url.raw_host,\n                port=request.url.port,\n                target=request.url.raw_path,\n            ),\n            headers=request.headers.raw,\n            content=request.stream,\n            extensions=request.extensions,\n        )\n        with map_httpcore_exceptions():\n            resp = await self._pool.handle_async_request(req)\n\n        assert isinstance(resp.stream, typing.AsyncIterable)\n\n        return Response(\n            status_code=resp.status,\n            headers=resp.headers,\n            stream=AsyncResponseStream(resp.stream),\n            extensions=resp.extensions,\n        )\n\n    async def aclose(self) -> None:\n        await self._pool.aclose()\n", "path": "httpx/_transports/default.py"}], "after_files": [{"content": "\"\"\"\nCustom transports, with nicely configured defaults.\n\nThe following additional keyword arguments are currently supported by httpcore...\n\n* uds: str\n* local_address: str\n* retries: int\n\nExample usages...\n\n# Disable HTTP/2 on a single specific domain.\nmounts = {\n    \"all://\": httpx.HTTPTransport(http2=True),\n    \"all://*example.org\": httpx.HTTPTransport()\n}\n\n# Using advanced httpcore configuration, with connection retries.\ntransport = httpx.HTTPTransport(retries=1)\nclient = httpx.Client(transport=transport)\n\n# Using advanced httpcore configuration, with unix domain sockets.\ntransport = httpx.HTTPTransport(uds=\"socket.uds\")\nclient = httpx.Client(transport=transport)\n\"\"\"\nimport contextlib\nimport typing\nfrom types import TracebackType\n\nimport httpcore\n\nfrom .._config import DEFAULT_LIMITS, Limits, Proxy, create_ssl_context\nfrom .._exceptions import (\n    ConnectError,\n    ConnectTimeout,\n    LocalProtocolError,\n    NetworkError,\n    PoolTimeout,\n    ProtocolError,\n    ProxyError,\n    ReadError,\n    ReadTimeout,\n    RemoteProtocolError,\n    TimeoutException,\n    UnsupportedProtocol,\n    WriteError,\n    WriteTimeout,\n)\nfrom .._models import Request, Response\nfrom .._types import AsyncByteStream, CertTypes, SyncByteStream, VerifyTypes\nfrom .base import AsyncBaseTransport, BaseTransport\n\nT = typing.TypeVar(\"T\", bound=\"HTTPTransport\")\nA = typing.TypeVar(\"A\", bound=\"AsyncHTTPTransport\")\n\n\n@contextlib.contextmanager\ndef map_httpcore_exceptions() -> typing.Iterator[None]:\n    try:\n        yield\n    except Exception as exc:  # noqa: PIE-786\n        mapped_exc = None\n\n        for from_exc, to_exc in HTTPCORE_EXC_MAP.items():\n            if not isinstance(exc, from_exc):\n                continue\n            # We want to map to the most specific exception we can find.\n            # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to\n            # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.\n            if mapped_exc is None or issubclass(to_exc, mapped_exc):\n                mapped_exc = to_exc\n\n        if mapped_exc is None:  # pragma: nocover\n            raise\n\n        message = str(exc)\n        raise mapped_exc(message) from exc\n\n\nHTTPCORE_EXC_MAP = {\n    httpcore.TimeoutException: TimeoutException,\n    httpcore.ConnectTimeout: ConnectTimeout,\n    httpcore.ReadTimeout: ReadTimeout,\n    httpcore.WriteTimeout: WriteTimeout,\n    httpcore.PoolTimeout: PoolTimeout,\n    httpcore.NetworkError: NetworkError,\n    httpcore.ConnectError: ConnectError,\n    httpcore.ReadError: ReadError,\n    httpcore.WriteError: WriteError,\n    httpcore.ProxyError: ProxyError,\n    httpcore.UnsupportedProtocol: UnsupportedProtocol,\n    httpcore.ProtocolError: ProtocolError,\n    httpcore.LocalProtocolError: LocalProtocolError,\n    httpcore.RemoteProtocolError: RemoteProtocolError,\n}\n\n\nclass ResponseStream(SyncByteStream):\n    def __init__(self, httpcore_stream: typing.Iterable[bytes]):\n        self._httpcore_stream = httpcore_stream\n\n    def __iter__(self) -> typing.Iterator[bytes]:\n        with map_httpcore_exceptions():\n            for part in self._httpcore_stream:\n                yield part\n\n    def close(self) -> None:\n        if hasattr(self._httpcore_stream, \"close\"):\n            self._httpcore_stream.close()  # type: ignore\n\n\nclass HTTPTransport(BaseTransport):\n    def __init__(\n        self,\n        verify: VerifyTypes = True,\n        cert: CertTypes = None,\n        http1: bool = True,\n        http2: bool = False,\n        limits: Limits = DEFAULT_LIMITS,\n        trust_env: bool = True,\n        proxy: Proxy = None,\n        uds: str = None,\n        local_address: str = None,\n        retries: int = 0,\n    ) -> None:\n        ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)\n\n        if proxy is None:\n            self._pool = httpcore.ConnectionPool(\n                ssl_context=ssl_context,\n                max_connections=limits.max_connections,\n                max_keepalive_connections=limits.max_keepalive_connections,\n                keepalive_expiry=limits.keepalive_expiry,\n                http1=http1,\n                http2=http2,\n                uds=uds,\n                local_address=local_address,\n                retries=retries,\n            )\n        else:\n            try:\n                self._pool = httpcore.HTTPProxy(\n                    proxy_url=httpcore.URL(\n                        scheme=proxy.url.raw_scheme,\n                        host=proxy.url.raw_host,\n                        port=proxy.url.port,\n                        target=proxy.url.raw_path,\n                    ),\n                    proxy_headers=proxy.headers.raw,\n                    ssl_context=ssl_context,\n                    max_connections=limits.max_connections,\n                    max_keepalive_connections=limits.max_keepalive_connections,\n                    keepalive_expiry=limits.keepalive_expiry,\n                    http1=http1,\n                    http2=http2,\n                )\n            except TypeError:  # pragma: nocover\n                self._pool = httpcore.HTTPProxy(\n                    proxy_url=httpcore.URL(\n                        scheme=proxy.url.raw_scheme,\n                        host=proxy.url.raw_host,\n                        port=proxy.url.port,\n                        target=proxy.url.raw_path,\n                    ),\n                    proxy_headers=proxy.headers.raw,\n                    ssl_context=ssl_context,\n                    max_connections=limits.max_connections,\n                    max_keepalive_connections=limits.max_keepalive_connections,\n                    keepalive_expiry=limits.keepalive_expiry,\n                )\n\n    def __enter__(self: T) -> T:  # Use generics for subclass support.\n        self._pool.__enter__()\n        return self\n\n    def __exit__(\n        self,\n        exc_type: typing.Type[BaseException] = None,\n        exc_value: BaseException = None,\n        traceback: TracebackType = None,\n    ) -> None:\n        with map_httpcore_exceptions():\n            self._pool.__exit__(exc_type, exc_value, traceback)\n\n    def handle_request(\n        self,\n        request: Request,\n    ) -> Response:\n        assert isinstance(request.stream, SyncByteStream)\n\n        req = httpcore.Request(\n            method=request.method,\n            url=httpcore.URL(\n                scheme=request.url.raw_scheme,\n                host=request.url.raw_host,\n                port=request.url.port,\n                target=request.url.raw_path,\n            ),\n            headers=request.headers.raw,\n            content=request.stream,\n            extensions=request.extensions,\n        )\n        with map_httpcore_exceptions():\n            resp = self._pool.handle_request(req)\n\n        assert isinstance(resp.stream, typing.Iterable)\n\n        return Response(\n            status_code=resp.status,\n            headers=resp.headers,\n            stream=ResponseStream(resp.stream),\n            extensions=resp.extensions,\n        )\n\n    def close(self) -> None:\n        self._pool.close()\n\n\nclass AsyncResponseStream(AsyncByteStream):\n    def __init__(self, httpcore_stream: typing.AsyncIterable[bytes]):\n        self._httpcore_stream = httpcore_stream\n\n    async def __aiter__(self) -> typing.AsyncIterator[bytes]:\n        with map_httpcore_exceptions():\n            async for part in self._httpcore_stream:\n                yield part\n\n    async def aclose(self) -> None:\n        if hasattr(self._httpcore_stream, \"aclose\"):\n            await self._httpcore_stream.aclose()  # type: ignore\n\n\nclass AsyncHTTPTransport(AsyncBaseTransport):\n    def __init__(\n        self,\n        verify: VerifyTypes = True,\n        cert: CertTypes = None,\n        http1: bool = True,\n        http2: bool = False,\n        limits: Limits = DEFAULT_LIMITS,\n        trust_env: bool = True,\n        proxy: Proxy = None,\n        uds: str = None,\n        local_address: str = None,\n        retries: int = 0,\n    ) -> None:\n        ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)\n\n        if proxy is None:\n            self._pool = httpcore.AsyncConnectionPool(\n                ssl_context=ssl_context,\n                max_connections=limits.max_connections,\n                max_keepalive_connections=limits.max_keepalive_connections,\n                keepalive_expiry=limits.keepalive_expiry,\n                http1=http1,\n                http2=http2,\n                uds=uds,\n                local_address=local_address,\n                retries=retries,\n            )\n        else:\n            self._pool = httpcore.AsyncHTTPProxy(\n                proxy_url=httpcore.URL(\n                    scheme=proxy.url.raw_scheme,\n                    host=proxy.url.raw_host,\n                    port=proxy.url.port,\n                    target=proxy.url.raw_path,\n                ),\n                proxy_headers=proxy.headers.raw,\n                ssl_context=ssl_context,\n                max_connections=limits.max_connections,\n                max_keepalive_connections=limits.max_keepalive_connections,\n                keepalive_expiry=limits.keepalive_expiry,\n            )\n\n    async def __aenter__(self: A) -> A:  # Use generics for subclass support.\n        await self._pool.__aenter__()\n        return self\n\n    async def __aexit__(\n        self,\n        exc_type: typing.Type[BaseException] = None,\n        exc_value: BaseException = None,\n        traceback: TracebackType = None,\n    ) -> None:\n        with map_httpcore_exceptions():\n            await self._pool.__aexit__(exc_type, exc_value, traceback)\n\n    async def handle_async_request(\n        self,\n        request: Request,\n    ) -> Response:\n        assert isinstance(request.stream, AsyncByteStream)\n\n        req = httpcore.Request(\n            method=request.method,\n            url=httpcore.URL(\n                scheme=request.url.raw_scheme,\n                host=request.url.raw_host,\n                port=request.url.port,\n                target=request.url.raw_path,\n            ),\n            headers=request.headers.raw,\n            content=request.stream,\n            extensions=request.extensions,\n        )\n        with map_httpcore_exceptions():\n            resp = await self._pool.handle_async_request(req)\n\n        assert isinstance(resp.stream, typing.AsyncIterable)\n\n        return Response(\n            status_code=resp.status,\n            headers=resp.headers,\n            stream=AsyncResponseStream(resp.stream),\n            extensions=resp.extensions,\n        )\n\n    async def aclose(self) -> None:\n        await self._pool.aclose()\n", "path": "httpx/_transports/default.py"}]}