diff options
author | FChannel <> | 2022-05-08 14:57:40 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 580dec5b89215310ce34341e11ff17fe38bdb63a (patch) | |
tree | 894424df66a9d9f7e41805822f29adac8fb490fe /util/proxy.go | |
parent | f7bf818d29393ceaccf4d2906557351fa6a4f49f (diff) |
more cleanup, logging and error logging everywhere
things are mostly in place can work on "features" and polish
Diffstat (limited to 'util/proxy.go')
-rw-r--r-- | util/proxy.go | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/util/proxy.go b/util/proxy.go index 0f4a648..daa90b5 100644 --- a/util/proxy.go +++ b/util/proxy.go @@ -9,27 +9,11 @@ import ( "github.com/FChannel0/FChannel-Server/config" ) -func RouteProxy(req *http.Request) (*http.Response, error) { - var proxyType = GetPathProxyType(req.URL.Host) - - if proxyType == "tor" { - proxyUrl, err := url.Parse("socks5://" + config.TorProxy) - if err != nil { - return nil, err - } - - proxyTransport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)} - client := &http.Client{Transport: proxyTransport, Timeout: time.Second * 15} - return client.Do(req) - } - - return http.DefaultClient.Do(req) -} - func GetPathProxyType(path string) string { if config.TorProxy != "" { re := regexp.MustCompile(`(http://|http://)?(www.)?\w+\.onion`) onion := re.MatchString(path) + if onion { return "tor" } @@ -40,17 +24,35 @@ func GetPathProxyType(path string) string { func MediaProxy(url string) string { re := regexp.MustCompile("(.+)?" + config.Domain + "(.+)?") - if re.MatchString(url) { return url } re = regexp.MustCompile("(.+)?\\.onion(.+)?") - if re.MatchString(url) { return url } config.MediaHashs[HashMedia(url)] = url + return "/api/media?hash=" + HashMedia(url) } + +func RouteProxy(req *http.Request) (*http.Response, error) { + var proxyType = GetPathProxyType(req.URL.Host) + + if proxyType == "tor" { + proxyUrl, err := url.Parse("socks5://" + config.TorProxy) + + if err != nil { + return nil, MakeError(err, "RouteProxy") + } + + proxyTransport := &http.Transport{Proxy: http.ProxyURL(proxyUrl)} + client := &http.Client{Transport: proxyTransport, Timeout: time.Second * 15} + + return client.Do(req) + } + + return http.DefaultClient.Do(req) +} |