Uh oh!
There was an error while loading. Please reload this page.
Add support for HTTPS proxies (available to trio/asyncio) - #745
Conversation
lovelydinosaur
commented
Aug 30, 2023
Looks like we could do with a docs update here... https://www.encode.io/httpcore/proxies/ We probably want to split "Proxy SSL and HTTP Versions" into "Proxy SSL" which documents the |
lovelydinosaur
commented
Aug 30, 2023
Okay, so attempting to test this... I'm using Installation... $ pip install httpcore trio trustme proxy.pyUse $ python-mtrustmeGeneratedacertificatefor'localhost', '127.0.0.1', '::1'Configureyourservertousethefollowingfiles:
cert=/Users/tomchristie/GitHub/encode/httpcore/server.pemkey=/Users/tomchristie/GitHub/encode/httpcore/server.keyConfigureyourclienttousethefollowingfiles:
cert=/Users/tomchristie/GitHub/encode/httpcore/client.pemRunning the proxy... $ proxy --cert-file server.pem --key-file server.key Make the requests... importsslimporttrioimporthttpcorectx=ssl.create_default_context()
ctx.load_verify_locations('client.pem')
asyncdefmain():
asyncwithhttpcore.AsyncHTTPProxy(proxy_url="http://127.0.0.1:8899/", proxy_ssl_context=ctx) ashttp:
response=awaithttp.request("GET", "https://www.example.com/")
print(response)
response=awaithttp.request("GET", "http://www.example.com/")
print(response)
trio.run(main)Fails with... [...]
ssl.SSLError: [SSL: HTTPS_PROXY_REQUEST] httpsproxyrequest (_ssl.c:992)What am I getting wrong here? |
Also, occurs to me that something we could do here would be decouple this from #732. Indicate in the CHANGELOG/docs that HTTPS proxies are only supported with |
T-256
commented
Aug 30, 2023
I think problem is here: httpcore/httpcore/_async/connection.py Line 140 in f7c515c Where you set |
T-256
commented
Aug 30, 2023
Just change the proxy url scheme to https. |
karpetrosyan
commented
Aug 31, 2023
We should probably merge #732 first, then go over this one. |
lovelydinosaur
commented
Sep 1, 2023
Wonderful thanks, tested now and all working as expected. Okay so, should we add the following error cases here?...
I'd suggest that this PR is neat and uncontentious, so let's work to getting it merged, as "Add support for HTTPS proxies (available to trio/asyncio)". Then follow up with the more awkward sync support. Remaining here is...
|
| ``` | ||
| ## Proxy SSL and HTTP Versions | ||
| ## Proxy SSL |
There was a problem hiding this comment.
These docs are really nice, thanks! 💚
karpetrosyan
commented
Sep 1, 2023
Because most users do not interact with SSL contexts, we can allow this behavior to keep things as simple as possible. When using the public HTTPS proxy, for example, the user must create the default SSL context and pass it to the HTTPProxy class without any modifications or configurations.
Agree |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Tom Christie <tom@tomchristie.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
lovelydinosaur
commented
Sep 1, 2023
Great - No objections to this. Welcome to merge once you're also happy with it @karosis88. |
Refs #722
Related #732 (Required for sync support)
TODO
proxy_ssl_contextargument toAsyncForwardHTTPConnection,AsyncTunnelHTTPConnectionandAsyncHTTPProxyclasses