Skip to content

Add support for https proxies - #80

Merged
tarasko merged 25 commits into
masterfrom
feature/https_proxy_support
Sep 12, 2026
Merged

tarasko merged 25 commits into
masterfrom
feature/https_proxy_support

Conversation

@tarasko

@tarasko tarasko commented Feb 17, 2026

Copy link
Copy Markdown
Owner

No description provided.

@tarasko

tarasko commented Feb 17, 2026

Copy link
Copy Markdown
Owner Author

Although the tests pass, implementation is still a bit ugly. I'll revise this if there is demand for this feature

@oliver-zehentleitner

Copy link
Copy Markdown

Even though using a proxy in a high-performance WebSocket setup feels like a crime to me, this would still be interesting as a websockets replacement. Any updates on this?

@tarasko

tarasko commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

Yes, indeed, would be nice to have it. I'll revisit this branch

@codspeed

codspeed Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by ×2.5

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 3 improved benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_bench_echo[64] 1,101.3 ms 339.2 ms ×3.2
⚡ test_bench_echo[8192] 1,415 ms 533.4 ms ×2.7
⚡ test_bench_echo[32768] 2 s 1.1 s +72.69%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feature/https_proxy_support (55811c8) with master (1480d58)

Open in CodSpeed

@tarasko
tarasko marked this pull request as draft August 4, 2026 11:29
@tarasko

tarasko commented Sep 10, 2026 •

Copy link
Copy Markdown
Owner Author

Currently picows uses python-socks to connect through proxy.

python-socks returns a raw socket that is already connected to the destination host through the proxy.

Unfortunately, this approach doesn't work with HTTPS proxies, because SSLSocket in many ways is not equivalent to raw sockets. Therefore python-socks does not officially support HTTPS proxy.

asyncio has Transport type, which is a better abstraction than raw socket. Transport can be turned into SSLTransport with start_tls.
If only python-socks could return us asyncio.Transport that would make proxy support straightforward for all downstream libraries.

import asyncio
import ssl
from python_socks.async_.asyncio import Proxy

...
proxy = Proxy.from_url("socks5://user:password@127.0.0.1:1080")
sock = await proxy.connect(
        dest_host="check-host.net",
        dest_port=443,
    )

The reason python-socks doesn't not do it is because it is asyncio specific.
python-socks tries to provide identical interface across sync, asyncio, trio and anyio.

There is NO sync equivalent of Transport and trio doesn't have lower level Transport only high-level streams (it seems)

Adding asyncio only
proxy.connect_transport seems to a cleanest solution. But I'm not sure if python-socks authors would do it.
Anyway, I opened an issue

@tarasko

tarasko commented Sep 10, 2026 •

Copy link
Copy Markdown
Owner Author

AI is able to generate a solution based on python-socks for HTTPS but it is an absolute unmaintainable trash full of dirty hacks.

Instead picows will implement its own HTTPProxyConnector protocol. It is trivial and solves the problem.

python-socks will only be used for socks4 and socks5 proxies.

@codecov-commenter

codecov-commenter commented Sep 12, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 90.22989% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.86%. Comparing base (1480d58) to head (55811c8).

Files with missing lines Patch % Lines
picows/proxy.py 89.86% 12 Missing and 3 partials ⚠️
picows/api.py 92.30% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #80      +/-   ##
==========================================
+ Coverage   91.78%   91.86%   +0.07%     
==========================================
  Files          18       19       +1     
  Lines        2667     2777     +110     
  Branches      139      156      +17     
==========================================
+ Hits         2448     2551     +103     
- Misses        176      181       +5     
- Partials       43       45       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tarasko tarasko changed the title Experimental support for https proxies Add support for https proxies Sep 12, 2026
@tarasko
tarasko marked this pull request as ready for review September 12, 2026 22:13
@tarasko tarasko added the v2.3.0 label Sep 12, 2026
@tarasko
tarasko merged commit d5eb524 into master Sep 12, 2026
33 checks passed
@tarasko
tarasko deleted the feature/https_proxy_support branch September 12, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants