Skip to content

Commit

Permalink
Add 88 bytes when counting byte size of POST requests to account for …
Browse files Browse the repository at this point in the history
…the payload_data envelope
  • Loading branch information
matus-tomlein committed Oct 18, 2024
1 parent 7df289a commit 17943ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion libraries/tracker-core/src/emitter/emitter_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion libraries/tracker-core/src/emitter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17943ce

Please sign in to comment.