Skip to content

Commit

Permalink
fix: Change cache content type to text/plain (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav Ravichandran authored Oct 26, 2018
1 parent 7a87c70 commit af457f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions plugins/caches.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ exports.plugin = {
response = h.response(Buffer.from(value.c.data));
response.headers = value.h;
} else {
response = h.response(value);
response.headers['content-type'] = 'application/zip';
response = h.response(Buffer.from(value));
response.headers['content-type'] = 'text/plain';
}

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

// For application/zip, upload it as Buffer
// For text/plain, 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') {
if (contents.h['content-type'] === 'text/plain') {
value = contents.c;
}

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

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

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

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

const putResponse = await server.inject(options);
Expand All @@ -446,7 +446,7 @@ describe('events plugin test', () => {
}
}).then((getResponse) => {
assert.equal(getResponse.statusCode, 200);
assert.equal(getResponse.headers['content-type'], 'application/zip');
assert.equal(getResponse.headers['content-type'], 'text/plain; charset=utf-8');
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 af457f6

Please sign in to comment.