From 79aec86f5f820645ec447cdc216b14300bd6c40d Mon Sep 17 00:00:00 2001 From: pb Date: Wed, 12 Mar 2025 15:26:00 +0100 Subject: [PATCH] Replaced the return of Call[Method]() by the stored value of the resp.Body --- tools/remote_caller.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/remote_caller.go b/tools/remote_caller.go index 73f2db9..a8bc4a5 100644 --- a/tools/remote_caller.go +++ b/tools/remote_caller.go @@ -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 } \ No newline at end of file