Skip to content

Commit

Permalink
#1016@minor: Add Content-Type header for Request.
Browse files Browse the repository at this point in the history
  • Loading branch information
orionmiz committed Aug 9, 2023
1 parent 0b20252 commit 04ae97b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/happy-dom/src/fetch/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export default class Request implements IRequest {
}

if (contentType) {
if (!this.headers.has('Content-Type')) {
this.headers.set('Content-Type', contentType);
}
this._contentType = contentType;
} else if (input instanceof Request && input._contentType) {
this._contentType = input._contentType;
Expand Down
10 changes: 10 additions & 0 deletions packages/happy-dom/test/fetch/Request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ describe('Request', () => {
expect(request._contentType).toBe('text/plain;charset=UTF-8');
});

it('Supports content type header from Request object.', () => {
const request = new Request(new Request(TEST_URL, { method: 'POST', body: 'Hello World' }));
expect(request.headers.get('Content-Type')).toBe('text/plain;charset=UTF-8');
});

it('Supports content type header from init object.', () => {
const request = new Request(TEST_URL, { method: 'POST', body: 'Hello World' });
expect(request.headers.get('Content-Type')).toBe('text/plain;charset=UTF-8');
});

it('Supports redirect from Request object.', () => {
const request = new Request(new Request(TEST_URL, { redirect: 'manual' }));
expect(request.redirect).toBe('manual');
Expand Down

0 comments on commit 04ae97b

Please sign in to comment.