Added a new http.Response field to HTTPCaller to store results for each call

This commit is contained in:
pb 2025-03-12 10:39:20 +01:00
parent 659b494ee4
commit 378f9e5095

View File

@ -51,7 +51,7 @@ var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
type HTTPCaller struct {
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
Disabled bool // Disabled flag
Results map[DataType]map[METHOD]map[string]interface{} // Used to store information regarding the last execution of a given method on a given data type
LastResults *http.Response // Used to store information regarding the last execution of a given method on a given data type
}
// NewHTTPCaller creates a new instance of the HTTP Caller
@ -77,6 +77,7 @@ func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) (
return nil, err
}
defer resp.Body.Close()
caller.LastResults = resp
return io.ReadAll(resp.Body)
}
@ -87,6 +88,7 @@ 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)
}
@ -106,6 +108,7 @@ func (caller *HTTPCaller) CallPost(url string, subpath string, body interface{},
return nil, err
}
defer resp.Body.Close()
caller.LastResults = resp
return io.ReadAll(resp.Body)
}
@ -124,6 +127,7 @@ func (caller *HTTPCaller) CallPut(url string, subpath string, body map[string]in
return nil, err
}
defer resp.Body.Close()
caller.LastResults = resp
return io.ReadAll(resp.Body)
}
@ -144,7 +148,13 @@ func (caller *HTTPCaller) CallRaw(method string, url string, subpath string,
req.AddCookie(c)
}
client := &http.Client{}
return client.Do(req)
resp, err := client.Do(req)
if err != nil {
return nil, err
}
caller.LastResults = resp
return resp, nil
}
// CallRaw calls the Raw method on the HTTP server