Skip to content

Commit

Permalink
Change Default Content-Type for POST Requests to 'application/json' (p…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Theodore Rand authored and dluxemburg committed Jul 17, 2018
1 parent 0ff09f5 commit 0582dc7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -233,10 +234,10 @@ export function newBidder(spec) {
error: onFailure
},
undefined,
{
Object.assign({
method: 'GET',
withCredentials: true
}
}, request.options)
);
break;
case 'POST':
Expand All @@ -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:
Expand Down
49 changes: 49 additions & 0 deletions test/spec/unit/core/bidderFactory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down

0 comments on commit 0582dc7

Please sign in to comment.