Commit 9e432879 authored by Geoff Simmons's avatar Geoff Simmons

Fix a nil dereference in DataplaneClient.getReq().

This was a case of golang's wonderfully confusing nil pointer vs
nil interface.
parent 97f90b1e
......@@ -171,11 +171,17 @@ func drainAndClose(body io.ReadCloser) {
}
func (client *DataplaneClient) getReq(
path, method string, body io.Reader) (*http.Request, error) {
path, method string,
body io.Reader,
withbody bool,
) (req *http.Request, err error) {
relPath := &url.URL{Path: path}
url := client.baseURL.ResolveReference(relPath)
req, err := http.NewRequest(method, url.String(), body)
if withbody {
req, err = http.NewRequest(method, url.String(), body)
} else {
req, err = http.NewRequest(method, url.String(), nil)
}
if err != nil {
return req, err
}
......@@ -238,7 +244,7 @@ func (client *DataplaneClient) StartTx(
// req.URL.RawQuery = query.Encode()
// req.Header.Set("Accept", "application/json")
req, err := client.getReq(txPath, http.MethodPost, nil)
req, err := client.getReq(txPath, http.MethodPost, nil, false)
if err != nil {
return
}
......@@ -292,7 +298,7 @@ func (client *DataplaneClient) FinishTx(
// req.Header.Set("Accept", "application/json")
state := ReloadState{Status: Unknown}
req, err := client.getReq(txPath+"/"+tx.ID, http.MethodPut, nil)
req, err := client.getReq(txPath+"/"+tx.ID, http.MethodPut, nil, false)
if err != nil {
return state, err
}
......@@ -404,7 +410,8 @@ func (client *DataplaneClient) configTLS(
// req.URL.RawQuery = query.Encode()
// req.SetBasicAuth(client.user, client.password)
// req.Header.Set("Accept", "application/json")
req, err := client.getReq(path, method, rdr)
req, err := client.getReq(path, method, rdr,
method != http.MethodDelete)
if err != nil {
return err
}
......@@ -499,7 +506,8 @@ func (client *DataplaneClient) DeleteTx(tx *models.Transaction) error {
func (client *DataplaneClient) Reloaded(id string) (bool, ReloadState, error) {
state := ReloadState{ID: id}
req, err := client.getReq(reloadsPath+"/"+id, http.MethodGet, nil)
req, err := client.getReq(reloadsPath+"/"+id, http.MethodGet, nil,
false)
if err != nil {
return false, state, err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment