feat: Parse content-type more strictly

This commit is contained in:
Joachim Van Herwegen
2022-03-28 10:10:56 +02:00
parent 7152897b89
commit 027e3707fd
8 changed files with 82 additions and 15 deletions

View File

@@ -1,4 +1,5 @@
import type { HttpResponse } from '../../../src/server/HttpResponse';
import { BadRequestHttpError } from '../../../src/util/errors/BadRequestHttpError';
import {
addHeader,
parseAccept,
@@ -213,6 +214,10 @@ describe('HeaderUtil', (): void => {
contentTypePlain.parameters.test = 'value1';
expect(parseContentType('text/plain; charset=utf-8;test="value1"')).toEqual(contentTypePlain);
});
it('errors on invalid content-types.', (): void => {
expect((): any => parseContentType('invalid type')).toThrow(BadRequestHttpError);
});
});
describe('#parseForwarded', (): void => {