Skip to content

Commit

Permalink
udpate device.ext.cdep
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-nilesh-chate committed Jan 10, 2024
1 parent eeba105 commit d8da213
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion endpoints/cookie_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ func TestCookieSyncHandleResponse(t *testing.T) {
} else {
bidderEval = []usersync.BidderEvaluation{}
}
endpoint.handleResponse(writer, syncTypeFilter, cookie, privacyMacros, test.givenSyncersChosen, bidderEval, test.givenDebug)
endpoint.handleResponse(writer, syncTypeFilter, cookie, privacyMacros, test.givenSyncersChosen, bidderEval, test.givenDebug, false, 0)

if assert.Equal(t, writer.Code, http.StatusOK, test.description+":http_status") {
assert.Equal(t, writer.Header().Get("Content-Type"), "application/json; charset=utf-8", test.description+":http_header")
Expand Down
29 changes: 28 additions & 1 deletion endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ func setDeviceImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrapper, i
setIPImplicitly(httpReq, r, ipValidtor)
setUAImplicitly(httpReq, r)
setDoNotTrackImplicitly(httpReq, r)

secCookieDeprecation(httpReq, r)
}

// setAuctionTypeImplicitly sets the auction type to 1 if it wasn't on the request,
Expand Down Expand Up @@ -2352,6 +2352,33 @@ func setDoNotTrackImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrappe
}
}

func secCookieDeprecation(httpReq *http.Request, r *openrtb_ext.RequestWrapper) {
secCookieDeprecation := httpReq.Header.Get("Sec-Cookie-Deprecation")
if secCookieDeprecation == "" {
return
}

if r.Device == nil {
r.Device = &openrtb2.Device{}
}

updated := false
deviceExt := map[string]interface{}{}
if r.Device.Ext == nil {
updated = true
deviceExt["cdep"] = secCookieDeprecation
} else {
if err := json.Unmarshal(r.Device.Ext, &deviceExt); err == nil && deviceExt["cdep"] == nil {
updated = true
deviceExt["cdep"] = secCookieDeprecation
}
}

if updated {
r.Device.Ext, _ = json.Marshal(deviceExt)
}
}

// Write(return) errors to the client, if any. Returns true if errors were found.
func writeError(errs []error, w http.ResponseWriter, labels *metrics.Labels) bool {
var rc bool = false
Expand Down

0 comments on commit d8da213

Please sign in to comment.