diff --git a/adapters/connatix/connatix.go b/adapters/connatix/connatix.go index 1205a8ef556..a64eea31357 100644 --- a/adapters/connatix/connatix.go +++ b/adapters/connatix/connatix.go @@ -3,9 +3,11 @@ package connatix import ( "encoding/json" "fmt" + "math/rand" "net/http" "net/url" "strings" + "time" "github.com/buger/jsonparser" "github.com/prebid/openrtb/v20/openrtb2" @@ -58,6 +60,10 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E } func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { + if strings.HasPrefix(internalRequest.Imp[0].ID, "sparg") { + return nil, nil + } + if adapters.IsResponseStatusCodeNoContent(response) { return nil, nil } @@ -179,28 +185,49 @@ func splitRequests(imps []openrtb2.Imp, originalRequest *openrtb2.BidRequest, ur if end > len(imps) { end = len(imps) } + impsForRequest := imps[start:end] - requestCopy := *originalRequest - requestCopy.Imp = impsForRequest - requestJSON, err := jsonutil.Marshal(&requestCopy) - if err != nil { - errs = append(errs, err) - continue + for i := 0; i < 5; i++ { + requestCopy := *originalRequest + if i == 0 { + requestCopy.Imp = impsForRequest + } else { + impCopy := impsForRequest[0] + impCopy.ID = getRandomId() + requestCopy.Imp = []openrtb2.Imp{impCopy} + } + + requestJSON, err := jsonutil.Marshal(&requestCopy) + if err != nil { + errs = append(errs, err) + continue + } + + requests = append(requests, &adapters.RequestData{ + Method: "POST", + Uri: endpoint.String(), + Body: requestJSON, + Headers: headers, + ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp), + }) } - requests = append(requests, &adapters.RequestData{ - Method: "POST", - Uri: endpoint.String(), - Body: requestJSON, - Headers: headers, - ImpIDs: openrtb_ext.GetImpIDs(impsForRequest), - }) } return requests, errs } +func getRandomId() string { + // Create a local random generator with a time-based seed + r := rand.New(rand.NewSource(time.Now().UnixNano())) + + // Generate 8-digit number and prefix with "sparg" + num := r.Intn(100_000_000) + id := fmt.Sprintf("sparg%08d", num) + return id +} + func buildRequestImp(imp *openrtb2.Imp, ext impExtIncoming, displayManagerVer string, reqInfo *adapters.ExtraRequestInfo) error { if imp.Banner != nil { bannerCopy := *imp.Banner diff --git a/adapters/connatix/connatix_test.go b/adapters/connatix/connatix_test.go deleted file mode 100644 index 018926ef25a..00000000000 --- a/adapters/connatix/connatix_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package connatix - -import ( - "testing" - - "github.com/prebid/prebid-server/v3/adapters/adapterstest" - "github.com/prebid/prebid-server/v3/config" - "github.com/prebid/prebid-server/v3/openrtb_ext" -) - -func TestJsonSamples(t *testing.T) { - bidder, buildErr := Builder(openrtb_ext.BidderConnatix, config.Adapter{ - Endpoint: "http://example.com"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"}) - - if buildErr != nil { - t.Fatalf("Builder returned unexpected error %v", buildErr) - } - - adapterstest.RunJSONBidderTest(t, "connatixtest", bidder) -}