This commit is contained in:
liwei
2024-05-01 18:35:32 +08:00
parent 070db64ca9
commit f8ea009fe9
6 changed files with 27 additions and 12 deletions
+12
View File
@@ -2,6 +2,7 @@ package util
import (
"encoding/base64"
"net/http"
"net/url"
"regexp"
"strings"
@@ -51,3 +52,14 @@ func BuildProxyUrl(scheme, host, usr, pwd string) *url.URL {
Host: host,
}
}
// ProxyUrlToHandler gets the proxy handler from the proxy url.
func ProxyUrlToHandler(proxyUrl *url.URL) func(*http.Request) (*url.URL, error) {
if proxyUrl == nil {
return nil
}
if proxyUrl.Scheme == "system" {
return http.ProxyFromEnvironment
}
return http.ProxyURL(proxyUrl)
}