feat: Store content type parameters

* feat: support storage and retrievel of content-type parameters

* test: extra unit tests for parseContentTypeWithParameters

* refactor: simplify set contentType()

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>

* refactor: simplify for loop because of unique blankNodes

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>

* refactor: ContentTypeParameter should be contentTypeParameter

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>

* refactor: remove undefined type in favor of var? syntax

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>

* refactor: use new parseContentType internally

* chore: remove commented code

* docs: code documentation line changed

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>

* refactor: Check for faulty metadata in contentType rdf structure

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>

* refactor: remove all instances of blanknodes

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>

* refactor: use full contentType when parsing header

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>

* refactor: use quads() method instead of store.getQuads()

* refactor: .value needed for type correctness

* feat: ReprMetadata constructor now supports full content-type string

Co-authored-by: Joachim Van Herwegen <joachimvh@gmail.com>
This commit is contained in:
Thomas Dupont
2022-03-14 10:27:34 +01:00
committed by GitHub
parent 30011ba86b
commit a8602055e6
9 changed files with 210 additions and 23 deletions

View File

@@ -190,16 +190,31 @@ describe('HeaderUtil', (): void => {
describe('#parseContentType', (): void => {
const contentTypeTurtle = 'text/turtle';
const contentTypePlain: any = {
value: 'text/plain',
parameters: {
charset: 'utf-8',
},
};
it('handles single content-type parameter (with leading and trailing whitespaces).', (): void => {
expect(parseContentType('text/turtle').type).toEqual(contentTypeTurtle);
expect(parseContentType('text/turtle ').type).toEqual(contentTypeTurtle);
expect(parseContentType(' text/turtle').type).toEqual(contentTypeTurtle);
expect(parseContentType('text/turtle').value).toEqual(contentTypeTurtle);
expect(parseContentType('text/turtle ').value).toEqual(contentTypeTurtle);
expect(parseContentType(' text/turtle').value).toEqual(contentTypeTurtle);
expect(parseContentType('text/plain; charset=utf-8')).toEqual(contentTypePlain);
expect(parseContentType(' text/plain; charset=utf-8')).toEqual(contentTypePlain);
expect(parseContentType('text/plain ; charset=utf-8')).toEqual(contentTypePlain);
expect(parseContentType(' text/plain ; charset=utf-8')).toEqual(contentTypePlain);
expect(parseContentType(' text/plain ; charset="utf-8"')).toEqual(contentTypePlain);
expect(parseContentType(' text/plain ; charset = "utf-8"')).toEqual(contentTypePlain);
});
it('handles multiple content-type parameters.', (): void => {
expect(parseContentType('text/turtle; charset=UTF-8').type).toEqual(contentTypeTurtle);
expect(parseContentType('text/turtle; charset=UTF-8').value).toEqual(contentTypeTurtle);
contentTypePlain.parameters.test = 'value1';
expect(parseContentType('text/plain; charset=utf-8;test="value1"')).toEqual(contentTypePlain);
});
});
describe('#parseForwarded', (): void => {
it('handles an empty set of headers.', (): void => {
expect(parseForwarded({})).toEqual({});