From 306511be1304b33876654332ec7ab59c39dc5e9a Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sun, 8 Sep 2024 21:06:31 +0200 Subject: [PATCH] detecting system proxy config protocols --- proxy/util.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/proxy/util.go b/proxy/util.go index 1984d65..3ead839 100644 --- a/proxy/util.go +++ b/proxy/util.go @@ -72,17 +72,38 @@ func ReadSystemProxy() (*Proxy, error) { } defer key.Close() - enabled, _, err := key.GetIntegerValue("proxyEnable") + enableVal, _, err := key.GetIntegerValue("proxyEnable") if err != nil { return nil, err } + enabled := enableVal != 0 - server, _, err := key.GetStringValue("proxyServer") + servers, _, err := key.GetStringValue("proxyServer") if err != nil && !errors.Is(err, registry.ErrNotExist) { return nil, err } - return &Proxy{Enabled: enabled != 0, Server: server}, nil + if !strings.ContainsAny(servers, ";=") { + return &Proxy{Enabled: enabled, Server: servers}, nil + } + + serverSplit := strings.Split(servers, ";") + serverDict := make(map[string]string) + for _, substr := range serverSplit { + subSplit := strings.Split(substr, "=") + key, value := subSplit[0], subSplit[1] + serverDict[key] = value + } + + if serverDict["http"] != "" { + return &Proxy{Enabled: enabled, Server: serverDict["http"]}, nil + } + + if serverDict["https"] != "" { + return &Proxy{Enabled: enabled, Server: serverDict["https"]}, nil + } + + return nil, errors.New("You need configure either HTTP or HTTPS proxy to proceed.") } func SetSystemProxy(state bool) error {