Skip to content

Commit

Permalink
fix: large json (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
d2lam authored Oct 18, 2018
1 parent b509838 commit 258d919
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions plugins/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ exports.plugin = {
}
});

// For text/plain payload or application/zip, upload it as Buffer
// For text/plain payload, upload it as Buffer
// Otherwise, catbox-s3 will try to JSON.stringify (https://github.com/fhemberger/catbox-s3/blob/master/lib/index.js#L236)
// and might create issue on large payload
if (contents.h['content-type'] === 'text/plain' ||
contents.h['content-type'] === 'application/zip') {
if (contents.h['content-type'] === 'text/plain') {
value = contents.c;
}

Expand Down
8 changes: 5 additions & 3 deletions plugins/caches.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.plugin = {
response.headers = value.h;
} else {
response = h.response(Buffer.from(value));
response.headers['content-type'] = 'text/plain';
response.headers['content-type'] = 'application/zip';
}

if (strategyConfig.plugin !== 's3') {
Expand Down Expand Up @@ -134,8 +134,10 @@ exports.plugin = {
}
});

// For text/plain payload, upload it as Buffer
if (contents.h['content-type'] === 'text/plain') {
// For application/zip, upload it as Buffer
// Otherwise, catbox-s3 will try to JSON.stringify (https://github.com/fhemberger/catbox-s3/blob/master/lib/index.js#L236)
// and might create issue on large payload
if (contents.h['content-type'] === 'application/zip') {
value = contents.c;
}

Expand Down
6 changes: 3 additions & 3 deletions test/plugins/caches.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('events plugin test', () => {
payload: 'THIS IS A TEST',
headers: {
'x-foo': 'bar',
'content-type': 'text/plain',
'content-type': 'application/zip',
ignore: 'true'
},
credentials: {
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('events plugin test', () => {
});
});

it('saves a cache without headers for text/plain type', async () => {
it('saves a cache without headers for application/zip type', async () => {
options.url = `/caches/events/${mockEventID}/foo`;

const putResponse = await server.inject(options);
Expand All @@ -239,7 +239,7 @@ describe('events plugin test', () => {
}
}).then((getResponse) => {
assert.equal(getResponse.statusCode, 200);
assert.equal(getResponse.headers['content-type'], 'text/plain; charset=utf-8');
assert.equal(getResponse.headers['content-type'], 'application/zip');
assert.isNotOk(getResponse.headers['x-foo']);
assert.isNotOk(getResponse.headers.ignore);
assert.equal(getResponse.result, 'THIS IS A TEST');
Expand Down

0 comments on commit 258d919

Please sign in to comment.