Skip to content

Commit 0b98ff9

Browse files
authored
Feature/post request when url is too long (#70)
* switch to POST when csr URL is too long
1 parent 676f0b2 commit 0b98ff9

2 files changed

Lines changed: 290 additions & 186 deletions

File tree

modules/dasBidAdapter.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ function buildUserIds(customParams) {
105105

106106
function getNpaFromPubConsent(pubConsent) {
107107
const params = new URLSearchParams(pubConsent);
108-
return params.get('npa') == '1';
108+
return params.get('npa') === '1';
109109
}
110110

111111
function buildOpenRTBRequest(bidRequests, bidderRequest) {
112112
const { customParams, keyValues } = parseParams(
113113
bidRequests[0].params,
114114
bidderRequest,
115115
);
116-
const imp = bidRequests.map((bid, index) => {
116+
const imp = bidRequests.map((bid) => {
117117
const sizes = getAdUnitSizes(bid);
118118
const imp = {
119119
id: bid.bidId,
@@ -270,11 +270,29 @@ export const spec = {
270270

271271
buildRequests: function (validBidRequests, bidderRequest) {
272272
const data = buildOpenRTBRequest(validBidRequests, bidderRequest);
273-
const jsonData = encodeURIComponent(JSON.stringify(data));
273+
const jsonData = JSON.stringify(data);
274+
const baseUrl = getEndpoint(data.ext.network);
275+
const fullUrl = `${baseUrl}?data=${encodeURIComponent(jsonData)}`;
276+
277+
// Switch to POST if URL exceeds 8k characters
278+
if (fullUrl.length > 8192) {
279+
return {
280+
method: 'POST',
281+
url: baseUrl,
282+
data: jsonData,
283+
options: {
284+
withCredentials: true,
285+
crossOrigin: true,
286+
customHeaders: {
287+
'Content-Type': 'text/plain'
288+
}
289+
},
290+
};
291+
}
274292

275293
return {
276294
method: 'GET',
277-
url: `${getEndpoint(data.ext.network)}?data=${jsonData}`,
295+
url: fullUrl,
278296
options: {
279297
withCredentials: true,
280298
crossOrigin: true,

0 commit comments

Comments
 (0)