Repository: encode/httpx

Issue:
SSL handshake failed on verifying the certificate
**im using charlesproxy for debugging each requests. Proxy ip and cert is from charlesproxy**

My code:
```
import httpx
client = httpx.Client(proxies={
    "http": "http://192.168.1.78:8888",
    "https": "http://192.168.1.78:8888",

})


client_cer = r'C:\Users\localhost\Documents\123.pem'
request = client.get("http://whoer.net",verify=client_cer)


```
output
```

SSL handshake failed on verifying the certificate
protocol: <asyncio.sslproto.SSLProtocol object at 0x0000020CDCD7E470>
transport: <_SelectorSocketTransport fd=768 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 625, in _on_handshake_complete
    raise handshake_exc
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x0000020CDCD7E470>
transport: <_SelectorSocketTransport closing fd=768 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
Traceback (most recent call last):
  File "C:/Users/localhost/PycharmProjects/TribalW_Test_Env/Basic/tests/httpx/proxy_test.py", line 11, in <module>
    request = client.get("http://whoer.net",headers=headers,verify=client_cer)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 818, in get
    proxies=proxies,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 729, in request
    proxies=proxies,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 760, in send
    async_response = concurrency_backend.run(coroutine, *args, **kwargs)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\concurrency\asyncio.py", line 241, in run
    return self.loop.run_until_complete(coroutine(*args, **kwargs))
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 584, in run_until_complete
    return future.result()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 230, in _get_response
    return await get_response(request)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\middleware\redirect.py", line 41, in __call__
    return await self(next_request, get_response)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\middleware\redirect.py", line 31, in __call__
    response = await get_response(request)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 191, in get_response
    request, verify=verify, cert=cert, timeout=timeout
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 243, in send
    request=request, verify=verify, cert=cert, timeout=timeout
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\connection_pool.py", line 118, in send
    connection = await self.acquire_connection(origin=request.url.origin)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 92, in acquire_connection
    return await self.tunnel_connection(origin)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 110, in tunnel_connection
    await self.tunnel_start_tls(origin, connection)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 194, in tunnel_start_tls
    timeout=timeout,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\concurrency\asyncio.py", line 216, in start_tls
    timeout=timeout.connect_timeout,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\tasks.py", line 416, in wait_for
    return fut.result()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 1134, in start_tls
    await waiter
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
```









Discussion:
Don't think I can help a lot here, but for info here's how we derive the CA bundle in `config.py`:

https://github.com/encode/httpx/blob/c9810a79d9c61583165e9aa237d1ac039086f3a8/httpx/config.py#L121-L134

To help debug this, can you make sure the program goes through L129 with the certificate you mentioned? I assume it does, because `verify` is obviously not a `bool`, and if it didn't find your certificate you'd get the `IOError`, but maybe we're don't correctly pass `verify` along to `self.verify` there.
how i can make sure my code is going through line 129 with my client_cer variable? Im not experienced coding but if you tell me i can test it.


Could you try running that script with HTTPX_DEBUG=1 set as an environment variable?
I can't see why TLS would be getting used unless the website is redirecting to HTTPS.

I'm guessing your proxy configuration generates a certificate for the HTTPS host on the fly and that cert you're passing is the cert to trust that self signed cert?
> 
> 
> Could you try running that script with HTTPX_DEBUG=1 set as an environment variable?
> I can't see why TLS would be getting used unless the website is redirecting to HTTPS.
> 
> I'm guessing your proxy configuration generates a certificate for the HTTPS host on the fly and that cert you're passing is the cert to trust that self signed cert?

like these?

`request = client.get("http://whoer.net",headers=headers,verify=client_cer,HTTPX_DEBUG=1)`

`TypeError: get() got an unexpected keyword argument 'HTTPX_DEBUG'
`

yes it generates one certificate thath is signed by charlesproxy so you can sniff all calls using charlesproxy mitm proxy and see there



Like this: `$ HTTPX_DEBUG=1 python run_script.py` from the command line. 
i dont know if i did it good

i did in windows machine, i can send you certificate if you want or whatever.

cmd /c "set HTTPX_DEBUG=1 && python  C:\Users\localhost\PycharmProjects\TribalW_Test_Env\Basic\tests\httpx\proxy_test.py"


@sethmlarson 


```

C:\Users\localhost\PycharmProjects\TribalW_Test_Env\Basic\network\client>cmd /c "set HTTPX_DEBUG=1 && python  C:\Users\localhost\PycharmProjects\TribalW_Test_Env\Basic\tests\httpx\proxy_test.py"
SSL handshake failed on verifying the certificate
protocol: <asyncio.sslproto.SSLProtocol object at 0x000001261B0329E8>
transport: <_SelectorSocketTransport fd=636 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 625, in _on_handshake_complete
    raise handshake_exc
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x000001261B0329E8>
transport: <_SelectorSocketTransport closing fd=636 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
Traceback (most recent call last):
  File "C:\Users\localhost\PycharmProjects\TribalW_Test_Env\Basic\tests\httpx\proxy_test.py", line 11, in <module>
    request = client.get("http://whoer.net",headers=headers,verify=client_cer)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 818, in get
    proxies=proxies,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 729, in request
    proxies=proxies,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 760, in send
    async_response = concurrency_backend.run(coroutine, *args, **kwargs)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\concurrency\asyncio.py", line 241, in run
    return self.loop.run_until_complete(coroutine(*args, **kwargs))
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 584, in run_until_complete
    return future.result()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 230, in _get_response
    return await get_response(request)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\middleware\redirect.py", line 41, in __call__
    return await self(next_request, get_response)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\middleware\redirect.py", line 31, in __call__
    response = await get_response(request)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 191, in get_response
    request, verify=verify, cert=cert, timeout=timeout
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 243, in send
    request=request, verify=verify, cert=cert, timeout=timeout
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\connection_pool.py", line 118, in send
    connection = await self.acquire_connection(origin=request.url.origin)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 92, in acquire_connection
    return await self.tunnel_connection(origin)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 110, in tunnel_connection
    await self.tunnel_start_tls(origin, connection)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 194, in tunnel_start_tls
    timeout=timeout,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\concurrency\asyncio.py", line 216, in start_tls
    timeout=timeout.connect_timeout,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\tasks.py", line 416, in wait_for
    return fut.result()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 1134, in start_tls
    await waiter
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)

C:\Users\localhost\PycharmProjects\TribalW_Test_Env\Basic\network\client>

```
Hmm, you should be seeing some debug messages. Do you have the latest version of HTTPX installed? (Try `python -m pip freeze` and paste the output)

Maybe try `setx HTTPX_DEBUG=1` then run the `python` command?
now yes
now worked good the debug and yes im using last httpx version i updated 7h ago with pip install httpx - upgrade when you tell me proxy support was shipped :)

```

04:23:35.687 - httpx.dispatch.proxy_http - forward_connection proxy_url=URL('http://192.168.1.78:8888') origin=Origin(scheme='http' host='192.168.1.78' port=8888)
04:23:35.687 - httpx.dispatch.connection_pool - acquire_connection origin=Origin(scheme='http' host='192.168.1.78' port=8888)
04:23:35.688 - httpx.dispatch.connection_pool - new_connection connection=HTTPConnection(origin=Origin(scheme='http' host='192.168.1.78' port=8888))
04:23:35.689 - httpx.dispatch.connection - start_connect host='192.168.1.78' port=8888 timeout=TimeoutConfig(timeout=5.0)
04:23:35.690 - httpx.dispatch.connection - connected http_version='HTTP/1.1'
04:23:35.690 - httpx.dispatch.http11 - send_headers method='GET' target='http://whoer.net' headers=Headers({'host': 'whoer.net', 'user-agent': 'python-httpx/0.7.3', 'accept': '*/*', 'accept-encoding': 'gzip, deflate, br', 'connection': 'keep-alive'})
04:23:35.691 - httpx.dispatch.http11 - receive_event event=NEED_DATA
04:23:35.774 - httpx.dispatch.http11 - receive_event event=Response(status_code=301, headers=[(b'date', b'Tue, 24 Sep 2019 02:23:36 GMT'), (b'transfer-encoding', b'chunked'), (b'cache-control', b'max-age=3600'), (b'expires', b'Tue, 24 Sep 2019 03:23:36 GMT'), (b'location', b'https://whoer.net/'), (b'vary', b'Accept-Encoding'), (b'server', b'cloudflare'), (b'cf-ray', b'51b14c1b4f9dc67f-MAD'), (b'connection', b'keep-alive')], http_version=b'1.1', reason=b'Moved Permanently')
04:23:35.776 - httpx.dispatch.proxy_http - tunnel_connection proxy_url=URL('http://192.168.1.78:8888') origin=Origin(scheme='https' host='whoer.net' port=443)
04:23:35.778 - httpx.dispatch.connection - start_connect host='192.168.1.78' port=8888 timeout=TimeoutConfig(timeout=5.0)
04:23:35.780 - httpx.dispatch.connection - connected http_version='HTTP/1.1'
04:23:35.780 - httpx.dispatch.http11 - send_headers method='CONNECT' target='whoer.net:443' headers=Headers({'host': '192.168.1.78:8888', 'user-agent': 'python-httpx/0.7.3', 'accept-encoding': 'gzip, deflate, br', 'connection': 'keep-alive', 'accept': '*/*'})
04:23:35.781 - httpx.dispatch.http11 - receive_event event=NEED_DATA
04:23:35.798 - httpx.dispatch.http11 - receive_event event=Response(status_code=200, headers=[], http_version=b'1.1', reason=b'Connection established')
04:23:35.799 - httpx.dispatch.proxy_http - tunnel_response proxy_url=URL('http://192.168.1.78:8888') origin=Origin(scheme='https' host='whoer.net' port=443) response=<Response [200 OK]>
04:23:35.801 - httpx.dispatch.http11 - receive_event event=PAUSED
04:23:35.825 - httpx.dispatch.proxy_http - tunnel_start_tls proxy_url=URL('http://192.168.1.78:8888') origin=Origin(scheme='https' host='whoer.net' port=443)
SSL handshake failed on verifying the certificate
protocol: <asyncio.sslproto.SSLProtocol object at 0x000001F3546149E8>
transport: <_SelectorSocketTransport fd=496 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 625, in _on_handshake_complete
    raise handshake_exc
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x000001F3546149E8>
transport: <_SelectorSocketTransport closing fd=496 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)
Traceback (most recent call last):
  File "C:\Users\localhost\PycharmProjects\TribalW_Test_Env\Basic\tests\httpx\proxy_test.py", line 11, in <module>
    request = client.get("http://whoer.net",headers=headers,verify=client_cer)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 818, in get
    proxies=proxies,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 729, in request
    proxies=proxies,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 760, in send
    async_response = concurrency_backend.run(coroutine, *args, **kwargs)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\concurrency\asyncio.py", line 241, in run
    return self.loop.run_until_complete(coroutine(*args, **kwargs))
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 584, in run_until_complete
    return future.result()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 230, in _get_response
    return await get_response(request)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\middleware\redirect.py", line 41, in __call__
    return await self(next_request, get_response)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\middleware\redirect.py", line 31, in __call__
    response = await get_response(request)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\client.py", line 191, in get_response
    request, verify=verify, cert=cert, timeout=timeout
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 243, in send
    request=request, verify=verify, cert=cert, timeout=timeout
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\connection_pool.py", line 118, in send
    connection = await self.acquire_connection(origin=request.url.origin)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 92, in acquire_connection
    return await self.tunnel_connection(origin)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 110, in tunnel_connection
    await self.tunnel_start_tls(origin, connection)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\dispatch\proxy_http.py", line 194, in tunnel_start_tls
    timeout=timeout,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\site-packages\httpx\concurrency\asyncio.py", line 216, in start_tls
    timeout=timeout.connect_timeout,
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\tasks.py", line 416, in wait_for
    return fut.result()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 1134, in start_tls
    await waiter
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "C:\Users\localhost\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 763, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)

```
Okay, so it's failing on the `tunnel_start_tls` which is good because that is what I figured what was happening. :) Now we just have to figure out why the `SSLContext` isn't trusting the self-signed certificate despite you configuring it that way.

I've got charles proxy downloaded now, this will be a great resource when developing for proxies in the future. :) I'll see if I can resolve it locally and then reply back here! Thanks for all the help you're giving here :bowing_man: 
Figured it out! PR will be incoming soon! :)

Resolving patch:
diff --git a/httpx/client.py b/httpx/client.py
--- a/httpx/client.py
+++ b/httpx/client.py
@@ -107,13 +107,6 @@ def __init__(
         else:
             self.base_url = URL(base_url)
 
-        if proxies is None and trust_env:
-            proxies = typing.cast(ProxiesTypes, get_environment_proxies())
-
-        self.proxies: typing.Dict[str, AsyncDispatcher] = _proxies_to_dispatchers(
-            proxies
-        )
-
         if params is None:
             params = {}
 
@@ -125,6 +118,20 @@ def __init__(
         self.dispatch = async_dispatch
         self.concurrency_backend = backend
 
+        if proxies is None and trust_env:
+            proxies = typing.cast(ProxiesTypes, get_environment_proxies())
+
+        self.proxies: typing.Dict[str, AsyncDispatcher] = _proxies_to_dispatchers(
+            proxies,
+            verify=verify,
+            cert=cert,
+            timeout=timeout,
+            http_versions=http_versions,
+            pool_limits=pool_limits,
+            backend=backend,
+            trust_env=trust_env,
+        )
+
     @property
     def headers(self) -> Headers:
         return self._headers
@@ -196,16 +203,11 @@ async def _get_response(
         cert: CertTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         if request.url.scheme not in ("http", "https"):
             raise InvalidURL('URL scheme must be "http" or "https".')
 
-        if proxies is not None:
-            dispatch_proxies = _proxies_to_dispatchers(proxies)
-        else:
-            dispatch_proxies = self.proxies
-        dispatch = self._dispatcher_for_request(request, dispatch_proxies)
+        dispatch = self._dispatcher_for_request(request, self.proxies)
 
         async def get_response(request: AsyncRequest) -> AsyncResponse:
             try:
@@ -351,7 +353,6 @@ async def get(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         return await self.request(
             "GET",
@@ -366,7 +367,6 @@ async def get(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     async def options(
@@ -383,7 +383,6 @@ async def options(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         return await self.request(
             "OPTIONS",
@@ -398,7 +397,6 @@ async def options(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     async def head(
@@ -415,7 +413,6 @@ async def head(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         return await self.request(
             "HEAD",
@@ -430,7 +427,6 @@ async def head(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     async def post(
@@ -450,7 +446,6 @@ async def post(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         return await self.request(
             "POST",
@@ -468,7 +463,6 @@ async def post(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     async def put(
@@ -488,7 +482,6 @@ async def put(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         return await self.request(
             "PUT",
@@ -506,7 +499,6 @@ async def put(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     async def patch(
@@ -526,7 +518,6 @@ async def patch(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         return await self.request(
             "PATCH",
@@ -544,7 +535,6 @@ async def patch(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     async def delete(
@@ -564,7 +554,6 @@ async def delete(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         return await self.request(
             "DELETE",
@@ -582,7 +571,6 @@ async def delete(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     async def request(
@@ -603,7 +591,6 @@ async def request(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         request = self.build_request(
             method=method,
@@ -624,7 +611,6 @@ async def request(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
         return response
 
@@ -639,7 +625,6 @@ async def send(
         cert: CertTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> AsyncResponse:
         return await self._get_response(
             request=request,
@@ -650,7 +635,6 @@ async def send(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     async def close(self) -> None:
@@ -729,7 +713,6 @@ def request(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         request = self.build_request(
             method=method,
@@ -750,7 +733,6 @@ def request(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
         return response
 
@@ -765,7 +747,6 @@ def send(
         cert: CertTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         concurrency_backend = self.concurrency_backend
 
@@ -779,7 +760,6 @@ def send(
             "cert": cert,
             "timeout": timeout,
             "trust_env": trust_env,
-            "proxies": proxies,
         }
         async_response = concurrency_backend.run(coroutine, *args, **kwargs)
 
@@ -824,7 +804,6 @@ def get(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         return self.request(
             "GET",
@@ -839,7 +818,6 @@ def get(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     def options(
@@ -856,7 +834,6 @@ def options(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         return self.request(
             "OPTIONS",
@@ -871,7 +848,6 @@ def options(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     def head(
@@ -888,7 +864,6 @@ def head(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         return self.request(
             "HEAD",
@@ -903,7 +878,6 @@ def head(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     def post(
@@ -923,7 +897,6 @@ def post(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         return self.request(
             "POST",
@@ -941,7 +914,6 @@ def post(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     def put(
@@ -961,7 +933,6 @@ def put(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         return self.request(
             "PUT",
@@ -979,7 +950,6 @@ def put(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     def patch(
@@ -999,7 +969,6 @@ def patch(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         return self.request(
             "PATCH",
@@ -1017,7 +986,6 @@ def patch(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     def delete(
@@ -1037,7 +1005,6 @@ def delete(
         verify: VerifyTypes = None,
         timeout: TimeoutTypes = None,
         trust_env: bool = None,
-        proxies: ProxiesTypes = None,
     ) -> Response:
         return self.request(
             "DELETE",
@@ -1055,7 +1022,6 @@ def delete(
             cert=cert,
             timeout=timeout,
             trust_env=trust_env,
-            proxies=proxies,
         )
 
     def close(self) -> None:
@@ -1074,16 +1040,32 @@ def __exit__(
         self.close()
 
 
-def _proxy_from_url(url: URLTypes) -> AsyncDispatcher:
-    url = URL(url)
-    if url.scheme in ("http", "https"):
-        return HTTPProxy(url)
-    raise ValueError(f"Unknown proxy for {url!r}")
-
-
 def _proxies_to_dispatchers(
-    proxies: typing.Optional[ProxiesTypes]
+    proxies: typing.Optional[ProxiesTypes],
+    verify: VerifyTypes,
+    cert: typing.Optional[CertTypes],
+    timeout: TimeoutTypes,
+    http_versions: typing.Optional[HTTPVersionTypes],
+    pool_limits: PoolLimits,
+    backend: ConcurrencyBackend,
+    trust_env: bool,
 ) -> typing.Dict[str, AsyncDispatcher]:
+    def _proxy_from_url(url: URLTypes) -> AsyncDispatcher:
+        nonlocal verify, cert, timeout, http_versions, pool_limits, backend, trust_env
+        url = URL(url)
+        if url.scheme in ("http", "https"):
+            return HTTPProxy(
+                url,
+                verify=verify,
+                cert=cert,
+                timeout=timeout,
+                pool_limits=pool_limits,
+                backend=backend,
+                trust_env=trust_env,
+                http_versions=http_versions,
+            )
+        raise ValueError(f"Unknown proxy for {url!r}")
+
     if proxies is None:
         return {}
     elif isinstance(proxies, (str, URL)):
diff --git a/httpx/dispatch/proxy_http.py b/httpx/dispatch/proxy_http.py
--- a/httpx/dispatch/proxy_http.py
+++ b/httpx/dispatch/proxy_http.py
@@ -7,6 +7,7 @@
     DEFAULT_POOL_LIMITS,
     DEFAULT_TIMEOUT_CONFIG,
     CertTypes,
+    HTTPVersionTypes,
     PoolLimits,
     SSLConfig,
     TimeoutTypes,
@@ -51,8 +52,10 @@ def __init__(
         proxy_mode: HTTPProxyMode = HTTPProxyMode.DEFAULT,
         verify: VerifyTypes = True,
         cert: CertTypes = None,
+        trust_env: bool = None,
         timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
         pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,
+        http_versions: HTTPVersionTypes = None,
         backend: ConcurrencyBackend = None,
     ):
 
@@ -62,6 +65,8 @@ def __init__(
             timeout=timeout,
             pool_limits=pool_limits,
             backend=backend,
+            trust_env=trust_env,
+            http_versions=http_versions,
         )
 
         self.proxy_url = URL(proxy_url)


Test patch:
diff --git a/tests/client/test_proxies.py b/tests/client/test_proxies.py
--- a/tests/client/test_proxies.py
+++ b/tests/client/test_proxies.py
@@ -27,3 +27,22 @@ def test_proxies_parameter(proxies, expected_proxies):
         assert client.proxies[proxy_key].proxy_url == url
 
     assert len(expected_proxies) == len(client.proxies)
+
+
+def test_proxies_has_same_properties_as_dispatch():
+    client = httpx.AsyncClient(proxies="http://127.0.0.1")
+    pool = client.dispatch
+    proxy = client.proxies["all"]
+
+    assert isinstance(pool, httpx.ConnectionPool)
+    assert isinstance(proxy, httpx.HTTPProxy)
+
+    for prop in [
+        "verify",
+        "cert",
+        "timeout",
+        "pool_limits",
+        "http_versions",
+        "backend",
+    ]:
+        assert getattr(pool, prop) == getattr(proxy, prop)