Skip to content

Commit 3df3dd4

Browse files
authored
Merge pull request #18 from zachafranz/increase-scope-for-parsing-body-as-json
JSON Parse additional JSON Content-Type's
2 parents 3c82335 + 99d1203 commit 3df3dd4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/api/parser.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ describe('Body parsing', () => {
1010
expect(body).toEqual(json);
1111
});
1212

13+
it('Parses json body when charset is also defined in the context-type', () => {
14+
const json = { hello: 'world' };
15+
const headers = { 'content-type': 'application/json;charset=UTF-8' };
16+
const body = new Body(JSON.stringify(json), headers).getParsedBody();
17+
expect(body).toEqual(json);
18+
});
19+
1320
it('Parses form url encoded body', () => {
1421
const form = { hello: 'world' };
1522
const headers = { 'content-type': 'application/x-www-form-urlencoded' };

src/api/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ export class Body {
5454
}
5555

5656
private isJSON(contentType: string): boolean {
57-
return contentType && contentType.toUpperCase() === 'APPLICATION/JSON';
57+
return contentType && contentType.toUpperCase().includes('APPLICATION/JSON');
5858
}
5959
}

0 commit comments

Comments
 (0)