diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 2b65a1f..ba56b2f 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -22,7 +22,7 @@ }, { "ImportPath": "github.com/gorilla/websocket", - "Rev": "b6ab76f1fe9803ee1d59e7e5b2a797c1fe897ce5" + "Rev": "5c91b59efa232fa9a87b705d54101832c498a172" }, { "ImportPath": "github.com/jtolds/gls", diff --git a/cmd/gotty-client/main.go b/cmd/gotty-client/main.go index da45fa9..457d0e7 100644 --- a/cmd/gotty-client/main.go +++ b/cmd/gotty-client/main.go @@ -25,7 +25,7 @@ func main() { app.ArgsUsage = "GOTTY_URL" app.BashComplete = func(c *cli.Context) { for _, command := range []string{ - "--debug", "--skip-tls-verify", "--help", + "--debug", "--skip-tls-verify", "--use-proxy-from-env", "--help", "--generate-bash-completion", "--version", "http://user:pass@host:1234/path/\\\\?arg=abcdef\\\\&arg=ghijkl", "https://user:pass@host:1234/path/\\\\?arg=abcdef\\\\&arg=ghijkl", @@ -46,6 +46,11 @@ func main() { Usage: "Skip TLS verify", EnvVar: "SKIP_TLS_VERIFY", }, + cli.BoolFlag{ + Name: "use-proxy-from-env", + Usage: "Use Proxy from environment", + EnvVar: "USE_PROXY_FROM_ENV", + }, } app.Action = Action @@ -77,6 +82,10 @@ func Action(c *cli.Context) { client.SkipTLSVerify = true } + if c.Bool("use-proxy-from-env") { + client.UseProxyFromEnv = true + } + // loop if err = client.Loop(); err != nil { logrus.Fatalf("Communication error: %v", err) diff --git a/gotty-client.go b/gotty-client.go index e38c259..b6d2a63 100644 --- a/gotty-client.go +++ b/gotty-client.go @@ -73,15 +73,16 @@ func GetWebsocketURL(httpURL string) (*url.URL, *http.Header, error) { } type Client struct { - Dialer *websocket.Dialer - Conn *websocket.Conn - URL string - WriteMutex *sync.Mutex - Output io.Writer - QuitChan chan struct{} - QuitChanClosed bool - SkipTLSVerify bool - Connected bool + Dialer *websocket.Dialer + Conn *websocket.Conn + URL string + WriteMutex *sync.Mutex + Output io.Writer + QuitChan chan struct{} + QuitChanClosed bool + SkipTLSVerify bool + UseProxyFromEnv bool + Connected bool } type querySingleType struct { @@ -105,12 +106,15 @@ func (c *Client) GetAuthToken() (string, error) { logrus.Debugf("Fetching auth token auth-token: %q", target.String()) req, err := http.NewRequest("GET", target.String(), nil) req.Header = *header - client := http.Client{} + tr := &http.Transport{} if c.SkipTLSVerify { - client.Transport = &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - } + conf := &tls.Config{InsecureSkipVerify: true} + tr.TLSClientConfig = conf } + if c.UseProxyFromEnv { + tr.Proxy = http.ProxyFromEnvironment + } + client := &http.Client{Transport: tr} resp, err := client.Do(req) if err != nil { return "", err @@ -156,6 +160,9 @@ func (c *Client) Connect() error { if c.SkipTLSVerify { c.Dialer.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} } + if c.UseProxyFromEnv { + c.Dialer.Proxy = http.ProxyFromEnvironment + } conn, _, err := c.Dialer.Dial(target.String(), *header) if err != nil { return err