diff --git a/README.md b/README.md index 9a308c7..cbfb309 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Check the default configuration with all the options [here](./internal/config/de | `--host` | | Proxy host, overrides config | | `--port` | `-p` | Proxy port, overrides config | | `--project` | `-P` | Project name to open directly, or `tmp` for a temporary session | +| `--upstream-proxy` | | Upstream proxy URL, overrides config (e.g. `http://user:pass@host:8888`) | | `--version` | `-v` | Print version and exit | | `--add-default-plugins` | | Add the default plugins to your plugins dir and exit | diff --git a/cmd/spilltea/main.go b/cmd/spilltea/main.go index 2acd629..b0860ad 100644 --- a/cmd/spilltea/main.go +++ b/cmd/spilltea/main.go @@ -7,11 +7,11 @@ import ( "path/filepath" tea "charm.land/bubbletea/v2" + spilltea "github.com/anotherhadi/spilltea" "github.com/anotherhadi/spilltea/internal/config" "github.com/anotherhadi/spilltea/internal/icons" "github.com/anotherhadi/spilltea/internal/intercept" "github.com/anotherhadi/spilltea/internal/keys" - spilltea "github.com/anotherhadi/spilltea" "github.com/anotherhadi/spilltea/internal/style" appUI "github.com/anotherhadi/spilltea/internal/ui/app" homeUI "github.com/anotherhadi/spilltea/internal/ui/home" @@ -27,6 +27,7 @@ func main() { flagPluginsDir = flag.String("plugins-dir", "", "path to plugins dir (overrides config)") flagHost = flag.String("host", "", "proxy host (overrides config)") flagPort = flag.IntP("port", "p", 0, "proxy port (overrides config)") + flagUpstreamProxy = flag.String("upstream-proxy", "", "upstream proxy URL, e.g. http://user:pass@host:8888 (overrides config)") flagVersion = flag.BoolP("version", "v", false, "print version") flagProject = flag.StringP("project", "P", "", `project name to open directly, or "tmp" for a temporary session`) flagAddDefaultPlugins = flag.Bool("add-default-plugins", false, "copy built-in example plugins into the plugins dir and exit") @@ -85,6 +86,9 @@ func main() { if *flagPort != 0 { config.Global.App.Port = *flagPort } + if *flagUpstreamProxy != "" { + config.Global.App.UpstreamProxy = *flagUpstreamProxy + } addr := fmt.Sprintf("%s:%d", config.Global.App.Host, config.Global.App.Port) // Check if the proxy port is available before starting the UI. diff --git a/internal/config/config.go b/internal/config/config.go index eb8af89..8dc2e32 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -18,11 +18,12 @@ type Config struct { Version string `mapstructure:"-"` App struct { - Host string `mapstructure:"host"` - Port int `mapstructure:"port"` - CertDir string `mapstructure:"cert_dir"` - ProjectDir string `mapstructure:"project_dir"` - PluginsDir string `mapstructure:"plugins_dir"` + Host string `mapstructure:"host"` + Port int `mapstructure:"port"` + CertDir string `mapstructure:"cert_dir"` + ProjectDir string `mapstructure:"project_dir"` + PluginsDir string `mapstructure:"plugins_dir"` + UpstreamProxy string `mapstructure:"upstream_proxy"` } `mapstructure:"app"` TUI struct { diff --git a/internal/config/default_config.yaml b/internal/config/default_config.yaml index 139a9bd..d428212 100644 --- a/internal/config/default_config.yaml +++ b/internal/config/default_config.yaml @@ -4,6 +4,7 @@ app: cert_dir: ~/.local/share/spilltea project_dir: ~/.local/share/spilltea plugins_dir: ~/.config/spilltea/plugins + upstream_proxy: "" # e.g. http://corporate-proxy:8888 or http://user:pass@host:8888 intercept: default_intercept_enabled: true diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 353ee52..a01860a 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -108,6 +108,7 @@ func Start(broker *intercept.Broker, mgr *plugins.Manager) error { Addr: addr, StreamLargeBodies: 1024 * 1024 * 5, CaRootPath: caPath, + Upstream: cfg.UpstreamProxy, } p, err := goproxy.NewProxy(opts)