Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pd-ctl, api: fix pd-ctl post bug when tls enabled #987

Merged
merged 2 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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