Skip to content
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

fix(fixRequestBody): fix type error #615

Merged
merged 1 commit into from
May 23, 2021
Merged
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
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));
}
}