2021-08-17 10:29:06 +02:00
|
|
|
package websteps
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
2021-09-07 17:09:30 +02:00
|
|
|
errorsxlegacy "github.com/ooni/probe-cli/v3/internal/errorsx"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
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) {
|
2021-08-17 10:29:06 +02:00
|
|
|
clnt := httpx.Client{
|
|
|
|
BaseURL: thAddr,
|
|
|
|
HTTPClient: sess.DefaultHTTPClient(),
|
|
|
|
Logger: sess.Logger(),
|
|
|
|
}
|
|
|
|
// make sure error is wrapped
|
2021-09-07 17:09:30 +02:00
|
|
|
err = errorsxlegacy.SafeErrWrapperBuilder{
|
2021-08-20 16:09:21 +02:00
|
|
|
Error: clnt.PostJSON(ctx, resourcePath, creq, &out),
|
2021-08-17 10:29:06 +02:00
|
|
|
Operation: errorsx.TopLevelOperation,
|
|
|
|
}.MaybeBuild()
|
|
|
|
return
|
|
|
|
}
|