Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,14 @@ internals.decoder = function (source, options) {

const contentEncoding = source.headers['content-encoding'];
const decoders = options.decoders ?? internals.decoders;
if (!decoders.hasOwnProperty(contentEncoding)) {
if (contentEncoding === undefined) {
return source;
}

if (!decoders.hasOwnProperty(contentEncoding)) {
throw Boom.unsupportedMediaType();
}

const decoderOptions = options.compression?.[contentEncoding] ?? null;
const stream = decoders[contentEncoding](decoderOptions);

Expand Down
6 changes: 3 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ describe('parse()', () => {
expect(payload.toString()).to.equal(body);
});

it('leaves payload raw when encoding unknown', async () => {
it('errors when encoding unknown', async () => {

const body = '{"x":"1","y":"2","z":"3"}';
const compressed = await internals.compress('gzip', body);
Expand All @@ -632,8 +632,8 @@ describe('parse()', () => {
'content-type': 'application/json'
};

const { payload } = await Subtext.parse(request, null, { parse: 'gunzip', output: 'data' });
expect(payload.toString()).to.equal(compressed.toString());
const err = await expect(Subtext.parse(request, null, { parse: 'gunzip', output: 'data' })).to.reject('Unsupported Media Type');
expect(err.output.statusCode).to.equal(415);
});

it('unzips payload without parsing (external decoders)', async () => {
Expand Down
Loading