Skip to content

WIP: SOCKS proxy support - #51

Closed
yeraydiazdiaz wants to merge 8 commits into
encode:masterfrom
yeraydiazdiaz:socks-proxy-support
Closed

WIP: SOCKS proxy support#51
yeraydiazdiaz wants to merge 8 commits into
encode:masterfrom
yeraydiazdiaz:socks-proxy-support

Conversation

@yeraydiazdiaz

Copy link
Copy Markdown
Contributor

Adds SOCKS4 proxy support via socksio 🎉

You can test this either locally using Dante via Docker as we do in socksio or simply running an ssh -vND <PORT> <OTHER_MACHINE>, then running the following script, assuming the proxy is running in localhost:1080:

importasyncioimporthttpcoreasyncdefread_body(stream):
try:
body= []
asyncforchunkinstream:
body.append(chunk)
returnb"".join(body)
finally:
awaitstream.aclose()
asyncdefsocks_proxy(proxy_server, proxy_mode):
asyncwithhttpcore.AsyncHTTPProxy(proxy_server, proxy_mode=proxy_mode) ashttp:
method=b"GET"url= (b"http", b"93.184.216.34", 80, b"/")
headers= [(b"host", b"example.org")]
http_version, status_code, reason, headers, stream=awaithttp.request(
method, url, headers
)
body=awaitread_body(stream)
print(body)
asserthttp_version==b"HTTP/1.1"assertstatus_code==200assertreason==b"OK"defmain():
proxy_server= (b'http', b'localhost', 1080)
proxy_mode='SOCKS4'asyncio.run(socks_proxy(proxy_server, proxy_mode))
if__name__=='__main__':
main()

Before I carry on with SOCKS4A and SOCKS5 (or possibly I should open a different PR?) I'd like some feedback.

@yeraydiazdiaz
yeraydiazdiaz requested a review from a teamApril 1, 2020 16:47
origin: Origin,
proxy_origin: Origin,
socks_version: str,
user_id: bytes = b"httpcore",

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required by SOCKS4.

SOCKS5 will require username/password and likely defining acceptable authentication methods. Which makes me think we might want separate AsyncSOCKS4Connection and AsyncSOCKS5Connection.

Comment threadhttpcore/_async/http_proxy.py
@yeraydiazdiaz

Copy link
Copy Markdown
ContributorAuthor

I realize there's a fair bit of cleanup noise as well, sorry about that. Hopefully the important bits are clear.

Comment threadhttpcore/_async/http_proxy.py
@lovelydinosaur

lovelydinosaur commented Apr 30, 2020

Copy link
Copy Markdown
Contributor

Looks like there's now a merge conflict between this and master, that'd need resolving.

Screenshot 2020-04-30 at 10 45 25

@yeraydiazdiaz

Copy link
Copy Markdown
ContributorAuthor

Yep, this branch predates the recent changes regarding proxies.

Will update it soon.

@yeraydiazdiaz

Copy link
Copy Markdown
ContributorAuthor

I think I'll hold off on this until we've decided if proxy modes are something we want at all.

encode/httpx#927 (comment) and encode/httpx#927 (comment)

@lovelydinosaur

Copy link
Copy Markdown
Contributor

SOCKS5 is now supported in 0.14.5 - https://www.encode.io/httpcore/proxies/#socks-proxy-support

(Not sure what we'd want to do about socks4, socks4a)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants

@yeraydiazdiaz@lovelydinosaur@florimondmanca