Skip to content

Commit

Permalink
Prebid Server Bid Adapter : Support for custom headers for XHR call (#…
Browse files Browse the repository at this point in the history
…11780)

* merge fix

* Adding support for custom headers for prebid server
  • Loading branch information
sanved77 authored Jun 20, 2024
1 parent 0ee1ba7 commit 9dc08c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ export const processPBSRequest = hook('sync', function (s2sBidRequest, bidReques
const requestJson = request && JSON.stringify(request);
logInfo('BidRequest: ' + requestJson);
const endpointUrl = getMatchingConsentUrl(s2sBidRequest.s2sConfig.endpoint, gdprConsent);
const customHeaders = deepAccess(s2sBidRequest, 's2sConfig.customHeaders', {});
if (request && requestJson && endpointUrl) {
const networkDone = s2sBidRequest.metrics.startTiming('net');
ajax(
Expand Down Expand Up @@ -584,7 +585,8 @@ export const processPBSRequest = hook('sync', function (s2sBidRequest, bidReques
{
contentType: 'text/plain',
withCredentials: true,
browsingTopics: isActivityAllowed(ACTIVITY_TRANSMIT_UFPD, s2sActivityParams(s2sBidRequest.s2sConfig))
browsingTopics: isActivityAllowed(ACTIVITY_TRANSMIT_UFPD, s2sActivityParams(s2sBidRequest.s2sConfig)),
customHeaders
}
);
} else {
Expand Down
14 changes: 14 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,20 @@ describe('S2S Adapter', function () {
})
})
})

it('should set customHeaders correctly when publisher has provided it', () => {
let configWithCustomHeaders = utils.deepClone(CONFIG);
configWithCustomHeaders.customHeaders = { customHeader1: 'customHeader1Value' };
config.setConfig({ s2sConfig: configWithCustomHeaders });

let reqWithNewConfig = utils.deepClone(REQUEST);
reqWithNewConfig.s2sConfig = configWithCustomHeaders;

adapter.callBids(reqWithNewConfig, BID_REQUESTS, addBidResponse, done, ajax);
const reqHeaders = server.requests[0].requestHeaders
expect(reqHeaders.customHeader1).to.exist;
expect(reqHeaders.customHeader1).to.equal('customHeader1Value');
});

it('should block request if config did not define p1Consent URL in endpoint object config', function () {
let badConfig = utils.deepClone(CONFIG);
Expand Down

0 comments on commit 9dc08c5

Please sign in to comment.