diff --git a/README.md b/README.md index 7f034ec..4d6060f 100644 --- a/README.md +++ b/README.md @@ -49,4 +49,3 @@ You can also download images (or technically any other file) using a file called You will need to be running a local `tor` proxy on port `9050` There is very little in the way of graceful error handling, contributions appreciated, please also feel free to submit issues & feature requests. - diff --git a/main.go b/main.go index 8374927..ebc4418 100644 --- a/main.go +++ b/main.go @@ -19,9 +19,27 @@ import ( "time" ) +func makeTorifiedClient() *http.Client { + torDialer, err := proxy.SOCKS5("tcp", "127.0.0.1:9050", nil, proxy.Direct) + if err != nil { + log.Fatalf("Could not connect to Tor Proxy: %v", err) + } + transportConfig := &http.Transport{ + Dial: torDialer.Dial, + } + client := new(http.Client) + client.Transport = transportConfig + client.CheckRedirect = func(r *http.Request, via []*http.Request) error { + r.URL.Opaque = r.URL.Path + return nil + } + return client +} + func fetch(url string, cachepath string) { fmt.Printf("Fetching [%v]\n", url) fp := gofeed.NewParser() + fp.Client = makeTorifiedClient() feed, err := fp.ParseURL(url) fmt.Printf("Feed %v %v\n", feed, err) cache, _ := json.Marshal(feed) @@ -51,17 +69,7 @@ func report() map[string]gofeed.Feed { func download(url string, cachepath string) { fmt.Printf("Fetching [%v]\n", url) - torDialer, err := proxy.SOCKS5("tcp", "127.0.0.1:9050", nil, proxy.Direct) - transportConfig := &http.Transport{ - Dial: torDialer.Dial, - } - client := http.Client{ - Transport: transportConfig, - CheckRedirect: func(r *http.Request, via []*http.Request) error { - r.URL.Opaque = r.URL.Path - return nil - }, - } + client := makeTorifiedClient() resp, err := client.Get(url) if err == nil {