Skip to content

Commit e1ee4d2

Browse files
committed
fix(fixRequestBody): fix TypeScript type
1 parent 6fd75f7 commit e1ee4d2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/handlers/fix-request-body.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { ClientRequest } from 'http';
1+
import type * as http from 'http';
22
import type { Request } from '../types';
33
import * as querystring from 'querystring';
44

55
/**
66
* Fix proxied body if bodyParser is involved.
77
*/
8-
export function fixRequestBody(proxyReq: ClientRequest, req: Request): void {
9-
if (!req.body || !Object.keys(req.body).length) {
8+
export function fixRequestBody(proxyReq: http.ClientRequest, req: http.IncomingMessage): void {
9+
const requestBody = (req as Request).body;
10+
11+
if (!requestBody || !Object.keys(requestBody).length) {
1012
return;
1113
}
1214

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

2022
if (contentType && contentType.includes('application/json')) {
21-
writeBody(JSON.stringify(req.body));
23+
writeBody(JSON.stringify(requestBody));
2224
}
2325

2426
if (contentType === 'application/x-www-form-urlencoded') {
25-
writeBody(querystring.stringify(req.body));
27+
writeBody(querystring.stringify(requestBody));
2628
}
2729
}

0 commit comments

Comments
 (0)