mirror of
https://github.com/hashicorp/terraform.git
synced 2026-02-03 20:50:59 -05:00
HTTP backend client cleanup
1. Don't need to close response body twice 2. Pass data as []byte, no need to wrap in a reader
This commit is contained in:
parent
abf7f3416b
commit
cf0254ae58
1 changed files with 3 additions and 5 deletions
|
|
@ -38,14 +38,13 @@ type httpClient struct {
|
|||
}
|
||||
|
||||
func (c *httpClient) httpRequest(method string, url *url.URL, data *[]byte, what string) (*http.Response, error) {
|
||||
// If we have data we need a reader
|
||||
var reader io.Reader = nil
|
||||
var body interface{}
|
||||
if data != nil {
|
||||
reader = bytes.NewReader(*data)
|
||||
body = *data
|
||||
}
|
||||
|
||||
// Create the request
|
||||
req, err := retryablehttp.NewRequest(method, url.String(), reader)
|
||||
req, err := retryablehttp.NewRequest(method, url.String(), body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to make %s HTTP request: %s", what, err)
|
||||
}
|
||||
|
|
@ -97,7 +96,6 @@ func (c *httpClient) Lock(info *statemgr.LockInfo) (string, error) {
|
|||
case http.StatusForbidden:
|
||||
return "", fmt.Errorf("HTTP remote state endpoint invalid auth")
|
||||
case http.StatusConflict, http.StatusLocked:
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("HTTP remote state already locked, failed to read body")
|
||||
|
|
|
|||
Loading…
Reference in a new issue