1
0
Fork 0

provide a timeout on http client

When using the `rqlite` CLI, I was unable to determine an issue of connection.
It turns out that the arugments I had provided were not working.
The issue did not present itself till I added a timeout to the HTTP client.
master
JT Archie 12 months ago
parent ea92d5d7bd
commit 6503ffac89

@ -18,6 +18,7 @@ import (
"github.com/Bowery/prompt"
"github.com/mkideal/cli"
clix "github.com/mkideal/cli/ext"
"github.com/rqlite/rqlite/cmd"
"github.com/rqlite/rqlite/cmd/rqlite/history"
httpcl "github.com/rqlite/rqlite/cmd/rqlite/http"
@ -34,15 +35,16 @@ type Nodes map[string]Node
type argT struct {
cli.Helper
Alternatives string `cli:"a,alternatives" usage:"comma separated list of 'host:port' pairs to use as fallback"`
Protocol string `cli:"s,scheme" usage:"protocol scheme (http or https)" dft:"http"`
Host string `cli:"H,host" usage:"rqlited host address" dft:"127.0.0.1"`
Port uint16 `cli:"p,port" usage:"rqlited host port" dft:"4001"`
Prefix string `cli:"P,prefix" usage:"rqlited HTTP URL prefix" dft:"/"`
Insecure bool `cli:"i,insecure" usage:"do not verify rqlited HTTPS certificate" dft:"false"`
CACert string `cli:"c,ca-cert" usage:"path to trusted X.509 root CA certificate"`
Credentials string `cli:"u,user" usage:"set basic auth credentials in form username:password"`
Version bool `cli:"v,version" usage:"display CLI version"`
Alternatives string `cli:"a,alternatives" usage:"comma separated list of 'host:port' pairs to use as fallback"`
Protocol string `cli:"s,scheme" usage:"protocol scheme (http or https)" dft:"http"`
Host string `cli:"H,host" usage:"rqlited host address" dft:"127.0.0.1"`
Port uint16 `cli:"p,port" usage:"rqlited host port" dft:"4001"`
Prefix string `cli:"P,prefix" usage:"rqlited HTTP URL prefix" dft:"/"`
Insecure bool `cli:"i,insecure" usage:"do not verify rqlited HTTPS certificate" dft:"false"`
CACert string `cli:"c,ca-cert" usage:"path to trusted X.509 root CA certificate"`
Credentials string `cli:"u,user" usage:"set basic auth credentials in form username:password"`
Version bool `cli:"v,version" usage:"display CLI version"`
HTTPTimeout clix.Duration `cli:"t,http-timeout" usage:"set timeout on HTTP requests" dft:"30s"`
}
var cliHelp = []string{
@ -394,10 +396,13 @@ func getHTTPClient(argv *argT) (*http.Client, error) {
}
}
client := http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: argv.Insecure, RootCAs: rootCAs},
Proxy: http.ProxyFromEnvironment,
}}
client := http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: argv.Insecure, RootCAs: rootCAs},
Proxy: http.ProxyFromEnvironment,
},
Timeout: argv.HTTPTimeout.Duration,
}
// Explicitly handle redirects.
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {

Loading…
Cancel
Save