Change Default Content-Type for POST Requests to 'application/json'#1681
Change Default Content-Type for POST Requests to 'application/json'#1681mkendall07 merged 15 commits intoprebid:masterfrom
Conversation
…sReceived in Sovrn adapter and Sovrn tests.
… this is the stated standard for Prebid 1.0.0.
src/adapters/bidderFactory.js
Outdated
| { | ||
| method: 'POST', | ||
| contentType: 'text/plain', | ||
| contentType: 'application/json', |
There was a problem hiding this comment.
Thanks for the PR. I think we want to make this configurable however. Reason being that if it's application/json then CORS preflight request is required (additional round trip). text/plain doesn't have this requirement.
There was a problem hiding this comment.
Thanks, is the intention for 1.0.0 then for the endpoint to accept the POST request JSON payload in plain text format?
There was a problem hiding this comment.
how do you feel about an optional 'contentType' param on the spec object?
So it would be,
contentType: spec.contentType || 'text/plain'
There was a problem hiding this comment.
The spec probably isn't a great place, because some adapters make several server requests. If a bidder wanted to make two requests with two different content types, they'd be stuck.
It would fit in pretty nicely on the ServerRequest object, though.
There was a problem hiding this comment.
works for me, thanks for helping out. We are just trying to avoid our current method of sending JSONP.
There was a problem hiding this comment.
I'll get a new PR in shortly.
There was a problem hiding this comment.
yep yep... the internet thanks you :)
…son', as this is the stated standard for Prebid 1.0.0." This reverts commit 0338ce7.
…a the ServerRequest object.
|
Hmm.... can't tell why it is still failing the tests. |
src/adapters/bidderFactory.js
Outdated
| contentType: 'text/plain', | ||
| contentType: request.contentType || 'text/plain', | ||
| withCredentials: true | ||
| } |
There was a problem hiding this comment.
Ony minor thing... how do you feel about request.options.contentType, where options is an object?
Reason being: this could become Object.assign({}, theseDefaultPostOptions, requests.options), and then bidders will be able to edit any of the ajax options that they wanted.
Another benefit is that the JSDoc types would be reusable. The fourth argument to ajax would have the same typedef as the ServerRequest.options object.
There was a problem hiding this comment.
Makes sense to me. Should the Object.assign() route only be implemented/tested for the POST ajax call? Or would there be a reason to pass options on the GET too?
There was a problem hiding this comment.
hmm... I guess I'd have a small preference towards doing it for both, just because parallelism makes the behavior easier for people to remember.
It's a pretty weak preference, though. At worst, the first adapter which passes options to GET will find out that it doesn't work, and then they'll just have to add it later.
src/adapters/bidderFactory.js
Outdated
| function processRequest(request) { | ||
| // check for undefined or null request.options | ||
| for (var member in request.options) { | ||
| if (!request.options[member]) { |
There was a problem hiding this comment.
What if someone wanted to override withCredentials: false?
Is there any particular reason you're trying to delete null & undefined here?
There was a problem hiding this comment.
Ah yeah, that was dumb my bad.
There was a problem hiding this comment.
I don't think so... I just ran it myself, and this test fails:
it('should allow falsey options in the overrides', () => {
const bidder = newBidder(spec);
const url = 'test.url.com';
const data = { arg: 2 };
const options = { withCredentials: false }
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: 'text/plain',
withCredentials: false // The test succeeds if this is true
});
});
Pretty sure you're deleting all false-y properties from the options object, so they don't override properly.
…ig for GET requests. Added test for this second change and removed tests for passing null or undefined member variables into the request.options object.
src/adapters/bidderFactory.js
Outdated
| }, | ||
| undefined, | ||
| { | ||
| Object.assign({}, { |
There was a problem hiding this comment.
Tiny optimization: you don't need to Object.assign({}, defaults, overrides) here. Since the defaults are defined right here, Object.assign(defaults, overrides) should work just fine, and allocate one fewer object.
Definitely shouldn't hold up the merge though.
* tag '0.31.0' of https://github.com/prebid/Prebid.js: (54 commits) Fix for prebid#1628 (allowing standard bidCpmAdjustment) (prebid#1645) Prebid 0.31.0 Release Support native click tracking (prebid#1691) Initial commit for video support for pbs (prebid#1706) Fixes: Immediate adapter response may end auction (prebid#1690) Rubicon feature/s2s test module (prebid#1678) Renaming of "huddledmasses" adapter into colossusssp (prebid#1701) Don't set non-object configurations (prebid#1704) Update JSDoc for `pbjs.enableAnalytics` (prebid#1565) Add ad units event (prebid#1702) AppnexusAst adapter: logging error message from endpoint (prebid#1697) AppnexusAst bidadapter markdown file (prebid#1696) Change Default Content-Type for POST Requests to 'application/json' (prebid#1681) Code improvement for trustx adapter (prebid#1673) PulsePoint Lite adapter - Enabling Sync pixel (prebid#1686) Update spotx video adapter to set the spotx_ad_key used in DFP (prebid#1614) Fix broken AOL mobile endpoint secure bid requests (prebid#1684) Fix adapter tests that hardcoded pbjs. (prebid#1666) no longer attaching gpt slots to adUnits, which breaks utils.cloneJson(adUnit) (prebid#1676) remove bidmanager from rubicon tests (prebid#1671) ...
….31.0 to aolgithub-master * commit 'e7341c948014a789084849495171d08d4b353d07': (21 commits) Added changelog entry. Fix for prebid#1628 (allowing standard bidCpmAdjustment) (prebid#1645) Prebid 0.31.0 Release Support native click tracking (prebid#1691) Initial commit for video support for pbs (prebid#1706) Fixes: Immediate adapter response may end auction (prebid#1690) Rubicon feature/s2s test module (prebid#1678) Renaming of "huddledmasses" adapter into colossusssp (prebid#1701) Don't set non-object configurations (prebid#1704) Update JSDoc for `pbjs.enableAnalytics` (prebid#1565) Add ad units event (prebid#1702) AppnexusAst adapter: logging error message from endpoint (prebid#1697) AppnexusAst bidadapter markdown file (prebid#1696) Change Default Content-Type for POST Requests to 'application/json' (prebid#1681) Code improvement for trustx adapter (prebid#1673) PulsePoint Lite adapter - Enabling Sync pixel (prebid#1686) Update spotx video adapter to set the spotx_ad_key used in DFP (prebid#1614) Fix broken AOL mobile endpoint secure bid requests (prebid#1684) Fix adapter tests that hardcoded pbjs. (prebid#1666) no longer attaching gpt slots to adUnits, which breaks utils.cloneJson(adUnit) (prebid#1676) ...
Type of change
Description of change
This change allows POST bid requests to be treated as JSON, by setting the Content-Type of the header.
While the docs for how to make a Prebid 1.0.0 adapter say that POST requests are treated as JSON, they are actually being treated as plain text currently.
Other information
I asked @mkendall07 about this bug and was told that it was worth putting in a pull request for.