feat: support system proxy (#515)

This commit is contained in:
Levi authored and GitHub committed 2024-05-01 18:53:12 +08:00
1 parent 070db64ca9
commit cea454b015
30 files changed
+324 -145

No files matched your search

+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)
}