Compare commits

...
Author SHA1 Message Date
gohumble 726408c80f added isOnionRegex 2022-11-03 09:32:07 +01:00
+9
View File
@@ -6,6 +6,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"regexp"
"time" "time"
"github.com/LightningTipBot/LightningTipBot/internal" "github.com/LightningTipBot/LightningTipBot/internal"
@@ -20,7 +21,15 @@ const (
ClientTypeTor = "tor" ClientTypeTor = "tor"
) )
// checks if strings contains http(s)://*.onion
var isOnion = regexp.MustCompile("^https?\\:\\/\\/[\\w\\-\\.]+\\.onion")
// GetClientForScheme returns correct client for url scheme.
// if tld is .onion, function will also return an onion client.
func GetClientForScheme(url *url.URL) (*http.Client, error) { func GetClientForScheme(url *url.URL) (*http.Client, error) {
if isOnion.FindString(url.String()) != "" {
return GetClient(ClientTypeTor)
}
switch url.Scheme { switch url.Scheme {
case "onion": case "onion":
return GetClient(ClientTypeTor) return GetClient(ClientTypeTor)