Skip to content

[pull] master from chimurai:master #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix(fixRequestBody): support text/plain (chimurai#1103)
* fix: add text/plain to fixRequestBody
* test: add test case to fix-request-body for text/plain
  • Loading branch information
knudtty authored Apr 17, 2025
commit 9183b8cc106ea0ad665b59d1611141984c3778a0
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
Loading