headzoo / surf

Stateful programmatic web browsing in Go.
MIT License
1.48k stars 159 forks source link

Tor socks proxy support #56

Closed shavit closed 7 years ago

shavit commented 7 years ago

To use the proxy use the Tor(url *url.URL) (err error) method

var err error
bow := surf.NewBrowser()
//err:= bow.Open("http://check.torproject.org")
//  if err != nil {
//    panic(err)
//  }
// Without proxy: Sorry. You are not using Tor.
//fmt.Println(bow.Title())

// With proxy: Congratulations. This browser is configured to use Tor.
u, _ := url.Parse("socks5://127.0.0.1:9050")
bow.Tor(u)
err = bow.Open("http://check.torproject.org")
  if err != nil {
   panic(err)
 }
fmt.Println(bow.Title())
lxt2 commented 7 years ago

I'm reluctant to add a Tor specific method when there is already possible via SetTransport. Perhaps this could be a SetProxy instead?

shavit commented 7 years ago

Yes, see https://github.com/headzoo/surf/pull/56/commits/5948ff4af84a1e94b415912849b696c8f8526a52

headzoo commented 7 years ago

My only reservation is passing a *url.URL to SetProxy() instead of a string like the other methods which take a url.

shavit commented 7 years ago

ok, see https://github.com/headzoo/surf/pull/56/commits/06b521e6b9a8326064e6304f33fbcb8ede384e20

headzoo commented 7 years ago

Thanks, looks good to me. I'll wait on @lxt2 so we can merge a bunch of these pull requests at once into one patch release. Should be soon.

lxt2 commented 7 years ago

Moving to #72.