You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So the issue with this is that there's no sans-I/O implementation of the SOCKv4 and SOCKSv5 protocols that doesn't require us to add 3 dependencies. The protocols are so simple that I'm actually in favor of writing our own library that has no dependencies.
It'll definitely intersect on the configuration stage on the client but the dispatcher implementation is separate, let's start by getting a sans-I/O implementation of SOCKSv4 and v5 w/o dependencies and go from there.
I actually think that the sans-I/O implementation should be it's own library, maybe on the python-http org, but it can start on one of our personal accounts. Would you like to be the originator or should I create a repo and add you and you can take it from there?
I pushed the initial commit: https://github.com/sethmlarson/socks
Feel free to make massive changes as nothing currently works E2E, it's just a result of me programming a few hours.
I've sent collaborator requests to everyone interested. :)
The repo will live under python-http once we release for the first time!
I wrote a small PoC with httpcore + PySocks with requesting example.com through the local socks5 proxy.
Working with the PoC, I added new method to AsyncioBackend named open_socks_stream (I decided that socks4/5 is a transport for us like tcp, ssl or uds).
If this idea (PySocks and a new method in the backends) works for you, I can start adding socks proxies support to httpcore
@cdeler From what I understand, SOCKS is an application-level protocol that sits on top of TCP (well, there's UDP in SOCKS5, but that's not something we should be thinking about for now), so in theory we shouldn't really need a new type of open_* method on concurrency backends.
Also, since I don't think it's been linked to here yet — @yeraydiazdiaz had started a lovely piece of work on HTTPCore already a few months back, based on the socksio library: encode/httpcore#51. Benefits of socksio is that it's sans-I/O, meaning that we can use it either with sync or async, just like h11 and h2 for HTTP/1.1 and HTTP/2.
So perhaps, if anyone's interested, there'd be room for getting that work up to date. I personally think socksio and the sans-I/O approach is our safest bet there if we want to have an as-simple-and-straightforward-as-possible implementation. :-)
I wonder what we should do with socks4. It enforces us to process nslookup on our side (as socks4 connect do not accept domain names).
Lets imagine that someone wants to access "google.com" through socks4 proxy. What should we do there? To raise a ProxyError with "SOCKS4 protocol do not support domain names as a host address" or make nslookup on our side (does anyone know good nslookup libraries for async?) ?
I wrote a socks library. It has no dependencies and supports sync, async and sans IO usage. I had to write because I want to use over 'unix domain sockets' which none of the other packages supported. (I didn't know about socksio when I wrote but the usage is much simpler). Feel free to depend on it or just copy relevant parts of it.
We've only got SOCKS5 in right now. Not obvs to me how much value there would be in 4/4a, or in SOCKS5 with the IP resolved by the client. Probably makes sense to leave a decision on those pending user feedback.
Our current behaviour is that the proxy resolves the DNS. (socks5h) What we don't have is support for the client resolving the DNS. (Which would be a bit of a pain to add, but do-able. Tho it's not obvious to me what use-case we'd want to support that for.)
Activity
sethmlarson commentedon Aug 27, 2019
So the issue with this is that there's no sans-I/O implementation of the SOCKv4 and SOCKSv5 protocols that doesn't require us to add 3 dependencies. The protocols are so simple that I'm actually in favor of writing our own library that has no dependencies.
yeraydiazdiaz commentedon Sep 2, 2019
I'm happy to lend a hand on this @sethmlarson. Does it depend on #259?
sethmlarson commentedon Sep 2, 2019
Thanks @yeraydiazdiaz! ❤️
It'll definitely intersect on the configuration stage on the client but the dispatcher implementation is separate, let's start by getting a sans-I/O implementation of SOCKSv4 and v5 w/o dependencies and go from there.
I actually think that the sans-I/O implementation should be it's own library, maybe on the python-http org, but it can start on one of our personal accounts. Would you like to be the originator or should I create a repo and add you and you can take it from there?
yeraydiazdiaz commentedon Sep 2, 2019
I'll definitely need some help so it might be easier if it's all setup in non-personal repo from the start 🙂
sethmlarson commentedon Sep 5, 2019
I pushed the initial commit: https://github.com/sethmlarson/socks
Feel free to make massive changes as nothing currently works E2E, it's just a result of me programming a few hours.
I've sent collaborator requests to everyone interested. :)
The repo will live under python-http once we release for the first time!
mIcHyAmRaNe commentedon Apr 10, 2020
while waiting for the implementation, this is a temporary alternative for people who want to use socks4/5 with httpx by using pysocks :
romis2012 commentedon Jul 10, 2020
If it's relevant, there is 3rd party SOCKS implementation: httpx-socks
bbkane commentedon Jul 10, 2020
It looks like that one doesnt support
trio(my favorite async backend).romis2012 commentedon Jul 11, 2020
Trio support added in version 0.2.0
cdeler commentedon Sep 16, 2020
@tomchristie
I wrote a small PoC with
httpcore+PySockswith requestingexample.comthrough the local socks5 proxy.Working with the PoC, I added new method to
AsyncioBackendnamedopen_socks_stream(I decided thatsocks4/5is a transport for us like tcp, ssl or uds).If this idea (
PySocksand a new method in the backends) works for you, I can start adding socks proxies support tohttpcoreflorimondmanca commentedon Sep 16, 2020
@cdeler From what I understand, SOCKS is an application-level protocol that sits on top of TCP (well, there's UDP in SOCKS5, but that's not something we should be thinking about for now), so in theory we shouldn't really need a new type of
open_*method on concurrency backends.Also, since I don't think it's been linked to here yet — @yeraydiazdiaz had started a lovely piece of work on HTTPCore already a few months back, based on the
socksiolibrary: encode/httpcore#51. Benefits ofsocksiois that it's sans-I/O, meaning that we can use it either with sync or async, just likeh11andh2for HTTP/1.1 and HTTP/2.So perhaps, if anyone's interested, there'd be room for getting that work up to date. I personally think
socksioand the sans-I/O approach is our safest bet there if we want to have an as-simple-and-straightforward-as-possible implementation. :-)cdeler commentedon Sep 16, 2020
@florimondmanca
Whoops, I lost that there is a PR in progress...
On one hand you are right, proxy works on L7, but it is a transport for us...
Well in terms of
pysocks, this library provides us with asocket-like interface which wraps a connectionYou can check what I've done here: encode/httpcore#186 (I've created a PR just to show an idea)
I'd like to have a chance to check encode/httpcore#51 :-) Thank you for the advice
Update: looks like @yeraydiazdiaz has the same problem as me with https connection
cdeler commentedon Sep 17, 2020
@florimondmanca you are right,
socksiois really better, since it allows us implement the code on connection-level. I closed encode/httpcore#186 (withPySock) and opened encode/httpcore#187 (socksio) draftcdeler commentedon Sep 21, 2020
I wonder what we should do with
socks4. It enforces us to processnslookupon our side (assocks4connect do not accept domain names).Lets imagine that someone wants to access
"google.com"through socks4 proxy. What should we do there? To raise aProxyErrorwith "SOCKS4 protocol do not support domain names as a host address" or makenslookupon our side (does anyone know good nslookup libraries forasync?) ?romis2012 commentedon Sep 21, 2020
Some socks5 servers also don't support DNS resolving. On the other hand, some socks4 servers support it.
See how it is implemented in python-socks which httpx-socks is based on. For asyncio backend you can also use aiodns.
KOLANICH commentedon Jan 18, 2021
python-hyper/hyper#441 may be related (though it is for hyper)
jacklanda commentedon Jan 20, 2021
Thank u and hope the implementation will come up to soon
balki commentedon Apr 11, 2021
I wrote a socks library. It has no dependencies and supports sync, async and sans IO usage. I had to write because I want to use over 'unix domain sockets' which none of the other packages supported. (I didn't know about socksio when I wrote but the usage is much simpler). Feel free to depend on it or just copy relevant parts of it.
lovelydinosaur commentedon Jan 20, 2022
Alrighty - closed via encode/httpcore#478 and #2034 using Seth's fantastic
socksiopackage.We've only got SOCKS5 in right now. Not obvs to me how much value there would be in 4/4a, or in SOCKS5 with the IP resolved by the client. Probably makes sense to leave a decision on those pending user feedback.
lovelydinosaur commentedon Jan 20, 2022
Correct. That is the current setup.
lovelydinosaur commentedon Jan 20, 2022
That seems like something that's a valid enough use-case to open an issue for. You'd be very welcome to do that, and reference this comment.
I had a quick read up about this to educate myself, and found this blog post to be pretty helpful.
lovelydinosaur commentedon Jan 20, 2022
That would probably be a nice feature / change in behaviour to have, yup, but it's a little bit involved to implement.
lovelydinosaur commentedon Jan 20, 2022
Sorry - slow me down I'm being a bit stupid.
Our current behaviour is that the proxy resolves the DNS. (
socks5h) What we don't have is support for the client resolving the DNS. (Which would be a bit of a pain to add, but do-able. Tho it's not obvious to me what use-case we'd want to support that for.)