Skip to content

Commit

Permalink
fix(fixRequestBody): fix TypeScript type (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed May 23, 2021
1 parent 6fd75f7 commit 21c70a0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/handlers/fix-request-body.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { ClientRequest } from 'http';
import type * as http from 'http';
import type { Request } from '../types';
import * as querystring from 'querystring';

/**
* Fix proxied body if bodyParser is involved.
*/
export function fixRequestBody(proxyReq: ClientRequest, req: Request): void {
if (!req.body || !Object.keys(req.body).length) {
export function fixRequestBody(proxyReq: http.ClientRequest, req: http.IncomingMessage): void {
const requestBody = (req as Request).body;

if (!requestBody || !Object.keys(requestBody).length) {
return;
}

Expand All @@ -18,10 +20,10 @@ export function fixRequestBody(proxyReq: ClientRequest, req: Request): void {
};

if (contentType && contentType.includes('application/json')) {
writeBody(JSON.stringify(req.body));
writeBody(JSON.stringify(requestBody));
}

if (contentType === 'application/x-www-form-urlencoded') {
writeBody(querystring.stringify(req.body));
writeBody(querystring.stringify(requestBody));
}
}

0 comments on commit 21c70a0

Please sign in to comment.