2021-08-17 10:29:06 +02:00
|
|
|
package websteps
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-01-05 17:17:20 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/httpx"
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2021-09-28 12:42:01 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-08-17 10:29:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Control performs the control request and returns the response.
|
|
|
|
func Control(
|
|
|
|
ctx context.Context, sess model.ExperimentSession,
|
2021-08-20 16:09:21 +02:00
|
|
|
thAddr string, resourcePath string, creq CtrlRequest) (out CtrlResponse, err error) {
|
2022-01-05 14:15:42 +01:00
|
|
|
clnt := &httpx.APIClientTemplate{
|
2021-08-17 10:29:06 +02:00
|
|
|
BaseURL: thAddr,
|
|
|
|
HTTPClient: sess.DefaultHTTPClient(),
|
|
|
|
Logger: sess.Logger(),
|
|
|
|
}
|
|
|
|
// make sure error is wrapped
|
2022-01-07 17:31:21 +01:00
|
|
|
err = clnt.WithBodyLogging().Build().PostJSON(ctx, resourcePath, creq, &out)
|
|
|
|
if err != nil {
|
|
|
|
err = netxlite.NewTopLevelGenericErrWrapper(err)
|
|
|
|
}
|
2021-08-17 10:29:06 +02:00
|
|
|
return
|
|
|
|
}
|