Add Proxy support

This commit is contained in:
lhb 2016-02-24 17:53:10 +09:00
parent 0c2f4fdffc
commit b65d82045a
3 changed files with 31 additions and 15 deletions

2
Godeps/Godeps.json generated
View File

@ -22,7 +22,7 @@
},
{
"ImportPath": "github.com/gorilla/websocket",
"Rev": "b6ab76f1fe9803ee1d59e7e5b2a797c1fe897ce5"
"Rev": "5c91b59efa232fa9a87b705d54101832c498a172"
},
{
"ImportPath": "github.com/jtolds/gls",

View File

@ -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)

View File

@ -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