Skip to content

Commit

Permalink
Merge pull request prebid#8 from PubMatic-OpenWrap/UOE-3793
Browse files Browse the repository at this point in the history
UOE-3793  Add a new request specific object to bid request extension
  • Loading branch information
PubMatic-OpenWrap authored Apr 4, 2019
2 parents 7ce6567 + d2577d1 commit e19e0e5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
33 changes: 33 additions & 0 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,34 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder
return bids, nil
}

func getCookiesFromRequest(request *openrtb.BidRequest) []string {
var reqExt openrtb_ext.ExtRequest
err := json.Unmarshal(request.Ext, &reqExt)
if err != nil {
logf("[PUBMATIC] Error while unmarshalling request.ext: %v.", string(request.Ext))
return nil
}

if reqExt.RequestParams["Cookie"] == nil {
return nil
}

cbyte, err := json.Marshal(reqExt.RequestParams["Cookie"])
if err != nil {
logf("[PUBMATIC] Error retrieving cookies from request.ext.requestparams: %v.", reqExt.RequestParams)
return nil
}

var cookies []string
err = json.Unmarshal(cbyte, &cookies)
if err != nil {
logf("[PUBMATIC] Error retrieving cookies from request.ext.requestparams: %v.", reqExt.RequestParams)
return nil
}

return cookies
}

func (a *PubmaticAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
errs := make([]error, 0, len(request.Imp))

Expand All @@ -317,6 +345,7 @@ func (a *PubmaticAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters
}
}

cookies := getCookiesFromRequest(request)
if wrapExt != "" {
rawExt := fmt.Sprintf("{\"wrapper\": %s}", wrapExt)
request.Ext = openrtb.RawJSON(rawExt)
Expand Down Expand Up @@ -364,6 +393,10 @@ func (a *PubmaticAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
for _, line := range cookies {
headers.Add("Cookie", line)
}

return []*adapters.RequestData{{
Method: "POST",
Uri: thisURI,
Expand Down
4 changes: 3 additions & 1 deletion openrtb_ext/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
)

// ExtRequest defines the contract for bidrequest.ext
// ExtRequest.RequestParams should only be used for data common to the request. It should not be used for bidder specific data
type ExtRequest struct {
Prebid ExtRequestPrebid `json:"prebid"`
Prebid ExtRequestPrebid `json:"prebid"`
RequestParams map[string]interface{} `json:"requestparams,omitempty"`
}

// ExtRequestPrebid defines the contract for bidrequest.ext.prebid
Expand Down

0 comments on commit e19e0e5

Please sign in to comment.