Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/handlers/fix-request-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export function fixRequestBody<TReq extends BodyParserLikeRequest = BodyParserLi
writeBody(querystring.stringify(requestBody));
} else if (contentType.includes('multipart/form-data')) {
writeBody(handlerFormDataBodyData(contentType, requestBody));
} else if (contentType.includes('text/plain')) {
writeBody(requestBody);
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/unit/fix-request-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ describe('fixRequestBody', () => {
expect(proxyRequest.write).toHaveBeenCalled();
});

it('should write when body is not empty and Content-Type is text/plain', () => {
const proxyRequest = fakeProxyRequest();
proxyRequest.setHeader('content-type', 'text/plain; charset=utf-8');

jest.spyOn(proxyRequest, 'setHeader');
jest.spyOn(proxyRequest, 'write');

fixRequestBody(proxyRequest, createRequestWithBody('some string'));

const expectedBody = 'some string';
expect(proxyRequest.setHeader).toHaveBeenCalledWith('Content-Length', expectedBody.length);
expect(proxyRequest.write).toHaveBeenCalledWith(expectedBody);
});

it('should write when body is not empty and Content-Type is application/json', () => {
const proxyRequest = fakeProxyRequest();
proxyRequest.setHeader('content-type', 'application/json; charset=utf-8');
Expand Down