savonrb / httpi

Common interface for Ruby's HTTP clients
http://httpirb.com
MIT License
300 stars 150 forks source link

Enable socks proxy server specification #155

Closed maxdidato closed 9 years ago

maxdidato commented 9 years ago

This will let a user to specify a socks proxy server in order to perform a request via it

rogerleite commented 9 years ago

Thanks @maxdidato ! Closes #154

acegilz commented 8 years ago

how do I define user and password socks5 proxy credentials?

I am using PIA proxy but couldn't find how to connect this, already looking a solution for some days, but still stucked.

https://www.privateinternetaccess.com/forum/discussion/258/private-internet-access-proxy-now-available-now-open

https://github.com/mikecmpbll/betfair/issues/6 https://github.com/astro/socksify-ruby/issues/1#issuecomment-162905681

acegilz commented 8 years ago

looking at the code it appears that socks connection block is only using host and port, while http proxy uses the 4 ( plus username and password)

Please help me I'm really confused on how to settup this socks proxy with credentials.. thanks

maxdidato commented 8 years ago

@acegilz The pull request let the user set a socks server without authentication.

acegilz commented 8 years ago

I see 😕 +1 for authentication support

mikecmpbll commented 8 years ago

I'll take a look at this tonight, I may be able to come up with a PR because I poked around a bit at this area whilst investigating mikecmpbll/betfair#6.

rogerleite commented 8 years ago

@mikecmpbll :+1:

acegilz commented 8 years ago

Thank you so much @mikecmpbll

mikecmpbll commented 8 years ago

the code for socksify is really quite bizarre. anyways, i don't have an authenticated socks proxy which i can test against, but looking at the code you should be able to set the credentials like this:

require 'socksify/http'
uri = URI.parse('http://www.google.com/')
socks_ip = '127.0.0.1' # your socks IP
socks_port = 9050 # your socks port
TCPSocket.socks_username = "username" # socks username
TCPSocket.socks_password = "password" # socks password
Net::HTTP.SOCKSProxy(socks_ip, socks_port).start(uri.host, uri.port) do |http|
  http.get(uri.path)
end

would you be able to test this @acegilz to see if you can get a page via your socks5 proxy? there's also a PR in the works on socksify, astro/socksify-ruby#24, to improve the interface when passing through credentials, which is going to be merged this weekend i understand.

if this works for you, you can actually set the socks_username and socks_password on TCPSocket outside of httpi so you can get up and running immediately. i'll probably wait for the socksify interface to be tidied up before creating a PR here.

acegilz commented 8 years ago

@mikecmpbll :thumbsup:

 => #<Net::HTTPOK 200 OK readbody=true> 
maxdidato commented 8 years ago

@mikecmpbll Thanks