Skip to content

Commit

Permalink
Validate proxy URL before setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Apr 22, 2024
1 parent 82d5384 commit 646414e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"embed"
"log/slog"
"net/url"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -61,13 +62,22 @@ func main() {
}
}

err = os.Setenv("HTTP_PROXY", settings.Settings.Proxy)
if err != nil {
slog.Error("failed to set HTTP_PROXY", slog.Any("error", err))
}
err = os.Setenv("HTTPS_PROXY", settings.Settings.Proxy)
if err != nil {
slog.Error("failed to set HTTPS_PROXY", slog.Any("error", err))
if settings.Settings.Proxy != "" {
// webkit honors these env vars, even if they are an empty string,
// so we must ensure they are valid
_, err := url.Parse(settings.Settings.Proxy)
if err != nil {
slog.Error("skipping setting proxy, invalid URL", slog.Any("error", err))
} else {
err = os.Setenv("HTTP_PROXY", settings.Settings.Proxy)
if err != nil {
slog.Error("failed to set HTTP_PROXY", slog.Any("error", err))
}
err = os.Setenv("HTTPS_PROXY", settings.Settings.Proxy)
if err != nil {
slog.Error("failed to set HTTPS_PROXY", slog.Any("error", err))
}
}
}

err = ficsitcli.Init()
Expand Down

0 comments on commit 646414e

Please sign in to comment.