Skip to content

Commit

Permalink
Merge pull request #816 from zapier/pde-5159/increase-hydration-url-s…
Browse files Browse the repository at this point in the history
…tring-limit

PDE-5159 feat(core) - Increase hydration payload limit
  • Loading branch information
standielpls authored Jul 2, 2024
2 parents 19c19be + c03389d commit fa58f80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/tools/wrap-hydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const crypto = require('crypto');

const { DehydrateError } = require('../errors');

// Max URL length for Node is 8KB (https://stackoverflow.com/a/56954244/)
// 8 * 1024 * (3 / 4) = 6144 max, minus some room for additional overhead
const MAX_PAYLOAD_SIZE = 6000;
// https://nodejs.org/docs/latest-v16.x/api/http.html#httpmaxheadersize
// Base64 encoding adds approx 4/3 to the original size
// To account for encoding, we use the inverse to calc the max original size (3/4)
// 16kb limit * 1024 * (3 / 4) = 12.228 kb max, minus some room for additional overhead
const MAX_PAYLOAD_SIZE = 12000;

const wrapHydrate = (payload) => {
payload = JSON.stringify(payload);
Expand Down
8 changes: 4 additions & 4 deletions packages/core/test/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ describe('hydration', () => {
);
});

it('should not accept payload size bigger than 6000 bytes.', () => {
const inputData = { key: 'a'.repeat(6001) };
it('should not accept payload size bigger than 12000 bytes.', () => {
const inputData = { key: 'a'.repeat(12001) };
(() => {
dehydrate(funcToFind, inputData);
}).should.throw(/Oops! You passed too much data/);
Expand Down Expand Up @@ -91,8 +91,8 @@ describe('hydration', () => {
);
});

it('should not accept payload size bigger than 6000 bytes.', () => {
const inputData = { key: 'a'.repeat(6001) };
it('should not accept payload size bigger than 12000 bytes.', () => {
const inputData = { key: 'a'.repeat(12001) };
(() => {
dehydrateFile(funcToFind, inputData);
}).should.throw(/Oops! You passed too much data/);
Expand Down

0 comments on commit fa58f80

Please sign in to comment.