From 054c2f6357da2e2b904033aff7ffa2e539f00aa1 Mon Sep 17 00:00:00 2001 From: Aaron Knudtson <87577305+knudtty@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:46:14 +0000 Subject: [PATCH 1/2] fix: add text/plain to fixRequestBody --- src/handlers/fix-request-body.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/handlers/fix-request-body.ts b/src/handlers/fix-request-body.ts index e8e1373d..371355e9 100644 --- a/src/handlers/fix-request-body.ts +++ b/src/handlers/fix-request-body.ts @@ -40,6 +40,8 @@ export function fixRequestBody Date: Wed, 16 Apr 2025 13:58:22 +0000 Subject: [PATCH 2/2] test: add test case to fix-request-body for text/plain --- test/unit/fix-request-body.spec.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/unit/fix-request-body.spec.ts b/test/unit/fix-request-body.spec.ts index d1250461..d634edb3 100644 --- a/test/unit/fix-request-body.spec.ts +++ b/test/unit/fix-request-body.spec.ts @@ -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');