Replaced the return of Call[Method]() by the stored value of the resp.Body

This commit is contained in:
pb 2025-03-12 15:26:00 +01:00
parent 9b3dfc7576
commit 79aec86f5f

View File

@ -82,8 +82,12 @@ func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) (
if err != nil {
return nil, err
}
err = caller.StoreResp(resp)
if err != nil {
return nil, err
}
return io.ReadAll(resp.Body)
return caller.LastResults["body"].([]byte), nil
}
// CallPut calls the DELETE method on the HTTP server
@ -93,8 +97,12 @@ func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error)
return nil, err
}
defer resp.Body.Close()
// caller.LastResults = resp
return io.ReadAll(resp.Body)
err = caller.StoreResp(resp)
if err != nil {
return nil, err
}
return caller.LastResults["body"].([]byte), nil
}
// CallPost calls the POST method on the HTTP server
@ -117,7 +125,8 @@ func (caller *HTTPCaller) CallPost(url string, subpath string, body interface{},
if err != nil {
return nil, err
}
return io.ReadAll(resp.Body)
return caller.LastResults["body"].([]byte), nil
}
// CallPost calls the POST method on the HTTP server
@ -135,7 +144,12 @@ func (caller *HTTPCaller) CallPut(url string, subpath string, body map[string]in
return nil, err
}
defer resp.Body.Close()
return io.ReadAll(resp.Body)
err = caller.StoreResp(resp)
if err != nil {
return nil, err
}
return caller.LastResults["body"].([]byte), nil
}
// CallRaw calls the Raw method on the HTTP server
@ -192,6 +206,5 @@ func (caller *HTTPCaller) StoreResp(resp *http.Response) error {
}
caller.LastResults["body"] = data
return nil
}