diff --git a/src/adapters/bidderFactory.js b/src/adapters/bidderFactory.js index becc4afc029..e490e17c60d 100644 --- a/src/adapters/bidderFactory.js +++ b/src/adapters/bidderFactory.js @@ -66,6 +66,7 @@ import { logWarn, logError, parseQueryStringParameters, delayExecution } from 's * @property {('GET'|'POST')} method The type of request which this is. * @property {string} url The endpoint for the request. For example, "//bids.example.com". * @property {string|object} data Data to be sent in the request. + * @property {object} options Content-Type set in the header of the bid request, overrides default 'text/plain'. * If this is a GET request, they'll become query params. If it's a POST request, they'll be added to the body. * Strings will be added as-is. Objects will be unpacked into query params based on key/value mappings, or * JSON-serialized into the Request body. @@ -233,10 +234,10 @@ export function newBidder(spec) { error: onFailure }, undefined, - { + Object.assign({ method: 'GET', withCredentials: true - } + }, request.options) ); break; case 'POST': @@ -247,11 +248,11 @@ export function newBidder(spec) { error: onFailure }, typeof request.data === 'string' ? request.data : JSON.stringify(request.data), - { + Object.assign({ method: 'POST', contentType: 'text/plain', withCredentials: true - } + }, request.options) ); break; default: diff --git a/test/spec/unit/core/bidderFactory_spec.js b/test/spec/unit/core/bidderFactory_spec.js index 04e4c051365..e91ddcf39a4 100644 --- a/test/spec/unit/core/bidderFactory_spec.js +++ b/test/spec/unit/core/bidderFactory_spec.js @@ -147,6 +147,31 @@ describe('bidders created by newBidder', () => { }); }); + it('should make the appropriate POST request when options are passed', () => { + const bidder = newBidder(spec); + const url = 'test.url.com'; + const data = { arg: 2 }; + const options = { contentType: 'application/json'}; + spec.isBidRequestValid.returns(true); + spec.buildRequests.returns({ + method: 'POST', + url: url, + data: data, + options: options + }); + + bidder.callBids(MOCK_BIDS_REQUEST); + + expect(ajaxStub.calledOnce).to.equal(true); + expect(ajaxStub.firstCall.args[0]).to.equal(url); + expect(ajaxStub.firstCall.args[2]).to.equal(JSON.stringify(data)); + expect(ajaxStub.firstCall.args[3]).to.deep.equal({ + method: 'POST', + contentType: 'application/json', + withCredentials: true + }); + }); + it('should make the appropriate GET request', () => { const bidder = newBidder(spec); const url = 'test.url.com'; @@ -169,6 +194,30 @@ describe('bidders created by newBidder', () => { }); }); + it('should make the appropriate GET request when options are passed', () => { + const bidder = newBidder(spec); + const url = 'test.url.com'; + const data = { arg: 2 }; + const opt = { withCredentials: false } + spec.isBidRequestValid.returns(true); + spec.buildRequests.returns({ + method: 'GET', + url: url, + data: data, + options: opt + }); + + bidder.callBids(MOCK_BIDS_REQUEST); + + expect(ajaxStub.calledOnce).to.equal(true); + expect(ajaxStub.firstCall.args[0]).to.equal(`${url}?arg=2&`); + expect(ajaxStub.firstCall.args[2]).to.be.undefined; + expect(ajaxStub.firstCall.args[3]).to.deep.equal({ + method: 'GET', + withCredentials: false + }); + }); + it('should make multiple calls if the spec returns them', () => { const bidder = newBidder(spec); const url = 'test.url.com';