fix: return contenttype header value string with parameters

This commit is contained in:
Thomas Dupont
2022-07-05 13:06:18 +02:00
committed by Joachim Van Herwegen
parent e0954cf2a7
commit 311f8756ec
12 changed files with 122 additions and 30 deletions

View File

@@ -1,6 +1,6 @@
import type { HttpResponse } from '../../../src/server/HttpResponse';
import { BadRequestHttpError } from '../../../src/util/errors/BadRequestHttpError';
import {
import { ContentType,
addHeader,
hasScheme,
matchesAuthorizationScheme,
@@ -11,8 +11,7 @@ import {
parseAcceptLanguage,
parseContentType,
parseForwarded,
parseLinkHeader,
} from '../../../src/util/HeaderUtil';
parseLinkHeader } from '../../../src/util/HeaderUtil';
describe('HeaderUtil', (): void => {
describe('#parseAccept', (): void => {
@@ -469,4 +468,21 @@ describe('HeaderUtil', (): void => {
expect(hasScheme('wss://example.com', 'http', 'WSS')).toBeTruthy();
});
});
describe('A ContentType instance', (): void => {
it('can serialize to a correct header value string with parameters.', (): void => {
const contentType: ContentType = new ContentType(
'text/plain',
{
charset: 'utf-8',
extra: 'test',
},
);
expect(contentType.toHeaderValueString()).toBe('text/plain; charset=utf-8; extra=test');
});
it('can serialize to a correct header value string without parameters.', (): void => {
const contentType: ContentType = new ContentType('text/plain');
expect(contentType.toHeaderValueString()).toBe('text/plain');
});
});
});