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

added SOCKS[45] proxy support #380

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

mumumu
Copy link

@mumumu mumumu commented Sep 29, 2017

Closes #177

added SOCKS[45] proxy support and its client impl, of course including tests with socks[45] server!

Usage is the following.

require 'httpclient'

#  ssh -fN -D 9999 remote_server
clnt = HTTPClient.new('socks4://localhost:9999')

#clnt = HTTPClient.new('socks5://localhost:9999')
#clnt = HTTPClient.new('socks5://username:password@localhost:9999')

#ENV['SOCKS_PROXY'] = 'socks5://localhost:9999'
#clnt = HTTPClient.new

target = 'http://www.example.com/'
puts clnt.get(target).content

target = 'https://www.google.co.jp/'
puts clnt.get(target).content

socks_socket = SOCKS5Socket.new(proxy.host, proxy.port, options)
end
dest_site = Site.new(dest)
opened_socket = socks_socket.open(dest_site.host, dest_site.port, {})

Choose a reason for hiding this comment

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

socks_socket could potentially be nil, probably need to raise above. Also var is defined within if condition, but that might be an acceptable style thing

@mumumu mumumu force-pushed the 177_add_socks_proxy_support branch from e8486e1 to 26e9727 Compare February 4, 2019 20:36
@mumumu mumumu force-pushed the 177_add_socks_proxy_support branch from 26e9727 to 9aeb8e7 Compare February 4, 2019 20:46
@@ -1073,8 +1077,10 @@ def load_environment
# HTTP_* is used for HTTP header information. Unlike open-uri, we
# simply ignore http_proxy in CGI env and use cgi_http_proxy instead.
self.proxy = getenv('cgi_http_proxy')
else
elsif ENV.key?('http_proxy')
Copy link

@ArtsiomVahin ArtsiomVahin Jan 3, 2020

Choose a reason for hiding this comment

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

Would suggest changing this line to elsif getenv('http_proxy') . As it now stands, setting "HTTP_PROXY" does not appear to work anymore, only works with "http_proxy"

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

Successfully merging this pull request may close these issues.

3 participants