From 17943cef55916728a5d038ae0d2ee6a241f70c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Fri, 18 Oct 2024 10:25:02 +0200 Subject: [PATCH] Add 88 bytes when counting byte size of POST requests to account for the payload_data envelope --- libraries/tracker-core/src/emitter/emitter_request.ts | 6 +++++- libraries/tracker-core/src/emitter/index.ts | 2 +- libraries/tracker-core/test/emitter/emitter_request.test.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/tracker-core/src/emitter/emitter_request.ts b/libraries/tracker-core/src/emitter/emitter_request.ts index 09f314ba6..c5b1b19a7 100644 --- a/libraries/tracker-core/src/emitter/emitter_request.ts +++ b/libraries/tracker-core/src/emitter/emitter_request.ts @@ -100,10 +100,14 @@ export function newEmitterRequest({ let abortController: AbortController | undefined; function countBytes(): number { - return events.reduce( + let count = events.reduce( (acc, event) => acc + (usePost ? event.getPOSTRequestBytesCount() : event.getGETRequestBytesCount()), 0 ); + if (usePost) { + count += 88; // 88 bytes for the payload_data envelope + } + return count; } function countEvents(): number { diff --git a/libraries/tracker-core/src/emitter/index.ts b/libraries/tracker-core/src/emitter/index.ts index cc80e9180..c22bd849b 100644 --- a/libraries/tracker-core/src/emitter/index.ts +++ b/libraries/tracker-core/src/emitter/index.ts @@ -326,7 +326,7 @@ export function newEmitter({ LOG.warn('Event (' + bytes + 'B) too big, max is ' + maxBytes); if (usePost) { - const bytes = emitterEvent.getPOSTRequestBytesCount(); + const bytes = emitterEvent.getPOSTRequestBytesCount() + 88; // 88 bytes for the payload_data envelope const tooBig = bytes > maxPostBytes; if (tooBig) { eventTooBigWarning(bytes, maxPostBytes); diff --git a/libraries/tracker-core/test/emitter/emitter_request.test.ts b/libraries/tracker-core/test/emitter/emitter_request.test.ts index 5bcf8a148..05342b931 100644 --- a/libraries/tracker-core/test/emitter/emitter_request.test.ts +++ b/libraries/tracker-core/test/emitter/emitter_request.test.ts @@ -71,7 +71,7 @@ test('countBytes returns the correct byte count', (t) => { t.true(request.addEvent(newEmitterEventFromPayload({ e: 'pv', p: 'web' }))); t.true(request.addEvent(newEmitterEventFromPayload({ e: 'pv', p: 'mob' }))); - t.is(request.countBytes(), 40); + t.is(request.countBytes(), 40 + 88); // 40 bytes for each event, 88 bytes for the payload_data envelope }); // MARK: - countEvents