Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socks proxy support for net/http #992

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Socks proxy support for net/http #992

wants to merge 8 commits into from

Conversation

technoweenie
Copy link
Member

This patches in SOCKS proxy support for the net/http adapter, using this snippet by @yarafan: #787 (comment).

I don't want to add the socksify gem as a required gem dependency for faraday. The net/http adapter attempts to load it, but only complains if you try to use a socks proxy:

$ irb -Ilib
>> require 'faraday'
=> true
>> Faraday.new(proxy: 'socks://127.0.0.1:6000').get('http://example.com').status
=> RuntimeError (SOCKS proxy support requires the socksify gem ~> 1.7.1)

$ gem install socksify
$ irb -Ilib
>> require 'faraday'
=> true
>> Faraday.new(proxy: 'socks://127.0.0.1:6000').get('http://example.com').status
Faraday::ConnectionFailed (Failed to open TCP connection to 127.0.0.1:6000 (Connection refused - connect(2) for "127.0.0.1" port 6000))

This behavior is difficult to test with rspec, so I tested this in the integration test suite faraday-live.

Fixes #787

@technoweenie
Copy link
Member Author

While the original patch passed my integration tests (technoweenie/faraday-live#7), I didn't like how the username and password were set:

      TCPSocket.socks_username = proxy[:user] if proxy[:user]
      TCPSocket.socks_password = proxy[:password] if proxy[:password]
      Net::HTTP::SOCKSProxy(proxy[:uri].host, proxy[:uri].port)

A global (or at-best, a thread local) socks username/pass doesn't seem very safe. I rewrote this to use the socksify maintainer's PR to support proxy authentication: astro/socksify-ruby#33

Copy link
Member

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

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

Nice implementation and great opportunity to also rewrite some old code in a much better way.
Ignoring Code Climate issues for the reasons explained in the comment above.

@technoweenie technoweenie mentioned this pull request Jun 25, 2019
3 tasks
@iMacTia
Copy link
Member

iMacTia commented Jul 4, 2019

For future visitors, this change is technically good to go but is waiting for astro/socksify-ruby#33 to be merged.

@iMacTia iMacTia added the blocked Blocked by external dependencies label Oct 14, 2020
@vizv
Copy link

vizv commented Jan 26, 2022

This takes forever 😅

@iMacTia
Copy link
Member

iMacTia commented Jan 26, 2022

Cross-dependencies with other libraries 🙈.
We have been chasing on astro/socksify-ruby#33, but to no avail 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Blocked by external dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Faraday and socks proxy with auth supporting
5 participants