-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Default Content-Type for POST Requests to 'application/json' #1681
Conversation
…sReceived in Sovrn adapter and Sovrn tests.
… this is the stated standard for Prebid 1.0.0.
src/adapters/bidderFactory.js
Outdated
@@ -249,7 +249,7 @@ export function newBidder(spec) { | |||
typeof request.data === 'string' ? request.data : JSON.stringify(request.data), | |||
{ | |||
method: 'POST', | |||
contentType: 'text/plain', | |||
contentType: 'application/json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll get a new PR in shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a small change... but I still think there should be a unit test for this, to prevent regressions.
src/adapters/bidderFactory.js
Outdated
@@ -249,7 +250,7 @@ export function newBidder(spec) { | |||
typeof request.data === 'string' ? request.data : JSON.stringify(request.data), | |||
{ | |||
method: 'POST', | |||
contentType: 'text/plain', | |||
contentType: request.contentType || 'text/plain', | |||
withCredentials: true | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -224,6 +225,12 @@ export function newBidder(spec) { | |||
requests.forEach(processRequest); | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, that was dumb my bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/adapters/bidderFactory.js
Outdated
@@ -233,10 +234,10 @@ export function newBidder(spec) { | |||
error: onFailure | |||
}, | |||
undefined, | |||
{ | |||
Object.assign({}, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) ...
…rebid#1681) * Update Sovrn adapter. Add test coverage. Enable deal IDs. * HS-271: Avoid using private variables such as _bidsRequested and _bidsReceived in Sovrn adapter and Sovrn tests. * lint * Add bidfloor param to test. * changed post content-type in bidder factory to 'application/json', as this is the stated standard for Prebid 1.0.0. * Revert "changed post content-type in bidder factory to 'application/json', as this is the stated standard for Prebid 1.0.0." This reverts commit 0338ce7. * Changed method for altering contentType so that it is configurable via the ServerRequest object. * Altered PR to conform to change reviews. added unit tests. * Added comment to pass Trion adapter test. * Removed false-y check for request.options. Added request.options config for GET requests. Added test for this second change and removed tests for passing null or undefined member variables into the request.options object. * small optimization to request.options to remove extra object declaration.
…rebid#1681) * Update Sovrn adapter. Add test coverage. Enable deal IDs. * HS-271: Avoid using private variables such as _bidsRequested and _bidsReceived in Sovrn adapter and Sovrn tests. * lint * Add bidfloor param to test. * changed post content-type in bidder factory to 'application/json', as this is the stated standard for Prebid 1.0.0. * Revert "changed post content-type in bidder factory to 'application/json', as this is the stated standard for Prebid 1.0.0." This reverts commit 0338ce7. * Changed method for altering contentType so that it is configurable via the ServerRequest object. * Altered PR to conform to change reviews. added unit tests. * Added comment to pass Trion adapter test. * Removed false-y check for request.options. Added request.options config for GET requests. Added test for this second change and removed tests for passing null or undefined member variables into the request.options object. * small optimization to request.options to remove extra object declaration.
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.