Skip to content

Commit

Permalink
fix pd-ctl post bug when tls enabled (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor1996 authored and siddontang committed Mar 12, 2018
1 parent 6ebdc82 commit d8d7de9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 5 additions & 5 deletions pdctl/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

var (
dailClient = &http.Client{}
dialClient = &http.Client{}

pingPrefix = "pd/ping"
errInvalidAddr = errors.New("Invalid pd address, Cannot get connect to it")
Expand All @@ -47,7 +47,7 @@ func InitHTTPSClient(CAPath, CertPath, KeyPath string) error {
return errors.Trace(err)
}

dailClient = &http.Client{Transport: &http.Transport{
dialClient = &http.Client{Transport: &http.Transport{
TLSClientConfig: tlsConfig,
}}

Expand All @@ -69,7 +69,7 @@ func getRequest(cmd *cobra.Command, prefix string, method string, bodyType strin

func dail(req *http.Request) (string, error) {
var res string
reps, err := dailClient.Do(req)
reps, err := dialClient.Do(req)
if err != nil {
return res, err
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func validPDAddr(pd string) error {
u.Scheme = "http"
}
addr := u.String()
reps, err := http.Get(fmt.Sprintf("%s/%s", addr, pingPrefix))
reps, err := dialClient.Get(fmt.Sprintf("%s/%s", addr, pingPrefix))
if err != nil {
return err
}
Expand All @@ -151,7 +151,7 @@ func postJSON(cmd *cobra.Command, prefix string, input map[string]interface{}) {
}

url := getAddressFromCmd(cmd, prefix)
r, err := http.Post(url, "application/json", bytes.NewBuffer(data))
r, err := dialClient.Post(url, "application/json", bytes.NewBuffer(data))
if err != nil {
fmt.Println(err)
return
Expand Down
6 changes: 1 addition & 5 deletions server/api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ func doDelete(url string) error {
}

func doGet(url string) (*http.Response, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, errors.Trace(err)
}
resp, err := dialClient.Do(req)
resp, err := dialClient.Get(url)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down

0 comments on commit d8d7de9

Please sign in to comment.